|
|
|
|
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
November 20, 2009, 09:59:56 PM
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Search:
Advanced search
Sept 30th - New Price -
Axon
is now $94
Robot Forum
72,667
Posts in
9,267
Topics by
5,292
Members
Latest Member:
lepomis
Robot Forum
>
Software
>
Software
>
HMC6343 compass code for Axon, I2C
0 Members and 1 Guest are viewing this topic.
Pages:
[
1
]
Author
Topic: HMC6343 compass code for Axon, I2C (Read 661 times)
Admin
Administrator
Supreme Robot
Helpful? 62
Online
Posts: 8,610
HMC6343 compass code for Axon, I2C
«
on:
June 30, 2009, 06:54:38 AM »
I got a
HMC6343 Compass
hooked up to my
Axon
, using I2C. Here is some code I'd like to share . . . don't forget to include the I2C AVRlib library.
Code:
//Read HMC6343 compass I2C data:
u08 TARGET_ADDR = 0x32; //0x32 = HMC6343 compass slave write address
u08 command = 0x50; //0x50 = post heading data, pitch data, and roll data
u08 in[6]; //6 bytes = MSB heading, LSB heading, MSB pitch, LSB pitch, MSB roll, LSB roll
i2cMasterSend(TARGET_ADDR, 1, &command); //send 1 byte command to slave from master
delay_ms(10);
i2cMasterReceive(TARGET_ADDR, 6, &in[0]); //read 6 byte data from slave to master
//process heading data:
compass = in[0]; //first byte is MSB heading
compass = compass << 8; //shift MSB byte to top of int
compass = compass + in[1]; //add LSB byte (2nd byte) to bottom of int
compass = compass; // / 10;
//process pitch data:
pitchCompass = in[2]; //3rd byte is MSB pitch
pitchCompass = pitchCompass << 8;
pitchCompass = pitchCompass + in[3]; //4th byte is LSB pitch
pitchCompass = pitchCompass / 10;
if(pitchCompass > 6400)
pitchCompass = (pitchCompass - 6400 - 155); //convert to negative values
//process roll data:
rollCompass = in[4]; //5th byte is MSB roll
rollCompass = rollCompass << 8;
rollCompass = rollCompass + in[5]; //6th byte is LSB roll
rollCompass = rollCompass / 10;
if(rollCompass > 6400)
rollCompass = (rollCompass - 6400 - 155); //convert to negative values
Output of course is pitchCompass and rollCompass.
Also a comment on this compass . . . I'm using it on my robot fish. The fish uses a waterproof magnet switch . . . the magnet is weak, and 2-3 inches away from the compass, but still affects results by about +/- 13% (absolute value 27%). Hopefully that info helps someone!
edit: changed the % error, due to my own error
«
Last Edit: July 01, 2009, 10:01:40 AM by Admin
»
Logged
subscribe to SoR's YouTube account
Razor Concepts
Supreme Robot
Helpful? 33
Offline
Posts: 1,076
razorconcepts.net
Re: HMC6343 compass code for Axon, I2C
«
Reply #1 on:
June 30, 2009, 03:21:17 PM »
Are the heading readings you are getting good? I've tried using a HMC6352 (no tilt compensation) and the readings are not proportional, but in between 360 and 0 degrees.
Logged
www.razorconcepts.net
Admin
Administrator
Supreme Robot
Helpful? 62
Online
Posts: 8,610
Re: HMC6343 compass code for Axon, I2C
«
Reply #2 on:
June 30, 2009, 08:08:33 PM »
Quote from: Razor Concepts on June 30, 2009, 03:21:17 PM
Are the heading readings you are getting good? I've tried using a HMC6352 (no tilt compensation) and the readings are not proportional, but in between 360 and 0 degrees.
Hmmmm I haven't done any real testing of it yet to comment. But outside interference can definitely make it non-proportional!
Logged
subscribe to SoR's YouTube account
Ro-Bot-X
Contest Winner
Supreme Robot
Helpful? 10
Offline
Posts: 1,117
Current project: MiniEric robot.
Re: HMC6343 compass code for Axon, I2C
«
Reply #3 on:
July 01, 2009, 05:21:04 AM »
I have an old Lego compass and I have noticed that it needs a bit of time to settle if the robot was moving and the measurements are not reliable while in motion, even it it is a streight line. This sensor is similar with the Devantech CMPS03, I had the same problems with that one too. So, it may be a good idea to keep the robot still while checking the compass, then let it move. Why? because of magnetic interference from the motors.
Logged
Check out my new blog!
SeriousRobotics
Admin
Administrator
Supreme Robot
Helpful? 62
Online
Posts: 8,610
Re: HMC6343 compass code for Axon, I2C
«
Reply #4 on:
July 01, 2009, 10:03:52 AM »
Quote from: Ro-Bot-X on July 01, 2009, 05:21:04 AM
Why? because of magnetic interference from the motors.
Not to mention the power fluctuations in your system, and the 'moving' environment. What if your floor had a steel I-beam under it and you didn't know? etc.
note: I changed the reported error above, had a typo . . .
Logged
subscribe to SoR's YouTube account
Pages:
[
1
]
Jump to:
Please select a destination:
-----------------------------
General Misc
-----------------------------
=> Misc
=> Robot Videos
-----------------------------
Software
-----------------------------
=> Software
-----------------------------
Electronics
-----------------------------
=> Electronics
-----------------------------
Mechanics and Construction
-----------------------------
=> Mechanics and Construction
Related Topics
Subject
Started by
Replies
Views
Last post
Axon - New source code broken
Software
gizzerd91
9
1176
January 11, 2009, 04:57:51 AM
by
Admin
AVRcam code for the Axon
Software
mbateman
7
1097
January 09, 2009, 11:03:06 PM
by
Ro-Bot-X
PWM axon source code
Software
Its_Friday
7
886
February 09, 2009, 07:17:11 PM
by
Admin
Need some help on interrupt code (axon)
Software
Tomas
2
362
February 11, 2009, 09:10:10 PM
by
Admin
Advertise on this Forum
Loading...