Shop OBEX P1 Docs P2 Docs Learn Events
Magic Compass Project update — Parallax Forums

Magic Compass Project update

Thomas FletcherThomas Fletcher Posts: 91
edited 2009-03-19 18:56 in Propeller 1
Magic Compass Project: To make a compass that points toward a geocache location instead of north using digital compass, GPS, and a servo to point needle.

So far I only have the digital compass HM55b. A micro servo is in the mail and I have to save up some pennies to get a GPS.

After some hair pulling dealing with real numbers, I believe I have the code ready for a north pointing compass.

My equation for determining the bearing between two points had unexpected but workable results. It returns 0 degrees for East, -90 for North, 90 for South and 180 for West.

Added an if statement to change the result into a 0-360 degree scheme that matches the compass.

The person's direction is pulled from the compass and the position the needle should point is worked out with another nested if.

Pretty sad looking code, but it has been a long time.

All that is left is to add code to manipulate the servo and to bring the (lat2/long2) values from the gps.


CON
         _clkmode        = xtal1 + pll16x
         _xinfreq        = 5_000_000

         
    Enable = 0
     Clock = 1
      Data = 2 
OBJ
   F32    : "Float32full"
   vp     : "Conduit"
   HM55B :  "HM55B Compass Module Asm"
VAR
  long lat1
  long long1
  long lat2
  long long2
  long r
  long degree
  long bearing
  long direction
  long needle
  'long place1, place2, place3
  'long first, second, third
  'long place3
  
  long angle

  
PUB MAIN | temp

   vp.config(string("start:dso"))  'start in dso mode
   vp.config(string("var:degree(base=-2), bearing(base=-2), direction(base=-2), needle(base=-2)"))
  
  
  vp.share(@degree,@needle)
  F32.start
  HM55B.start(Enable,Clock,Data)

   lat1 := 28.963105          'coordinates have north bearing 0
   long1 := -81.471019
   lat2 :=    28.963763
   long2 := -81.471019


   'place1 := F32.Radians(F32.Fsub(long2,long1))          The math for r broken down in chunks.
   'place2 := f32.radians(f32.fsub(90.0,lat2))
   'place3 := f32.radians(f32.fsub(90.0,lat1))
   'first:= F32.fmul(F32.sin(F32.Radians(F32.Fsub(long2,long1))),F32.cos(f32.radians(f32.fsub(90.0,lat2))))
   'second:=F32.fmul(F32.cos(f32.radians(f32.fsub(90.0,lat1))),F32.sin(f32.radians(f32.fsub(90.0,lat2))))
   'third:=F32.fmul(F32.fmul(F32.sin(f32.radians(f32.fsub(90.0,lat1))),F32.cos(f32.radians(f32.fsub(90.0,lat2)))),f32.cos(F32.Radians(F32.Fsub(long2,long1))))
   'r := F32.atan2(f32.fsub(second,third),first)
   
   r := F32.atan2(f32.fsub(F32.fmul(F32.cos(f32.radians(f32.fsub
(90.0,lat1))),F32.sin(f32.radians(f32.fsub(90.0,lat2)))),F32.fmul(F32.fmul(F32.sin
(f32.radians(f32.fsub(90.0,lat1))),F32.cos(f32.radians(f32.fsub(90.0,lat2)))),f32.cos
(F32.Radians(F32.Fsub(long2,long1))))),F32.fmul(F32.sin(F32.Radians(F32.Fsub(long2,long1))),
F32.cos(f32.radians(f32.fsub(90.0,lat2)))))

   
   degree := F32.degrees(r)             ' degree comes out 0:east -90:north 90:south 180,-180:west
  
   if f32.fcmp(degree,-90.0)==1 and f32.fcmp(0.0,degree)== 1                 '  Convert degrees to 0-360 bearings
      bearing := f32.fsub(90.0,f32.fabs(degree))
   elseif  F32.fcmp(degree,-90.0) == 0 or F32.fcmp(degree,0.0) == 0
      bearing := f32.fsub(90.0,f32.fabs(degree))
   elseif f32.fcmp(-90.0,degree)==1
      bearing := f32.fsub(450.0,f32.fabs(degree))               
   elseif f32.fcmp(degree,0.0)==1
      bearing := f32.fadd(90.0,degree)

   repeat                                                            'set needle position to point to destination depending on how you are facing
      direction := f32.fdiv(f32.degrees(HM55B.theta),1302)
      if f32.fcmp(181.0,direction) == 1
         angle := direction
         if f32.fcmp(direction,bearing) == 1
            temp := f32.fsub(direction,bearing)
            needle := f32.fsub(360.0,temp)
         else
            needle := f32.fsub(bearing,angle)   
          
      else
         if f32.fcmp(bearing,0.0) == 0
            bearing:= 360.0
         angle := f32.fsub(360.0,direction)
         if f32.fcmp(bearing, direction) == 1
            needle := f32.fsub(bearing,direction)
         else    
            needle := f32.fsub(bearing,angle)



Post Edited (Thomas Fletcher) : 3/14/2009 1:45:21 PM GMT

Comments

  • parts-man73parts-man73 Posts: 830
    edited 2009-03-09 17:37
    Excellent project! I used to do Geocaching a few years ago. This is a great idea.

    For those of you that don't know what it is. Geocaching is a game/sport/hobby wherein someone hides a "cache", a waterproof
    container, and posts GPS coordinates and hints on the Geocaching website. Sometimes there is a prize exchange in the
    cache(usually with a theme, but never expensive), sometimes a logbook. The real reward is getting out for a good hike,
    and solving the puzzle of where it's hidden. You'd be surprised how many people that participate in this activity (I just checked,
    there are 497 active geocaches within 25 miles of my location and 743,828 worldwide)

    one small question. Most servos I have used do not have the ability to turn a full 360 degrees. Except of course the continuous rotation
    servos that are used to drive the wheels on a BOEBot. But the continuous rotation servos have no positional feedback. How do you plan
    to accomplish the positioning of the needle with a full 360 degree sweep?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Brian

    uController.com - home of SpinStudio - the modular Development system for the Propeller

    PropNIC - Add ethernet ability to your Propeller! PropJoy - Plug in a joystick and play some games!

    SD card Adapter - mass storage for the masses Audio/Video adapter add composite video and sound to your Proto Board
  • parts-man73parts-man73 Posts: 830
    edited 2009-03-09 17:41
    Also.... will there be a display of distance to the Cache?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Brian

    uController.com - home of SpinStudio - the modular Development system for the Propeller

    PropNIC - Add ethernet ability to your Propeller! PropJoy - Plug in a joystick and play some games!

    SD card Adapter - mass storage for the masses Audio/Video adapter add composite video and sound to your Proto Board
  • smbakersmbaker Posts: 164
    edited 2009-03-09 18:00
    One solution, and something that would look really cool, would be to grab a surplus aircraft ADF indicator off of ebay. Don't know how to drive such a thing though. Somewhere I actually have one of these laying around; ought to make an interesting project some weekend.
    Scott
    one small question. Most servos I have used do not have the ability to turn a full 360 degrees. Except of course the continuous rotation
    servos that are used to drive the wheels on a BOEBot. But the continuous rotation servos have no positional feedback. How do you plan
    to accomplish the positioning of the needle with a full 360 degree sweep?



  • Thomas FletcherThomas Fletcher Posts: 91
    edited 2009-03-09 18:36
    Iiiiiiiiieeeeeeeee

    Hmmm. Did not know that.

    This is a video for hacking servos for 360 movement.

    http://www.metacafe.com/watch/yt-CtLN8BoMIlQ/robot_builders_guide_3_hacking_a_servo/

    I wonder if you just stopped at the first step in the video if you could pulse up into the higher positions that become available by
    removing the locking stub.
  • parts-man73parts-man73 Posts: 830
    edited 2009-03-09 18:58
    Hacking a servo for 360 movement involves removing the potentiometer that is used for positional feedback. Thus you
    lose all feedback. You'd need some sort of position encoder to resolve direction.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Brian

    uController.com - home of SpinStudio - the modular Development system for the Propeller

    PropNIC - Add ethernet ability to your Propeller! PropJoy - Plug in a joystick and play some games!

    SD card Adapter - mass storage for the masses Audio/Video adapter add composite video and sound to your Proto Board
  • mctriviamctrivia Posts: 3,772
    edited 2009-03-09 19:11
    what you need is a grey code disk or capacitance rotary encoded. the second would work because the needle would alter the capacitance

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Need to make your prop design easier or secure? Get a PropMod has crystal, eeprom, and programing header in a 40 pin dip 0.7" pitch module with uSD reader, and RTC options.
  • bullopenebullopene Posts: 7
    edited 2009-03-09 19:12
    Sounds like a job for STEPPER MOTOR!

    hahaha
  • parts-man73parts-man73 Posts: 830
    edited 2009-03-09 19:25
    Stepper motor was my first thought too, but you'd also need an encoder for that as well. Yes, you'd have position by keeping a
    running count of the # of steps and in which direction you stepped, But if you lost a few steps here or there by bumping the needle
    position, your direction will continue to be off.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Brian

    uController.com - home of SpinStudio - the modular Development system for the Propeller

    PropNIC - Add ethernet ability to your Propeller! PropJoy - Plug in a joystick and play some games!

    SD card Adapter - mass storage for the masses Audio/Video adapter add composite video and sound to your Proto Board
  • Thomas FletcherThomas Fletcher Posts: 91
    edited 2009-03-09 19:45
    R298-1T-SERVO.jpg

    This guy sounds like he will do the trick. More money then I was planning on spending but maybe I will make a robo-owl in the future.




    www.acroname.com/robotics/parts/R298-1T-SERVO.html
  • BradCBradC Posts: 2,601
    edited 2009-03-10 00:42
    parts-man73 said...
    Stepper motor was my first thought too, but you'd also need an encoder for that as well. Yes, you'd have position by keeping a
    running count of the # of steps and in which direction you stepped, But if you lost a few steps here or there by bumping the needle
    position, your direction will continue to be off.

    A single hall-effect or photo interrupter used as a zero point calibration would solve that pretty quickly. If you were worried about bumping or otherwise you can run a quick (and it would be quick) periodic re-calibration.
    The Navman marine wind instruments are stepper driven and use a hall effect to determine zero point. Actually, now I think of it the Speedo and Tacho in my Audi were stepper units also.

    Personally I'd be using something like a mobile phone LCD or OLED and a virtual display/pointer.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cardinal Fang! Fetch the comfy chair.
  • Thomas FletcherThomas Fletcher Posts: 91
    edited 2009-03-10 00:55
    I am hoping the end result is similar to this in appearance. Sacrilege I know, but I would like it not to look like an electronic device.


    thm_POTC_104.jpg
  • CannibalRoboticsCannibalRobotics Posts: 535
    edited 2009-03-10 01:25
    You could put some LED's on the needle to indicate distance.
    Cool project!
    Jim-

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Signature space for rent, only $1.
    Send cash and signature to CannibalRobotics.
  • WhitWhit Posts: 4,191
    edited 2009-03-10 01:31
    Thomas Fletcher said...
    I am hoping the end result is similar to this in appearance. Sacrilege I know, but I would like it not to look like an electronic device.


    thm_POTC_104.jpg
    Why sacrilege? I think it is a great idea and will make a neat package.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Whit+


    "We keep moving forward, opening new doors, and doing new things, because we're curious and curiosity keeps leading us down new paths." - Walt Disney
  • grindelgrindel Posts: 68
    edited 2009-03-10 11:21
    In reality, it really might not be so bad to loose the 60 degrees of arc (or whatever the servo rotation is) since you're really
    interested in going in the direction the needle is pointing instead of getting a heading off of North. You can always take it all apart and add an encoder later.
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-03-10 12:17
    Like on propeller-clocks you could put at least the compass-sensor on the 'needle'. With a one wire device you only need one sliding contact if you transfer currency and information with this one signal. As the compas turns rather slowly you won't have to many problems with the signal quality.

    Just an idea.
  • mctriviamctrivia Posts: 3,772
    edited 2009-03-10 13:58
    you can always use a multi turn servo and if you hit limit unrap

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Need to make your prop design easier or secure? Get a PropMod has crystal, eeprom, and programing header in a 40 pin dip 0.7" pitch module with uSD reader, and RTC options.
  • BradCBradC Posts: 2,601
    edited 2009-03-10 14:02
    mctrivia said...
    you can always use a multi turn servo and if you hit limit unrap

    If you are going to do that you may as well use a stepper and a hall or photo interrupter.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cardinal Fang! Fetch the comfy chair.
  • RobertWRobertW Posts: 66
    edited 2009-03-13 03:41
    Tom,

    I read your project description and it brought back memories of me backpacking in Boy Scouts. Not to change what you had in mind for your project but I was thinking, it sounds like you are making something similar to a car GPS. If I understand the project description correctly, you are just looking for the direction to the next point. You might not need servo with a full 360 degree rotation. I am thinking that the direction of the needle only would provide a starting direction and correction indication. At the begining of your trip the needle could move to show the correct starting direction. If the endpoint was to your left, the needle could turn 90 degrees to the left, etc. As you physically start to turn in the correct direction, the needle would also start moving until it points straight in front of you. If you change directions from a straight line than the needle would move accordingly. With this type of movement, any points behind you could still be 'pointed to' by having the servo turn to it's max roation in the correct direction. As you turn in the correct direction, again, the needle would eventually point straight forward. Just a thought. Good luck.
  • Thomas FletcherThomas Fletcher Posts: 91
    edited 2009-03-13 17:00
    I went ahead and ordered the 360 degree servo above, but if it doesn't work out I will try that. I also have some micro servos on the way. I was hoping to keep the device footprint small and your idea would allow me to use the micros.

    I also liked the idea a while back of using leds on the needle as distance indicators. My needle is actually going to be a disk with an arrow and I thought about lighting up the arrow to show >3,000ft on down to within 10ft with 5 or 6 leds, but I can't decide
    which way sounds better to me. Should the lights go out to the tip of arrow as you get closer? Or should the lights move back toward the center as you get closer?

    I am also wondering about the wiring. I was thinking of using two disks with the bottom stationary wired disk having conductive tracks that powers the leds on the top moving disk (bumper car style) but I am wondering if this could cause sparks.
  • mctriviamctrivia Posts: 3,772
    edited 2009-03-13 18:45
    sparks will not be a problem at low voltages and current. also if they exist does not mean it is damaging anything.

    there should be more leds the closer you get think wifi finder and stronger signal if closer

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Need to make your prop design easier or secure? Get a PropMod has crystal, eeprom, and programing header in a 40 pin dip 0.7" pitch module with uSD reader, and RTC options.
  • David GitzDavid Gitz Posts: 4
    edited 2009-03-15 02:24
    Why don't you just gear it up? If you gear a 180 degree turn servo up by 2, you'll get 360 out of it, although it will be half as accurate.
  • Thomas FletcherThomas Fletcher Posts: 91
    edited 2009-03-19 18:56
    demoboard.jpg

    I am making progress. I now have a very expensive compass. I haven't purchased a GPS yet so now it is just pointing north.

    I haven't been able to get the 1T 360 servo to work at all as I believe it needs it's own power supply.

    I was able to get the micro servos I got off of EBay for $5 each to work and used RobertW's suggestion to make use of the sub 90 degree arc of the servo.

    I really like the effect but the servo is a lot louder then I thought they would be. Is there a whisper quite servo?
Sign In or Register to comment.