Ask Your Question
0

Twist with covariance stamped Compass heading

asked 2018-04-22 14:03:29 -0500

Lion31 gravatar image

updated 2018-04-23 00:57:09 -0500

gvdhoorn gravatar image

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.

Here is the heading code:

#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() {
  compass.read();

  /*
  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

    compass.heading((LSM303::vector<int>){0, 0, 1});

  to use the +Z axis as a reference.
  */
  float heading = compass.heading();

  Serial.println(heading);
  delay(100);
}
edit retag flag offensive close merge delete

Comments

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.

gvdhoorn gravatar imagegvdhoorn ( 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?

mohsen gravatar imagemohsen ( 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.

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

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-04-22 16:42:50 -0500

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2018-04-22 14:03:29 -0500

Seen: 75 times

Last updated: Apr 23 '18