Shop OBEX P1 Docs P2 Docs Learn Events
Compass sensor.... Wich one is best for propeller? — Parallax Forums

Compass sensor.... Wich one is best for propeller?

BotdocterBotdocter Posts: 271
edited 2011-02-09 19:56 in Propeller 1
Hello guys,

I want to add a compass module to my robot. I looked some up but the best modules don't have propeller code in the obex.

I had a look at the hm55b and the hm6345. Those seem to output raw data so i must filter it before i can use it. Also they don't have tilt compensation.

Preferably i would like this one: Devantech CMPS09 compass

It also has a accelerometer build in.

There is no propeller code for it though. Would it be hard to interface to it?
It has a i2c, pwm and serial output.

Any other suggestions are welcome!!

Comments

  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-02-04 09:23
    don't have propeller code in the obex.
    There is no propeller code for it though.

    It's obvious your keyboard is working -- write some code! :smile:

    The CMPS09 is an I2C device and there are plenty of I2C objects available.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-02-04 09:53
    Botdoctor,

    There is an object for the MicroMag 3-Axis Magnetometer. Sparkfun also sells another triple axis magnetometer for $10 less than the MicroMag. The less expensive one uses I2C.

    I think one of the downside to these magnetometers is you would need to write the calibration software yourself (which could be fun, it's on my todo list).

    I couldn't find the Ap Note about calibration online so I'm attaching a copy.

    Duane

    Ap_Note_Multipoint_Calibration_Primer_(APNOTE_-_1001766_-_R01).pdf
  • John AbshierJohn Abshier Posts: 1,116
    edited 2011-02-04 14:49
    I have that compass. Some code is attached. I mounted it to a Traxas EMax RC truck modified to be a robot. Vibrations get measured as tilt which changes direction. Heavy duty filtering will be required . A couple feet of "global warming" has put project on hold.

    John Abshier
  • BotdocterBotdocter Posts: 271
    edited 2011-02-04 18:45
    Thank you! That helps a lot!

    Do you happen to know where to find info on how to calibrate?

    And how is that with the HM55B?
  • John AbshierJohn Abshier Posts: 1,116
    edited 2011-02-05 07:42
    Link to CMPS09 technical data http://www.robot-electronics.co.uk/htm/cmps09doc.htm

    John Abshier
  • BotdocterBotdocter Posts: 271
    edited 2011-02-06 05:12
    Thank you! I ordered it yesterday! Should be herr on tuesday... Woohoo!

    @Johnny Mac:

    I know i could write my own. But since my project is quite big (for me) i'd like to use the most compatible options so atleast i know that it should work with the code that was written for it.

    I also bought a IR Thermometer sensor. To measure body temp. This one has propeller code allready in the obex.


    Anyway, thank you!
  • BotdocterBotdocter Posts: 271
    edited 2011-02-07 21:35
    I have that compass. Some code is attached. I mounted it to a Traxas EMax RC truck modified to be a robot. Vibrations get measured as tilt which changes direction. Heavy duty filtering will be required . A couple feet of "global warming" has put project on hold.

    John Abshier

    Did you manage to get it together with the gps data? Or in other words: Do you know how i can calculate the compass and gps so i can let my bot drive from point 1 (robot locat.) to point 2? I have searched all over the internet but can't find any clear formula( that i can read)
  • HughHugh Posts: 362
    edited 2011-02-07 23:04
    Botdocter wrote: »
    Did you manage to get it together with the gps data? Or in other words: Do you know how i can calculate the compass and gps so i can let my bot drive from point 1 (robot locat.) to point 2? I have searched all over the internet but can't find any clear formula( that i can read)
    If I remember correctly (and that's a big 'if'!) one of the GPS NMEA-parsing objects in the Obex have PUBs that allow the bearing from one lat/long to another to be calculated. Otherwise, Google 'rhumb line'!

    Hope this helps,

    Hugh
  • RS_JimRS_Jim Posts: 1,768
    edited 2011-02-08 05:35
    Botdocter,
    The obex reference is "GPS Float Demo" It includes all of the NEMA string parsing and a rumbline navigation demo. I have played with it some to test my GPS receiver and it works well!.
    RS_Jim
  • BotdocterBotdocter Posts: 271
    edited 2011-02-08 05:47
    Thank you guys! I indeed found it in the obex.

    Allthough i don't need the parsing script since that is done by roborealm on the pc. (usb gps mouse)
    And can i add my compass to this code too?
  • BotdocterBotdocter Posts: 271
    edited 2011-02-09 19:56
    The compass is working very steady! With the code you posted.
    Now that it's working i'm going to the next step.

    Could anyone tell me (help me) to convert this into spin?
    It is for calculating the bearing from robot location to end location.
    Formula: θ*= atan2( sin(Δlong).cos(lat2),
    cos(lat1).sin(lat2) − sin(lat1).cos(lat2).cos(Δlong) )
    JavaScript:
    var y = Math.sin(dLon) * Math.cos(lat2);
    var x = Math.cos(lat1)*Math.sin(lat2) -
    Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);
    var brng = Math.atan2(y, x).toBrng();
    Excel: =ATAN2(COS(lat1)*SIN(lat2)-SIN(lat1)*COS(lat2)*COS(lon2-lon1), SIN(lon2-lon1)*COS(lat2))
    Since atan2 returns values in the range -π ... +π (that is, -180° ... +180°), to normalise the result to a compass bearing (in the range 0° ... 360°, with -ve values transformed into the range 180° ... 360°), convert to degrees and then use (θ+360)*%*360, where % is modulo.

    This is the initial bearing which if followed in a straight line along a great-circle arc (orthodrome) will take you from the start point to the end point; in general, the bearing you are following will have varied by the time you get to the end point (if you were to go from say 35°N,45°E (Baghdad) to 35°N,135°E (Osaka), you would start on a bearing of 60° and end up on a bearing of 120°!).

    For final bearing, simply take the initial bearing from the end point to the start point and reverse it (using θ = (θ+180) % 360).
Sign In or Register to comment.