Page 2 of 5 FirstFirst 12345 LastLast
Results 11 to 20 of 50

Thread: Magnetic compass build and code

  1. #11
    25+ Posting Member Doug77's Avatar
    Join Date
    Aug 2012
    Location
    scotland
    Posts
    49

    Re: Magnetic compass build and code

    Im starting to think I may be overcomplicating this thing... as North is a know position on the Compass card due to a photo interrupter switch maybe I should just take the heading and have the stepper locate to that position... ie GOTO HEADING (359) etc in whatever Arduino code is, and then compensate whenever North is detected (360)

    Sorry im rambling here,

    Doug..

  2. #12
    150+ Forum Groupie
    Join Date
    Nov 2013
    Location
    Evansville, Indiana
    Posts
    251

    Re: Magnetic compass build and code

    I think I have it.


    We will take the difference of old and new then convert.
    In these examples when "step" is positive its moving left, when "step is negative it is moving right.
    These examples are not coded properly for conceptual purposes.

    new_hdg = 90
    old_hdg = 100
    step = old_hdg - new_hdg
    step = 100 - 90

    step = 10 (10 to the left in this case)


    new_hdg = 180
    old_hdg = 170
    step = old_hdg - new_hdg
    step = 170 - 180

    step = -10 (10 to the right in this case)

    ***********************************************
    For the Trap...
    new_hdg = 355
    old_hdg = 5
    step = old_hdg - new_hdg
    step = 5 - 355
    step = -350

    if (step < -180) NOTE that is providing we don't have jumps more than 180
    { step = step + 360;}
    step = -350 + 360
    That would = 10 ( to the left, like our first example)
    *********************************************
    Second Trap...

    new_hdg = 10
    old_hdg = 359
    step = old_hdg - new_hdg
    step = 359 - 10
    step = 349

    if (step > 180) NOTE that is providing we don't have jumps more than 180
    { step = step - 360;}
    step = 349 -360
    step = -11 (11 to the right in this case)


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

  3. #13
    25+ Posting Member Doug77's Avatar
    Join Date
    Aug 2012
    Location
    scotland
    Posts
    49

    Re: Magnetic compass build and code

    Thanks for that Fess,

    that looks pretty good although at a quick glance the (New heading "greater than" old heading)=CW and (New heading "less than" old heading)=CCW routine is going to have to be altered....is that right??

    CANCEL THAT!!......... Negatives and positives give direction DUH!! mil gracias

    Now if I only knew someone who knew what they were doing that could take my previously attached ZiP file and quickly alter it ..... LOL

    Doug..

  4. #14
    150+ Forum Groupie
    Join Date
    Nov 2013
    Location
    Evansville, Indiana
    Posts
    251

    Re: Magnetic compass build and code

    Doug,

    If you want Positive Step numbers to be to the right and Negative Step numbers to the left, you could swap the formula so ( step = new_hdg - old_hdg).

    You would also have to change the operation in the traps for that.


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

  5. #15
    25+ Posting Member Doug77's Avatar
    Join Date
    Aug 2012
    Location
    scotland
    Posts
    49

    Re: Magnetic compass build and code

    Thanks Fess,

    Appreciate your help buddy, its all so obvious when someone who knows what they are doing points it out...its been so long since I did any kind of mathematics, not that I was any kind of whizz kid when I did lol

    Doug..

  6. #16
    75+ Posting Member vikingsraven's Avatar
    Join Date
    Dec 2012
    Location
    UK
    Posts
    89

    Re: Magnetic compass build and code

    sow the wind reap the whirlwind!, thank fess for looking at it. for the accuracy i recon using( if you can) half steps on the servo, limiting any calculations to groups of 50 steps.
    compass.png
    so this shows complete numbers every 45 degrees is a round number of 50 pulses. the only real errors you'll get are between 0-8,10-17,19-26,28-35,-37-44.
    so the modulo 9 thing should resolve this.
    Ill work on it when i can, mark

  7. #17
    25+ Posting Member Doug77's Avatar
    Join Date
    Aug 2012
    Location
    scotland
    Posts
    49

    Re: Magnetic compass build and code

    Hi Mark,

    Lol yeah definately blowing a gale here!!!... Im using Half steps

    cheers bud

    Doug..

  8. #18
    75+ Posting Member
    Join Date
    Sep 2013
    Location
    California, USA
    Posts
    109

    Re: Magnetic compass build and code

    Hey Guys,
    Consider the alternative of using pots to provide compass heading feedback - this design needs far less computations and can't ever get out of sync. Here's a look at this design for a whiskey compass. It uses a cheap 1.5rpm dc gear motor and a dual potentiometer with the mechanical stops removed (180deg out of phase). The motor is coupled to the pot shaft which in turn rotates the compass wheel. I can't take credit for making this, but it's very slick.
    compass-pots.jpg

  9. #19
    75+ Posting Member vikingsraven's Avatar
    Join Date
    Dec 2012
    Location
    UK
    Posts
    89

    Re: Magnetic compass build and code

    there's always one isn't there! ( sorry English wit!)
    hi SteveL like the idea of that actually, anyway back to the stepper motor one!
    youll also need to set up a pulse speed control, so if its over 10 deg go this fast over 20 this fast , otherwise if you do a fast turn the compass wont catch up, in my case normally a stall into a corkscrew.
    maybe use a map function
    map(stepSpeedDelay,0,360,1000,10)
    so if its 10 degrees you'll get say 888 delay pulse length , if its 40+ degrees youll get a shorter delay pulse.

    ill try to bang out some code this evening, been building quad copter, quad robot, repairing an M8 greyhound armoured car and 3 jeeps so a tad busy.

  10. #20
    25+ Posting Member Doug77's Avatar
    Join Date
    Aug 2012
    Location
    scotland
    Posts
    49

    Re: Magnetic compass build and code

    Hi folks,

    Ive just noticed a problem with my initial sketch,

    How do I extract the heading "< J " as a whole number/integer? I used compass[Count] = Digit.toInt(); which I then tried to read it as x = compass[0,1,2]; which isnt working and is only giving me a single digit

    instead of say
    Compass[3,4,5] I would like to end up with Compass= 345

    sorry if thats as clear as mud... I need the heading numbers as a 3 digit integer so I can subtract new heading from old etc

    hope im using the correct terminology .. slow and old but getting there

    many thanks

    Doug..

Page 2 of 5 FirstFirst 12345 LastLast