Results 1 to 6 of 6

Thread: Servo movement

  1. #1
    10+ Posting Member
    Join Date
    Apr 2014
    Location
    United States
    Posts
    15
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Servo movement

    Hi Jim, I bought a arduino Uno a few days ago and I've been overwhelmed a little ever since until I found your fantastic program.

    Here is basically what I'm wanting to do. I have always been irritated by my CH yoke not becoming stiffer the faster the plane flies, so I thought I'd fix it.
    I'm using your program, more of a Godsend really, to communicate with my Uno board which will in turn run a servo that I will mount on the yoke. I will have a pulley or servo horn attached to the yoke shaft with fishing line and springs. Then I'll just have the Uno read the airspeed and transmit it to the servo.

    I've modified your MultiKey with flaps servo sketch for right now to read the engine rpm and its working great except for one thing, I'm getting less than a quarter of a turn out of the servo. A lot of the problem may be the way the servo is geared internally but I noticed that in your sketch you had listed the following

    int flapsi = flaps.toInt(); // convert it to an integer (Thanks Phill)
    flapsi = (flapsi + 10);// Manual correction to suit servo zero.
    flapsServo.write(flapsi * 3); // Manual fiddle to get full span of servo.
    // Note.. Using the "Map" method slows it down.
    //Serial.print(flapsi); // Used for testing

    I have done a lot of "Manual fiddling" to get to the full span of the servo trying anywhere from 1 to 15 in place of the * 3 with no change. Below is your sketch that I have modified.


    /*
    This code is in the public domain
    For use with "Link2fs_Multi"
    Jimspage.co.nz
    My thanks to the Guys that gave me snippets of code.

    This sets the complete Arduino card for "keys" input except pin 13.
    Attach a switch to any pin (except 13) and program that pin in "Multi"
    Pin 13 is used for the servo to indicate flaps.
    For this servo code to work you must tick " Everything to do with "Keys" starts with a "K" in this code.

    */

    #include
    Servo RPMServo;



    int CodeIn;// used on all serial reads
    int KpinNo;
    int Koutpin;
    String RPM;

    String KoldpinStateSTR, KpinStateSTR, Kstringnewstate,Kstringoldstate;

    void setup()
    {
    Kstringoldstate = "111111111111111111111111111111111111111111111111111111111111111111111";

    for (int KoutPin = 2; KoutPin < 70; KoutPin++)// Get all the pins ready for "Keys"
    {
    pinMode(KoutPin, INPUT);
    digitalWrite(KoutPin, HIGH);
    }
    Serial.begin(115200);
    pinMode(13, OUTPUT);// For the servo.
    RPMServo.attach(13);

    }

    void loop() {
    {KEYS();} //Check the "keys" section
    if (Serial.available()) {
    CodeIn = getChar();
    if (CodeIn == '=') {EQUALS();} // The first identifier is "="
    if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<"
    if (CodeIn == '?') {QUESTION();}// The first identifier is "?"
    if (CodeIn == '/') {SLASH();}// The first identifier is "/" (Annunciators)
    }

    }

    char getChar()// Get a character from the serial buffer
    {
    while(Serial.available() == 0);// wait for data
    return((char)Serial.read());// Thanks Doug
    }

    void EQUALS(){ // The first identifier was "="
    CodeIn = getChar(); // Get another character
    switch(CodeIn) {// Now lets find what to do with it
    case 'A'://Found the second identifier
    //Do something
    break;

    case 'B':
    //Do something
    break;

    case 'C':
    //Do something
    break;
    }
    }

    void LESSTHAN(){ // The first identifier was "<"
    CodeIn = getChar(); // Get another character
    switch(CodeIn) {// Now lets find what to do with it
    case 'A'://Found the second identifier
    //Do something
    break;

    case 'B':
    //Do something
    break;

    case 'T'://Found the second identifier ("T" Eng1RPM)
    RPM = "";
    RPM += getChar();
    RPM += getChar();
    RPM += getChar();
    int RPMi = RPM.toInt(); // convert it to an integer (Thanks Phill)
    RPM = (RPM + 10);// Manual correction to suit servo zero.
    RPMServo.write(RPMi * 90); // Manual fiddle to get full span of servo.
    // Note.. Using the "Map" method slows it down.
    //Serial.print(flapsi); // Used for testing
    break;
    }
    }

    void QUESTION(){ // The first identifier was "?"
    CodeIn = getChar(); // Get another character
    switch(CodeIn) {// Now lets find what to do with it
    case 'A'://Found the second identifier
    //Do something
    break;

    case 'B':
    //Do something
    break;

    case 'C':
    //Do something
    break;
    }
    }
    void SLASH(){ // The first identifier was "/" (Annunciator)
    //Do something
    }
    void KEYS()
    {
    Kstringnewstate = "";
    for (int KpinNo = 2; KpinNo < 70; KpinNo++){
    KpinStateSTR = String(digitalRead(KpinNo));
    KoldpinStateSTR = String(Kstringoldstate.charAt(KpinNo - 2));
    if (KpinStateSTR != KoldpinStateSTR)
    {
    if (KpinNo != 13){
    Serial.print ("D");
    if (KpinNo < 10) Serial.print ("0");
    Serial.print (KpinNo);
    Serial.println (KpinStateSTR);
    }
    }
    Kstringnewstate += KpinStateSTR;
    }
    Kstringoldstate = Kstringnewstate;
    }
    Any Thoughts, Anyone

    Thanks
    Mark

  2. #2
    10+ Posting Member
    Join Date
    Apr 2014
    Location
    United States
    Posts
    15
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Servo movement

    Hi,

    I bought a arduino Uno a few days ago and I'm really excited about the possibilities that it represents since I found Link2FS.

    What I'm wanting to do is run a servo on my flight yoke that will adjust the resistance based on airspeed.

    I've gotten it up and running but I haven't started mounting the servo to the yoke yet.

    I've modified Jim's flap sketch to run but I'm looking for some help with the resolution of the servo. I've lowered both the cycle time and the refresh time in Link2fs and I've done some adjusting on the two line of the sketch below. Right now I'm testing it using engine RPM.

    RPM = (RPM + 0);// Manual correction to suit servo zero.
    RPMServo.write(RPMi * 30); // Manual fiddle to get full span of servo.

    The values that were originally written in the sketch were 10 and 3. If I get it where it will move smoothly and with the full travel
    it happens all at once around 1800 rpm in a Cessna. If I lower the RPMi* value it will move in increments instead of all at once but the movement is about 30 degrees or so a move. Does anyone know of something else I might try?

    Sorry about the double post! I would delete it if I could.
    Thanks
    Mark

  3. #3
    25+ Posting Member
    Join Date
    Dec 2010
    Location
    Canada
    Posts
    26
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Servo movement

    I may not fully understand but if you want a servo to be a linear operation to an fsx value you could do what I did for the turn coordinators:

    val = tc1; // reads the value of the data from FSX
    val = map(val, 0, 256, 0, 179); // scale it to use it with the servo ( between 0-256 for FSX turn coordinator,between 0 and 180 for servo)
    myServo.slowmove(val,45); // sets the servo position according to the scaled value (second number is servo speed 0=slowest, 255=fastest)

    Just change out the slowmove for a write as I used a variable speed library in this case. You should be able to map the limits in the same way.

    Long story short- Map the FSX value min/max to the servo min/max.

    Cheers

  4. #4
    10+ Posting Member
    Join Date
    Apr 2014
    Location
    United States
    Posts
    15
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Servo movement

    Thanks WhiteStar01, I think that's what I was lookin for!
    Mark

    Edit: WhiteStar, I don't guess I could get you to post that sketch or point me to it could I?

  5. #5
    25+ Posting Member
    Join Date
    Dec 2010
    Location
    Canada
    Posts
    26
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Servo movement

    Delete this from your code:

    RPM = (RPM + 10);// Manual correction to suit servo zero.
    RPMServo.write(RPMi * 90); // Manual fiddle to get full span of servo.

    Add this in place:

    val = RPMi;
    val = map(val, 0, 5000, 0, 179); // scale it to use it with the servo ( between 0-? for RPM ,between 0 and 180 for servo)
    RPMServo.write(val);

    Scale it to suit your servo and aircraft.
    Cheers
    Eric

  6. #6
    75+ Posting Member



    Join Date
    Sep 2013
    Location
    California, USA
    Posts
    109
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Servo movement

    Hi Mark,
    I found this little payware ad-on for fsx which generates a pretty nifty force feedback signal for your yoke servos at http://www.fs-force.com/features/airforces.htm. Once you get your system working well this might provide a better source to monitor for your feedback signal.
    Good luck with your project, great idea.
    ...Steve