MomsFriendlyRobotCompany / nxp_imu

Python drivers for Adafruit Precision NXP 9-DOF
https://pypi.org/project/nxp-imu/
MIT License
8 stars 4 forks source link

cal.py doesn't work #6

Open vicmortelmans opened 2 years ago

vicmortelmans commented 2 years ago

Hi,

The roll and pitch readouts seem OK, but the heading doesn't. So I thought perhaps a calibration is needed, because heading relies mostly on the magnetic sensor. The papers in docs are a bit over my head, but I noticed a script cal.py in examples that may be of help?

(Note that my application is a rigid setup, so I can't have users do the '8-movement').

Sadly, the script fails:

Traceback (most recent call last):
  File "/home/nymea/heliostaat/./nxp-imu-cal.py", line 34, in <module>
    accel.write8(0x2B, 0x40)
  File "/home/nymea/.local/lib/python3.9/site-packages/nxp_imu/I2C.py", line 44, in write8
    self.i2c.write_byte_data(self.address, reg, data)
  File "/home/nymea/.local/lib/python3.9/site-packages/smbus2/smbus2.py", line 455, in write_byte_data
    ioctl(self.fd, I2C_SMBUS, msg)
OSError: [Errno 121] Remote I/O error

It seems to go wrong on issuing a soft reset. Looking at the traceback, this is done over I2C. The board has a dedicated RST pin, as well as some interrupt pins, which I did not connect to my Raspberry Pi; I only connected the two I2C pins (and power). Is that OK, or does the script rely on the other pins to be connected as well?

Best regards, Vic

walchko commented 2 years ago

I only used the I2C interface if I remember correctly.

Yes, roll and pitch are easier because they reference gravity which is always down. Heading is harder and the Earth's magnetic field is really weak and other magnetic fields can throw off your compass. So you have to calibrate it for hard and soft iron distortions. You can collect a lot of data in known orientations and do a least squares thing to calculate the corrections. So you can try something like this.

vicmortelmans commented 2 years ago

Hi,

thanks... all this calibrating is looking fairly complicated, even though I have an engineering degree in applied sciences :( And I don't seem to find any ready-made python modules for doing this.

What it should measure is the angle of a panel that is vertically hinged to another panel, fixed on the wall, so it's basically like a door. Fixing the sensor to the door, I thought the heading would be a good way to measure this. But the sensor being fixed limits the possibility for calibration, I reckon.

My plan B is to use a permanent magnet in a fixed position nearby the sensor, so the sensor can measure the relative angle towards that magnet... Not sure though if that will work out.

Best regards, Vic

May 12, 2022 04:10:31 Kevin @.***>:

I only used the I2C interface if I remember correctly.

Yes, roll and pitch are easier because they reference gravity which is always down. Heading is harder and the Earth's magnetic field is really weak and other magnetic fields can throw off your compass. So you have to calibrate it for hard and soft iron distortions. You can collect a lot of data in known orientations and do a least squares thing to calculate the corrections. So you can try something like this[https://github.com/walchko/bearsnacks/blob/main/navigation-and-mapping/inertial-navigation/calibration-magnetometer/calibrate-magnetometer.ipynb].

— Reply to this email directly, view it on GitHub[https://github.com/MomsFriendlyRobotCompany/nxp_imu/issues/6#issuecomment-1124457860], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AABHZDF2D57FAGCFZLU33E3VJRSBFANCNFSM5VWGKUAA]. You are receiving this because you authored the thread.