bonzaixx1
Posts: 1
Joined: Fri Jul 14, 2017 3:36 pm

Sense Hat Magnetometer - Reporting incorrect degrees

Fri Jul 14, 2017 3:49 pm

I've seen similar issues posted around but I have been unable to get anything to work.

My project is a Pi with a Sense Hat sitting on top of a Roomba, which is controlled through the Pi. I am trying to have the Roomba rotate 90 degrees to the left from where it starts and then stop. I have it rotating and reading in the current degree, but the magnetometer never reports a value outside of the range 70-150, when it hits the edge of that range it just goes in reverse from there (ex: 71 -> 70 -> 71 again).

I have calibrated the sense hat twice now, same results both times. I am noticing one thing, which is that in the calibration example on the Pi site (https://www.raspberrypi.org/documentati ... sense-hat/) it shows the following values:
Min x: 51.60 min y: 69.39 min z: 65.91
Max x: 53.15 max y: 70.97 max z: 67.97

and the values I got were never more than low 40s. Did I somehow calibrate it wrong? I moved it every way I possibly could and the values stopped changing.

I am using dir = sense.get_compass() to get the degree value.

bensimmo
Posts: 1926
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Sense Hat Magnetometer - Reporting incorrect degrees

Fri Jul 14, 2017 7:39 pm

Is there any big magnets near it (like motors etc).
They may be interfering.

Does it do the same not on the roomba?

Wouldn't sense.get_orientation() work better for this task. Using all three sensors to work it out.
You also need to keep the polling loops quite fast iirc.

User avatar
Davespice
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 1634
Joined: Fri Oct 14, 2011 8:06 pm
Location: London, United Kingdom
Contact: Website Twitter

Re: Sense Hat Magnetometer - Reporting incorrect degrees

Thu Aug 10, 2017 8:54 am

Hi there

So that function turns off the gyroscope and accelerometer then only uses the magnetometer to give you the angle. The magnetometer is actually perturbed by all the metal in the USB ports and any casing you've got. Calibration helps to mitigate it but doesn't make it perfect.

What I think will help you is to also use gyroscope and accelerometer to get the angle. The get_orientation function will give you pitch, roll and yaw - and yaw is basically the same as the compass angle.

Try this:

Code: Select all

self.set_imu_config(True, True, True)  # Turns on gyroscope, accelerometer and magnetometer

while True:
    o = get_orientation()
    dir = o["yaw"]
    print(dir)

bensimmo
Posts: 1926
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Sense Hat Magnetometer - Reporting incorrect degrees

Fri Aug 18, 2017 9:44 am

Is it possible to use the runtime calibration with the sensehat?
So I can do the old figure of 8 we do with mobile phones?

https://github.com/RTIMULib/RTIMULib2/b ... /README.md

User avatar
Davespice
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 1634
Joined: Fri Oct 14, 2011 8:06 pm
Location: London, United Kingdom
Contact: Website Twitter

Re: Sense Hat Magnetometer - Reporting incorrect degrees

Fri Aug 18, 2017 3:57 pm

There is the ellipsoid fit calibration you can use, more info on this thread.
viewtopic.php?f=104&t=109064&p=750616#p810193

bensimmo
Posts: 1926
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Sense Hat Magnetometer - Reporting incorrect degrees

Sat Aug 19, 2017 7:40 am

Yes, but that's not at runtime and would need to be done every time you move it to a different environment if you are having problems or wanted a more 'accurate' reading.
If it was at run time, you could do the figure of 8's as a quick calibration and be on your way. It also says it can increase the boundaries as it goes.
Being in my lab is different to being out in a field and in fact here in the classrooms at a school quite different from room to room as there are a lot of equipment around and as anyone trying to use plotting compasses for empa/isa/iaa practicals would have found out, it can be a nightmare for magnetic readings ;-)

Would that need the sensehat API updating to use V2 or does it already (it just say custom in the python code). Though neither versions are developed by the original person anymore.

Just thinking of ways to make this easier than write some code to read write do save etc, given the option is there in the Lib2

Return to “Astro Pi”

Who is online

Users browsing this forum: No registered users and 1 guest