# Twist with covariance stamped Compass heading

My team and I are fairly new to ROS and we are trying to make an autonomous robot and we are using a compass to tell our heading.

The problem was we were using a borrowed IMU and acted like a compass using gyros and we got our robot to work decent with that IMU but created a lot of drift.

So we are using now a Ada Fruit LSM303DLHC compass and accelerator which has very little drift the only thing I'm struggling with is trying to get ros my arduino code to spit out a geometry message twist with covariance stamped, because that is what we had our old IMU spitting out and it worked well.

I have the arduino code that reads the heading and I have already calibrated the compass offsets. I just need to get my code to output that type of message. if anyone can help that would be greatly appreciated.

Attached you should find a picture of what the IMU was publishing.

The code is publishing integers to the Serial monitor a the moment.

#include <Wire.h>
#include <LSM303.h>

LSM303 compass;

void setup() {
Serial.begin(9600);
Wire.begin();
compass.init();
compass.enableDefault();

/*
Calibration values; the default values of +/-32767 for each axis
lead to an assumed magnetometer bias of 0. Use the Calibrate example
program to determine appropriate values for your particular unit.
*/
compass.m_min = (LSM303::vector<int16_t>){ -4096,  -4096,  -4096};
compass.m_max = (LSM303::vector<int16_t>){ +1497,  +1969,  +1482};
}

void loop() {

/*
When given no arguments, the heading() function returns the angular
difference in the horizontal plane between a default vector and
north, in degrees.

The default vector is chosen by the library to point along the
surface of the PCB, in the direction of the top of the text on the
silkscreen. This is the +X axis on the Pololu LSM303D carrier and
the -Y axis on the Pololu LSM303DLHC, LSM303DLM, and LSM303DLH
carriers.

To use a different vector as a reference, use the version of heading()
that takes a vector argument; for example, use

to use the +Z axis as a reference.
*/

delay(100);
}

edit retag close merge delete

1

May I suggest you edit your question text and add some full stops, commas and perhaps divide it up into some parapgraphs? This is just about unreadable.

( 2018-04-22 14:23:14 -0500 )edit
1

How is you system set up? Are you trying to implement your arduino code in ROS? Are sending a message from an arduino board to a computer running ROS?

( 2018-04-22 14:33:39 -0500 )edit

I hope my edits to my question help both of you understand my question a bit more thank you for the feedback.

( 2018-04-22 14:59:15 -0500 )edit

Sort by ยป oldest newest most voted

You may have a bit more work to do. The problem is that Twist messages are relative, they only include linear and angular velocities. The Compass you are using is provides absolute heading information.

The correct way to fuse the new absolute heading information with your system will not be the same as the way you were fusing the original relative angular information.

I recommend looking at the robot localization package which includes some great documentation on this matter. If you decide to use that package you'll have a very powerful EKF to estimate the position and motion of your robot.

more