Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    300+ Forum Addict Tom_G_2010's Avatar
    Join Date
    Mar 2011
    Location
    Central Mass
    Posts
    437
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Question Trouble with "Q" Heading Extraction ???

    Jim,

    I'm now working on my Whiskey Compass using a stepper motor, Seed Motor Shield, and an Uno Card. My plan is to turn the compass disk with a 400 step (0.9 degree) stepper motor using a 10:1 worm gear drive. You'll see the 10:1 in the code where I translate the 360 degrees into 3600 and for the motor the 400 steps into 4000.

    My first draft at the code is working well on the test bench when I feed it Q extractions manually using the serial Monitor but I am loosing steps when running it via FSX. If I fly a plane on auto pilot and start at a given heading and do a standard rate turn of 360 degrees I am loosing several steps so that the heading indicator will come up a few degrees short of a full 360. This could be a rounding error or a serial overflow, or just bad code, or . . . I'm not sure yet.

    I suspected it was something to do with crossing North and the adjustment I was doing, but if I do a 180 from East crossing South to West so that no North Adjust takes place I see the same type of error cut down by about 1/2 as I would expect.

    I don't know where I'm dropping steps but need to find a way to monitor this live. When disconnected from FSX I can throw in some serial print commands and read all the calculated values via the serial monitor. But can't use that monitor (I don't think) while connected to FSX via Link2FS. Is there way to capture all that activity while running the board connected to Link2FS?

    One other related question: I have seen both Q360.0 and Q000.0 coming form Link2FS. Why would I get both? I was expecting to only see one or the other.

    Thanks in advance for any assistance or direction,
    Tom G.

    Code:
    #include  //Load Stepper Control Library
    
    const int stepsPerRevolution = 400;                   //0.9 degree 400 step motor
    int ExtFlg;                                           //Extraction designator from Link2FS  
    String HeadingDot, HeadingExt, HeadingExt_Last; //Heading Extraction
    
    float HeadingVal, HeadingVal_Last = stepsPerRevolution * 10; //Numeric Heading Value
    float StepVal, StepMaxP = 1000, StepMaxN = -1000;            //Calculated Motor Steps and max allowable steps before triggering the crossing North adjustments
    
    Stepper myStepper(stepsPerRevolution, 8,11,12,13);           //Initialize Stepper Motor
    
    void setup() {
     myStepper.setSpeed(75); //Set Stepper Speed (May want to look at adjusitng this or calculating it to smooth out stepper
     Serial.begin(115200);   //Initialize Serial Bus
     pinMode(9,OUTPUT);      //Set Pin Modes and Enable Stepper Motor
     pinMode(10,OUTPUT);
     digitalWrite(9,HIGH);
     digitalWrite(10,HIGH);
    }
    
    void loop() {
      ExtFlg = getChar();
    
      //------------ Heading ------------  
      if (ExtFlg == 'Q'){
        HeadingExt = "";
        HeadingExt += getChar(); 
        HeadingExt += getChar(); 
        HeadingExt += getChar(); 
        HeadingDot += getChar(); //Skips decimal place in extraction to, in effect, multiply by 10
        HeadingExt += getChar(); 
        if (HeadingExt != HeadingExt_Last){ 
    
          char carray[6];
          HeadingExt.toCharArray(carray, sizeof(carray)); //Convert extracted string to numeric value
          HeadingVal = atoi(carray);
    
          HeadingVal = map(HeadingVal, 0, 3600, 0, 4000); //Convert 360 degree heading value to 400 steps
    
          StepVal = HeadingVal - HeadingVal_Last; //Calculate difference between last heading read and current heading
    
          if(StepVal > StepMaxP){ // Adjust for crossing North
            StepVal = -1*(4000 - StepVal);
          }
    
          if(StepVal < StepMaxN){ // Adjust for crossing North
            StepVal = -1*(-4000 - StepVal);
          }
    
          myStepper.step(StepVal); //Move Stepper by calculated steps needed
    
       }
    
        HeadingVal_Last = HeadingVal; //Update Last values with current
        HeadingExt_Last = HeadingExt;
    
      } // End Heading
    
    } //End Program Loop
    
    char getChar() //Serial Read Function
    {
      while(Serial.available() == 0);
      return((char)Serial.read());
    }
    https://www.facebook.com/mycessnasim PC: Intel Core i7 Haswell @ 3.8GHz, 8Gb Ram, Win 7 64Bit, dual SSDs, GeFroce 780 SIM: FSX w/Aclrtn Pk, FSUIPC4, ASN, UTX, GEX, REX 4

  2. #2
    500+ This must be a daytime job Jim NZ's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    764
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Trouble with "Q" Heading Extraction ???

    Hi Tom ,,, you've opened a can of worms here but an interesting mission. !!
    Firstly ,, the data you see is actually true FSX data so it sends 360 when there is no decimal point but as soon as you turn further it changes to 000.1 ,,, so that's what your seeing.
    Basically you see 360 for one tenth of a degree.

    I had a check with the multi and that done exactly the same thing, so I changed it to read "000" when it was 360.
    Actually in the multi there is no decimal point reading ,, just 000 to 359.
    Or should it be 001 to 360 ??????

    You can read the Arduino serial.print using the "from com port" text-box in the "keys" section but the serial.println needs to be in lots of more than 3 characters ,,
    ie ,,,,
    serial println "Tom" you wont see (3 characters) ,,,
    but if you sent "Tom2" you will see it. (4 characters)

    I had a quick look-see at your code and it went over my head ,, I've had nothing to do with steppers at all so hopefully one of the other Guys might pop in and help you out.

    Cheers Tom ,,, Jim
    www.jimspage.co.nz/intro.htm
    All this and Liz still loves me ! !

  3. #3
    300+ Forum Addict Tom_G_2010's Avatar
    Join Date
    Mar 2011
    Location
    Central Mass
    Posts
    437
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Trouble with "Q" Heading Extraction ???

    Jim,

    Thanks for the quick reply. I don't think 001-360 or 000-359 is an issue either way as long as it's a known and predictable output. If I had my choice I would opt for 001-360 because zeros can sometimes be a pain depending on the math being done in the code.

    I am however, wondering how loosing the decimal place will affect things when I convert all my code to start using multi. I am too new into the stepper world and still rather green when it comes to coding myself to say for sure but the first admittedly uneducated pro and con that popped into my head is as follows:

    Pro for not having it: It reduces the freq of "Q" extractions being sent during a continuous turn and therefore reduces the load on the serial bus and lag in seeing other extractions.

    Con for not having it: The decimal precision helps smooth out the compass movement and loosing it could require more coding to create smooth movement of the compass.

    If I can get past the current bug I'm working on it would not be hard to truncate the current extraction so the code acted only on the integer values to see how it behaves. I may do that knowing that multi won't support it.


    Regarding the "from com port" text-box in the "keys" section, that's a section of Link2FS that I haven't delved into yet. Can I feed that data to a file or screen output so I can review the full sequence after my turns are complete?

    Again, Thanks!!!
    Tom G.
    https://www.facebook.com/mycessnasim PC: Intel Core i7 Haswell @ 3.8GHz, 8Gb Ram, Win 7 64Bit, dual SSDs, GeFroce 780 SIM: FSX w/Aclrtn Pk, FSUIPC4, ASN, UTX, GEX, REX 4

  4. #4
    500+ This must be a daytime job Jim NZ's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    764
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Trouble with "Q" Heading Extraction ???

    I changed it to show 1 - 360 in the new (Not released yet) "multi" ,, it makes sense to go that way because of any mathematics some-one may want to use.

    And as far as the decimal point ,,, I left it as just the degree's as to include the decimal point would have been a complete overkill and swamped the serial port. To do a 90 degree turn it sends out 90 "changes" but with the decimal point it would have been a staggering 900 "changes".

    As far as the "Keys" port reading text-box ,,, no that's the only hope you have ,, seeing a quick flash of the code received and from memory, it's very quick, so you'd have to have "fast eyes"
    I'm not even sure it will work as I'm not setup to run the old "InOut" but I did look at it's code.

    Hope that helps you Tom ,,,, Jim
    www.jimspage.co.nz/intro.htm
    All this and Liz still loves me ! !

  5. #5
    10+ Posting Member
    Join Date
    Jan 2011
    Location
    Midlands, UK
    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: Trouble with "Q" Heading Extraction ???

    Hey Tom, have you looked into the SoftwareSerial as a way of getting debug info out. I was looking at it the other day because I wanted some into while I was testing my system and of course the com port is taken up reading Link2FS.

    Arduino - SoftwareSerial

  6. #6
    300+ Forum Addict Tom_G_2010's Avatar
    Join Date
    Mar 2011
    Location
    Central Mass
    Posts
    437
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Trouble with "Q" Heading Extraction ???

    I had looked at that a while back for something I was doing on my Mega. But, I wasn't sure if I could use it on the Uno and I'm not quite sure how to use it to create a monitor bus. I'll have to do some more reading on that. I looked at some external software based serial monitors but the free ones don't work and the low end of the payware ones is $65.

    If I can get the Arduino software serial to provide an output I can monitor that would be perfect. I'll have to do some more reading when I get back to the house this afternoon. THANK!
    https://www.facebook.com/mycessnasim PC: Intel Core i7 Haswell @ 3.8GHz, 8Gb Ram, Win 7 64Bit, dual SSDs, GeFroce 780 SIM: FSX w/Aclrtn Pk, FSUIPC4, ASN, UTX, GEX, REX 4

  7. #7
    10+ Posting Member
    Join Date
    Jan 2011
    Location
    Midlands, UK
    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: Trouble with "Q" Heading Extraction ???

    Ummm... if you know any visual basic 6 I think you can just use mscomm. I'll have a play tomorrow and let you know. If it works I can knock up a simple monitor program for us (I really need one too).

    I think the main problem with softwareserial is it kind of hits the Arduino processor quite heavily though.

  8. #8
    25+ Posting Member



    Join Date
    Dec 2010
    Location
    Newnan, Ga.
    Posts
    65
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Trouble with "Q" Heading Extraction ???

    I will start working with the Arduino Mega again and the ability to monitor the information flowing back and forth would be great. As a newbie and still trying to get a grasp on the code and it will be nice to see what I am or not accomplishing.

  9. #9
    300+ Forum Addict Tom_G_2010's Avatar
    Join Date
    Mar 2011
    Location
    Central Mass
    Posts
    437
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Trouble with "Q" Heading Extraction ???

    I didn't get far with software serial yesterday but that was as much lack of time as it was lack of experience with it. The Snow Storm that hit my area really threw a bigger wrinkle in my weekend than I thought it would.

    In my case I have two Arduinos at this point another one or two may be in the works later. But for now, a Mega running all my LEDs, some 7 segment displays, and a couple servos, and an Uno running my stepper motor and I will eventually piggy back a couple more shields on the Uno to expand what it is doing. So at this time I'm looking to monitor the activity on the Uno.

    Neo, If you're able to come up with something using VB6 that would be great. I dabbled in VB6 a few years ago to create a few very basic programs but never really dug into it much more so I don't know that I would be able to come up with something like that. Anything you come up with would be more than helpful and greatly appreciated!

    Thanks!
    Tom G.
    https://www.facebook.com/mycessnasim PC: Intel Core i7 Haswell @ 3.8GHz, 8Gb Ram, Win 7 64Bit, dual SSDs, GeFroce 780 SIM: FSX w/Aclrtn Pk, FSUIPC4, ASN, UTX, GEX, REX 4

  10. #10
    25+ Posting Member



    Join Date
    Aug 2009
    Location
    Oss - Netherlands
    Posts
    61
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Trouble with "Q" Heading Extraction ???

    Hi Tom,
    I am too new to be of any help, but I have been reading a lot about Arduino's to get up to date.

    Could you use your 2 arduino's to do what you want? If 1 is connected to FSX through link2FS, you can't use serial monitor. But, just a thought here, you could use the pin serial out on that one and connect that to your pin serial in on the other board and use its serial monitor?

    Greetings,
    Eric

    Edit: well that would be a lot of work. Jims program shows output from the arduino on the keys tab. You can also select which program to send that output too. Like notepad. Looks a lot easier than my ,, solution,, above

Page 1 of 2 12 LastLast