Results 1 to 6 of 6
  1. #1
    10+ Posting Member
    Join Date
    Jan 2013
    Location
    canada
    Posts
    14
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    I need float instead of string for for pitch LINK2FS6F

    Can anyone help me with conversion, or is it possible to eliminate String process and just get float only. i have tried and no luck. i Just want the data in float form. here is code. This is just the basic code with string form only, i have deleted the ones with float that did not work for me.THANKS!!

    int CodeIn;
    String Pt, PtOld;

    void setup()
    {
    Serial.begin(115200);
    }

    void loop()
    {
    {OTHER();}// Check for "Other" things to do. (Non extraction stuff)
    if (Serial.available()) { //Check if anything there
    CodeIn = getChar(); //Get a serial read if there is.
    if (CodeIn == '=') {EQUALS();} // The first identifier is "=" ,, goto void EQUALS
    if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<" ,, goto void LESSTHAN
    if (CodeIn == '?') {QUESTION();}// The first identifier is "?" ,, goto void QUESTION
    if (CodeIn == '/') {SLASH();}// The first identifier is "/" ,, goto void SLASH (Annunciators)
    }
    }


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


    }


    void OTHER(){
    }

    void LESSTHAN(){
    CodeIn = getChar();
    switch(CodeIn) {
    case 'Q'://Found the second identifier
    //Do something
    delay (11);
    Pt = "";
    Pt += getChar();
    Pt += getChar();
    Pt += getChar();
    Pt += getChar();
    Pt += getChar();
    Pt += getChar();


    if (Pt != PtOld) {
    PtOld = Pt;
    }
    break;
    }
    }

  2. #2
    150+ Forum Groupie
    Join Date
    Nov 2013
    Location
    Evansville, Indiana
    Posts
    243
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: I need float instead of string for for pitch LINK2FS6F

    Try it with Integer and disregard the decimal.

    Up where you declare your variables...

    String Digit;
    String pitch_str;
    int pitch_multiplier;
    int pitch;


    Down in your "Q" case try this....

    case 'Q':

    Digit = "";
    Digit = getChar(); // the plus or minus

    if (Digit == "-") // if its a minus
    {
    pitch_multiplier = -1; // negative is pitch up
    }
    else // if its not a minus then it MUST be a plus
    {
    pitch_multiplier = 1; // positive is pitch down
    }

    Digit = getChar(); // digit 1
    pitch_str += Digit;

    Digit = getChar(); // digit 2
    pitch_str += Digit;

    Digit = getChar(); // digit 3
    pitch_str += Digit;

    Digit = getChar(); // the decimal point which we drop
    Digit = getChar(); // digit 4
    pitch_str += Digit;


    pitch = pitch_str.toInt(); // Take our 4 digit string and convert to Integer


    pitch = pitch * pitch_multiplier; // Now make the pitch Integer positive or negative

    break;


    See if that helps, there are a number of ways to skin this cat.
    Floats are possible, I just don't have working knowledge, currently.

    Tell us what you intend to do and it may make the solution come quicker and or easier.

    ~Fess
    I will only ever be, half the Geek that I wished I was.
    TheGeekForge.Com

  3. #3
    10+ Posting Member
    Join Date
    Jan 2013
    Location
    canada
    Posts
    14
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: I need float instead of string for for pitch LINK2FS6F

    i wanted to check and see if float value can be used to control servo resolution instead of an integer, to get more precision. I'm new to programming so i was just testing curiosity.

  4. #4
    150+ Forum Groupie
    Join Date
    Nov 2013
    Location
    Evansville, Indiana
    Posts
    243
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: I need float instead of string for for pitch LINK2FS6F

    MLRUSSELL,

    You will see in many of my posts the mantra, " Crawl, Walk, Run".

    First make something move.
    Have you taken any data from FSX via Link2FS and made an Arduino do anything? Light an LED, move a servo, etc.
    If you haven't, do that first.
    Then go the other way, make a switch or button on the Arduino change something in FSX.
    This will help you learn the mechanics of the system.

    As far as precision goes, the float value 100.3 can be mathematically the same as int value 1003, unless you divide. It is just a matter of decimal point position.
    If you are going to scale the value range of pitch to the servo, I'm not sure you can even use a decimal.
    For that matter you might not be able to use negative values so you would need to add a base value to make it positive.



    ~Fess
    I will only ever be, half the Geek that I wished I was.
    TheGeekForge.Com

  5. #5
    25+ Posting Member



    Join Date
    Nov 2010
    Location
    The Netherlands
    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: I need float instead of string for for pitch LINK2FS6F

    Hi MLRussel, Fess,

    I guess you have the same goal as i do.
    Get a servo to work with greater precision. (see post on autothrottle)
    Have you been able to move the servo with less than one degree, using pos "commands"
    At the moment i'm trying to control the servo using writeMicroseconds.
    the servo can be moved in very small steps.

    Have yet to find a way to get the data from link2fs in the correct format.
    Was thinking of decimal, but a 1003 like figure would do!

    Sorry, no real help from me. Hope we can figure this out.

  6. #6
    25+ Posting Member



    Join Date
    Nov 2010
    Location
    The Netherlands
    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: I need float instead of string for for pitch LINK2FS6F

    Hi MLRussel,

    Maybe this will help your project.
    Using the writeMicroseconds, i got accurate autothrottle response on a servo.
    more that the pos command.

    See thread: http://www.mycockpit.org/forums/showthread.php?t=29034

    Using the expert setting in link2fs, i got a 4 digit figure from FSX about the throttle position. (raw data * 10)
    that way i got a higer resolution than the throttle position in the sim extractions (1)

    Hope this helps.
    cheers