Jump to content
The simFlight Network Forums

How to use flaps offset to a servo


Recommended Posts

Hi Paul,  Emerson (from Virtual Aviation) again! 

My LandGear is finalized. Everything's fine. Now I'm in another challenge. To export flaps offset 0BDC to a servo on arduino board.

Could you help me out in this new challenge? 

Here's part of my code in C#  (see red bold font)

1-Setting the offset:

         // =====================================
        // DECLARE OFFSET
        // =====================================
         private Offset<int> flaps = new Offset<int>(0x0BDC);

2-Loop timerMain :


        private void timerMain_Tick(object sender, EventArgs e)
        {
            // Call process() to read/write data to/from FSUIPC
            // We do this in a Try/Catch block incase something goes wrong
            try
            {
                FSUIPCConnection.Process();

                // Update the information on the form
                // (See the Examples Application for more information on using Offsets).

             
                // exporting flaps data to a servo

                 this.txtFlaps.Text = flaps.Value.ToString();

                port.WriteLine(flaps.Value.ToString());

            }

 }
                catch (Exception ex)
                {
                    // An error occured. Tell the user.
                    MessageBox.Show("Connection Failed\n\n" + ex.Message, "FSUIPC", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            configureForm();
        }

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Here's the arduino firmware, very simple:

 

#include<Servo.h>
Servo base;
void setup() 
{
  base.attach(8);
  Serial.begin(9600);  
}
void loop()
{
      int val=Serial.parseInt();
      if(val!=0)
      {
        base.write(val);
      }
}

***************************************************************

What is working ?

Paul, when FSUIPC connects and flaps are UP  == 0 ,  at the time I change the flaps with 1 degree (first notch) flaps value == 2048 . Servo makes no movement. 

When I set flaps 2, flaps value == 4096 and servo moves 90 degrees approximately. Then I set flpas == 5 and  and txt.flaps value == 4096 and servo keep steady (no changes). And nothing 

changes on servo as the values changes in txtFlaps on each new flap position is set but servo only changes from flap position 1 to 2 and 2 to 1. Flaps value from 2048 to 4096 and from 4096 to 2048.

I think I have to creat a new firmware that according to each value arduino receives from C# (0 to 16383) , it set a servo position angle according to these values. Am I correct? Do you know another way to make the servo recognizes each flap notch and applying these values to the servo? 

I would be happy if you could help me out here. Thanks in advance.

Best Regards,

 

     Emerson Schmidt

Virtual Aviation - Brazil

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

Hi Emerson,

The C# code looks fine and it sound like you are getting sensible values from FSUIPC.

(I think you made a mistake here though (in red) as the the number should change from 2 to 5 degrees)

>> When I set flaps 2, flaps value == 4096 and servo moves 90 degrees approximately. Then I set flpas == 5 and  and txt.flaps value == 4096 a

Quote

I think I have to creat a new firmware that according to each value arduino receives from C# (0 to 16383) , it set a servo position angle according to these values. Am I correct?

Yes possibly. I don't know what values your servos need to make them move.

At the moment you are just sending the raw flaps values. It would be a lucky coincidence if those were the same values the servo needs. It's likely that you will need to do some maths to translate the flaps value into the correct range for the servo.

If you can explain to me what values are needed to make the servo move I can help with that.

Paul

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.