a Kalman filter to fuse gyro and compass readings

Discussion specific to projects ideas and support.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: a Kalman filter to fuse gyro and compass readings

Post by HaWe »

matt, you drive me to a white heat.
Using a compass addtionally, and trying to increase the odometric reliabiltity: this attempt fails. It's always worse than odometry alone.
Going ahead is almost 100% reliable (5 cm left/right deviation and 1cm distance difference when 5m going ahead), even if the ground changes from wood to carpet.
But when driving 4x90° in a square of 1m edges 4 times each, odometry gives about 20° deviation and 10-20cm distance to the start-stop-point in the end.
Using a compass for turning calculation, I had 40-50° error in heading at the end and missed the target point at the end of up to 50 cm radius.
edit: I repeatetd this dozens of times. Never the compass gave more accuracy than odometry renouncing the compass.
Last edited by HaWe on 16 Oct 2010, 12:18, edited 1 time in total.
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

Re: a Kalman filter to fuse gyro and compass readings

Post by mightor »

Don't let this thread turn into a flame war or I'll simply lock it and remove the offending posts. I am not hindered by any mathematical knowledge so I don't really care (or know) who is right or wrong but I can spot an impending flame war when I see one.

So far the only one in this argument who has shown any kind of data is Andy, so anyone who doesn't have data, kindly gather some to prove your theory before posting here again.

Thanks,
- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: a Kalman filter to fuse gyro and compass readings

Post by HaWe »

sry Xander, I posted the data already twice, the last time just over your last post - which different data will you/one expect to read?
physics-matt
Posts: 76
Joined: 29 Sep 2010, 06:57

Re: a Kalman filter to fuse gyro and compass readings

Post by physics-matt »

I think some extra information like how many times you repeated the experiment and how repeatable the results were would be helpful.

It would also be very interesting to know how the accuracies varied with the number of times the robot went round the square. Moreover, what heading did the robot think it had at the end? Did this also correspond to the heading it was trying to achieve?

Matt
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: a Kalman filter to fuse gyro and compass readings

Post by HaWe »

please write your own program and gather your own data and show us, as Xander wrote.
(Xander, you may remove the last 2 posts)

but @Xander: I read through this thread again, but I didn't find any data from Andy - which one did you mean?
The only data comparing odometry with or without compass are by myself - did I or did you miss something?

(might be deleted)
rghansen
Posts: 67
Joined: 12 Oct 2010, 17:44

Re: a Kalman filter to fuse gyro and compass readings

Post by rghansen »

mightor wrote:Don't let this thread turn into a flame war or I'll simply lock it and remove the offending posts. I am not hindered by any mathematical knowledge so I don't really care (or know) who is right or wrong but I can spot an impending flame war when I see one.


Thanks,
- Xander
Thank you Xander for stepping in.

Since I'm also working on a room mapper with odometry and was planning on buying a compass sensor to improve its performance, I'd very much like to know if the compass works so poorly that I can't use it correct the heading errors that I know will build up in the odometry code.

In any case, I'd like to thank Aswin for his excellent Kalman filter blog. It's not easy to find anything useful about Kalman filters that's not written in Greek.
gloomyandy
Posts: 323
Joined: 29 Sep 2010, 05:03

Re: a Kalman filter to fuse gyro and compass readings

Post by gloomyandy »

Ok so here is some actual data. Taken by a tracked robot equipped with both a compass sensor and with a gyro sensor. That traces 10 50cm squares, so 4 90 degree turns per iteration. The robot paused before and after each rotation to allow sensor readings to be taken without motor noise etc. causing problems. The first data set is the recorded relative values for each turn. So I read the compass/gyro value before and after the turn and recorded the delta.

Code: Select all

Odom	Comp	Gyro
90.15	85.00	89.59
90.08	88.00	90.08
89.93	96.00	92.42
90.08	88.00	89.18
90.08	85.00	90.15
90.08	91.00	90.27
90.00	94.00	92.00
90.08	89.00	90.18
90.15	85.00	89.48
90.01	91.00	91.04
90.08	95.00	91.40
90.15	88.00	90.62
90.08	85.00	88.38
90.15	90.00	88.44
90.23	96.00	89.17
90.08	91.00	89.13
90.00	89.00	91.87
90.15	91.00	91.78
90.15	94.00	91.34
90.08	90.00	90.93
90.08	89.00	91.78
90.00	96.00	91.96
90.15	95.00	90.50
90.15	90.00	91.52
89.93	88.00	91.29
89.93	92.00	91.62
89.93	95.00	89.96
90.08	89.00	91.04
89.93	87.00	91.43
90.08	92.00	91.92
90.08	93.00	90.30
90.08	88.00	89.27
90.08	86.00	90.41
89.93	91.00	91.26
90.00	95.00	91.20
89.93	88.00	90.54
90.08	88.00	91.69
89.86	90.00	91.09
89.86	93.00	90.33
90.01	90.00	90.77
The first column is the odometry data, the second from the compass and the third from the gyro. As you would expect the odometry data only has a very small variation, since all this is really showing is the accuracy of the leJOS motor driver and does not really show how the actual robot moved (if you lift the robot of the floor for the entire test the odometry data will be similar to the above despite the robot having not moved at all). The compass data range around +/- 6 degrees of the target 90 while the gyro is +/- 2 degrees.

The second set of data shows the sensed orientation of the robot after completing each square:

Code: Select all

0.10	359.00	349.60
0.12	358.00	338.04
0.30	357.00	324.99
0.69	356.00	287.70
1.09	0.00	279.08
1.49	6.00	271.52
1.44	7.00	260.09
1.54	8.00	248.18
1.49	9.00	235.99
1.20	6.00	230.93
The gyro data seems to be way off. This seems to be because of the way that it accumulates errors during the linear parts of the move and while the robot is not moving. I'm not sure why this happens and it is probably worth further investigation. I also manually measured the orientation of the robot at the end of the test (after carefully aligning the start point). The actual measured angle of the robot at the end of the test was 5 degrees.

I ran the above tests eight times and the above data is typical of the results obtained...

Finally I ran a series of 40 squares one after the other I manually measured the orientation after every 10 squares. The results are shown below:

Code: Select all

Odom	Comp	Meas
1.19	7.00	6.00
2.08	13,00	11.00
3.20	19.00	18.00
4.32	27.00	25.00
In this case I've only given values for the odometry, compass and actual measured results. Here you can clearly see how the actual position error accumulates. As the error accumulates the absolute nature of the compass provides a better indication of the robots orientation.

I'm actually surprised that the odometry values in these tests accumulate so much, I suspect this is down to the tolerances allowed in the stopping point by the leJOS motor driver...
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: a Kalman filter to fuse gyro and compass readings

Post by HaWe »

Checking the compass acuracy: do you tell the robot to go ahead by evaluating simulateously the current stream of compass data?
Or how do you tell him to go straight regardless of odometry (or motor synchronization which actually is the same)?
And how do you let him turn 90° and then stop rotation? Do you measure compass headings simulateously while turning until it's 90° more than at the start of turning?

I'm not sure what the 2nd table really shows, but it seems to me that Odometry is about 6-7 times more accurate than compass or gyro. Or am I wrong?

Code: Select all

Odom   Comp   Meas
1.19   7.00   6.00
2.08   13,00   11.00
3.20   19.00   18.00
4.32   27.00   25.00
edit:
It's not easy to find anything useful about Kalman filters that's not written in Greek.
that's really funny. I'd love to find something useful about KF that ACTUALLY IS written in Greek (or Latin, or German of course, too) ;)
Last edited by HaWe on 16 Oct 2010, 19:25, edited 1 time in total.
physics-matt
Posts: 76
Joined: 29 Sep 2010, 06:57

Re: a Kalman filter to fuse gyro and compass readings

Post by physics-matt »

gloomyandy wrote:Ok so here is some actual data.
Haha! Looks like I'm not the only one who spent an enjoyable evening collecting data ;)

I constructed a simple bot and programmed it to record its bearing before and after completing a number of laps of my kitchen floor. The bearing was measured both using the compass (readings taken before and after when the motors were off) and odometry. I also measured the bearing using a protractor, using my kitchen tiles as a reference. These are well lined up and I estimate that the protractor measurements are accurate to ground truth within 2 degrees.

The first experiment was to make the robot do a small turn on the spot. The delta (bearing at end minus bearing at start) was recorded as follows:

Code: Select all

Compass  Odo  Protractor
133         127  134
132         128  132
133         127  132
133         129  132
132         128  132
I then made the robot travel a lap of the kitchen (more or less) and the results for the delta were:

Code: Select all

Compass  Odo  Protractor
26           28     40
44           30     46
40           29     42
26           14     24
38           25     36
33           23     34
34           25     34
42           30     40
Something appears to have gone wrong with the measurement of the first run, but the others show the compass within 2 degrees of the protractor and the odometry reading consistently about 10 degrees lower.

The next set of results are for two laps of the kitchen:

Code: Select all

Compass  Odo  Protractor
52           32     50
47           26     46
36           13     34
37           14     36
33           8       30
31           5       30
25           3       24
20           358   16
This shows a similar relationship between the compass and protractor readings, but now the odometry readings are consistently about 20 degrees lower. This suggests a systematic accumulation of errors and to test this I ran the experiment again, but with all right turns turned into left turns (again, two laps of the kitchen):

Code: Select all

Compass  Odo  Protractor
185          216  176
181          216  176
187          224  186
193          229  192
194          228  194
Indeed, the odometry readings now show a consistently high value. Also note that for the first two runs the compass and protractor readings differ by a lot more than usual. This is probably because on those runs the robot finished within about 70cm of my oven (which is effectively a big lump of metal). For the remaining runs I ensured that the robot started and finished at least 1m away from any metal objects (as had been done for all previous experiments).

This is all very encouraging for the compass - it demonstrates a consistent accuracy of a couple of degrees. How do we explain the reports of poor performance then? One explanation could be stray magnetic fields, but another is the fact that the compass has to be horizontal when taking readings. To show the effect of this, I mounted it in a couple of different ways which held the compass at different angles relative to the horizontal (but all at the same bearing) and just recorded the value received from the sensor whilst the robot was stationary. The results are as follows

Code: Select all

Angle  Reading
0        165
53      172
-53     14
53      172
0        165
-53     11
I repeated the experiment a few times to ensure that mounting and re-mounting of the compass was not to blame.

The results are striking. In particular, it appears that if the compass is pointed downwards it goes way off. This is a likely explanation for poor results from the sensor, and demonstrates that it needs to be carefully mounted or calibrated to take the effect into account.

Matt
rghansen
Posts: 67
Joined: 12 Oct 2010, 17:44

Re: a Kalman filter to fuse gyro and compass readings

Post by rghansen »

gloomyandy wrote:Ok so here is some actual data. Taken by a tracked robot equipped with both a compass sensor and with a gyro sensor. That traces 10 50cm squares, so 4 90 degree turns per iteration. The robot paused before and after each rotation to allow sensor readings to be taken without motor noise etc. causing problems. The first data set is the recorded relative values for each turn. So I read the compass/gyro value before and after the turn and recorded the delta.

The first column is the odometry data, the second from the compass and the third from the gyro. As you would expect the odometry data only has a very small variation, since all this is really showing is the accuracy of the leJOS motor driver and does not really show how the actual robot moved (if you lift the robot of the floor for the entire test the odometry data will be similar to the above despite the robot having not moved at all). The compass data range around +/- 6 degrees of the target 90 while the gyro is +/- 2 degrees.

The second set of data shows the sensed orientation of the robot after completing each square:

The gyro data seems to be way off. This seems to be because of the way that it accumulates errors during the linear parts of the move and while the robot is not moving. I'm not sure why this happens and it is probably worth further investigation. I also manually measured the orientation of the robot at the end of the test (after carefully aligning the start point). The actual measured angle of the robot at the end of the test was 5 degrees.

I ran the above tests eight times and the above data is typical of the results obtained...

Finally I ran a series of 40 squares one after the other I manually measured the orientation after every 10 squares. The results are shown below:

In this case I've only given values for the odometry, compass and actual measured results. Here you can clearly see how the actual position error accumulates. As the error accumulates the absolute nature of the compass provides a better indication of the robots orientation.

I'm actually surprised that the odometry values in these tests accumulate so much, I suspect this is down to the tolerances allowed in the stopping point by the leJOS motor driver...
Thanks for the hard data. So it looks like the compass is only accurate to about +- 6 degrees, but would still be useful for correcting the odometry errors which would probably quickly exceed this value.

Did you try the things Aswin suggested in his blog in order to reduce the compass errors?

What did your robot look like? I found that the accuracy of my castor robot increased significantly when I replaced the standard slick tires with the off road tires which have a large diameter and a smaller contact area. I suspect that using the large diameter, narrow "tractor" tires that come with the education supplement kit would produce even better results, certainly better than a track driven robot.

Have you looked at philo's odometry robot http://www.philohome.com/odin/odin.htm. It's odometry pure.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests