IMU Calibration (compass and tilt)


#1

I am confused as to how you are currently doing compass and tilt calibration.

I see there is a compass calibration button, but what is the procedure? Do you have a routine that does a self calibration and the user just has to move it around a lot, or do we have to have it due north then hit calibrate?

Where is the tilt,yaw,roll calibrated, if in a script please indicate the file and the sections of code? I could shim my IMU pod, but it would be nice to just adjust the values and hit save.


I can't get the IMU working
#2

I'm having the same problem, have not figured out this yet. The calibration process appears to do nothing. The same goes for depth calibration also. Tried to align compass north and click calibrate, but nothing happened.

One thing that did work though (to a certain extend), is to edit MPU9150.cpp

To the end of the script the following lines are written:

}
MPU.read();
navdata::HDGD = MPU.m_fusedEulerPose[VEC3_Z] * RAD_TO_DEGREE + 180; //need to confirm
navdata::PITC = MPU.m_fusedEulerPose[VEC3_X] * RAD_TO_DEGREE;
navdata::ROLL = MPU.m_fusedEulerPose[VEC3_Y] * RAD_TO_DEGREE;
navdata::YAW = MPU.m_fusedEulerPose[VEC3_Z] * RAD_TO_DEGREE;
}
#endif

I changed the HDGD value according to my compass offset. Whilst pointing it towards North, I read a value of -126 degrees. I then changed the "RAD_TO_DEGREE + 180" to "+126"

Saved the file, and reloaded the Arduino from cockpit. Afterwards the compass value came up with a heading value of 0 +/-2 degrees. This is in the heading part of the telemetry data shown on rights side of ROVCockpit. The compass dial that is part of the HUD did not show correct unfortunately. This still showed East as heading. Even stranger was when I then rotated the ROV towards East, verified by compass, the ROV heading showed West! Still on telemetry data, the HUD compass is far out.

Definitively a puzzle that needs solving!

As far as the other vectors like tilt and roll, I would assume applying a similar offset value would work there as well. Have not tried to change this as the values are correct in my set up.

The best would of course be if the calibration buttons in the ROV cockpit worked, but still this only handles 2 of the parameters, the rest still needs to be changed elsewhere.


#3

I tested my IMU today, I'm having the same kind of issue than you. Do you have any solution in between?

Thanks,

JYC


#4

Hi JYC:

As of right now, the only way to calibrate the pitch/roll/compass heading is to hand modify the Arduino file MPU9150.cpp. We definitely want to change this situation, but there are other software issues that are higher priority right now. If anyone wants to contribute code patches to help out with this, get yourself a GitHub account and start coding away!

-W


#5

Thanks for reply, I'll have a look if I can do something. Actually I think there is more that a calibration problem for the compass, when turning the ROV of 360° it never shows the north, I think Armand had the same kind of issue.

JYC


#6

Calibration code for the IMU has been added to github. You can grab that code as a reference. We are working on guidance on where to place the IMU to minimize interference from the Motors. All of the calibration code and updated IMU orientation code will be in the pending release.


#7

Great! many thanks for that!!

JYC


#8

Sorry I don't have much idea about linux!!

I have 2 questions concerning this:

I edited the MPU9150.cpp with the new code but it does not compile (multiple definition of `MPU9150Lib::MPU9150Lib()).

So I made also an update.sh and it seems that it does not do the update (see below) because i changed AConfig.h an MPU9150.cpp: I get "commit your changes or stash them before you can merge." How do I commit my changes or stash them?

Thanks!

* Stopping OpenROV NodeJS server openrov * ---> OpenROV NodeJS server stopped openrov [ OK ]
From git://github.com/OpenROV/openrov-software
* branch master -> FETCH_HEAD
Updating 70cda4b..d313e5c
error: Your local changes to the following files would be overwritten by merge:
arduino/OpenROV/AConfig.h
arduino/OpenROV/MPU9150.cpp
Please, commit your changes or stash them before you can merge.
Aborting
./update.sh: 5: ./update.sh: /opt/openrov/updatelinux.sh: not found
npm WARN package.json sync@0.2.2 No repository field.

> serialport@1.2.5 install /opt/openrov/node_modules/serialport
> node-gyp rebuild

make: Entering directory `/opt/openrov/node_modules/serialport/build'
CXX(target) Release/obj.target/serialport/src/serialport.o
CXX(target) Release/obj.target/serialport/src/serialport_unix.o
CXX(target) Release/obj.target/serialport/src/serialport_poller.o
SOLINK_MODULE(target) Release/obj.target/serialport.node
SOLINK_MODULE(target) Release/obj.target/serialport.node: Finished
COPY Release/serialport.node
make: Leaving directory `/opt/openrov/node_modules/serialport/build'
unpacking
staging: build dir is /tmp/tmp.NQG9xiRddt
staged src in to build folder
unpacked into folder /tmp/tmp.NQG9xiRddt
compilling in /tmp/tmp.NQG9xiRddt
Searching for Board description file (boards.txt) ... /usr/share/arduino/hardware/arduino/boards.txt
Searching for Arduino lib version file (version.txt) ... /usr/share/arduino/lib/version.txt
Detecting Arduino software version ... 1.0.5 (1.0.5)
Searching for Arduino core library ... /usr/share/arduino/hardware/arduino/cores/arduino
Searching for Arduino standard libraries ... /usr/share/arduino/libraries
Searching for Arduino variants directory ... /usr/share/arduino/hardware/arduino/variants
Searching for make ... /usr/share/arduino/hardware/tools/avr/bin/make
Searching for avr-gcc ... /usr/share/arduino/hardware/tools/avr/bin/avr-gcc
Searching for avr-g++ ... /usr/share/arduino/hardware/tools/avr/bin/avr-g++
Searching for avr-ar ... /usr/share/arduino/hardware/tools/avr/bin/avr-ar
Searching for avr-objcopy ... /usr/share/arduino/hardware/tools/avr/bin/avr-objcopy
src/OpenROV.ino
Searching for Arduino lib version file (version.txt) ... /usr/share/arduino/lib/version.txt
Detecting Arduino software version ... 1.0.5 (1.0.5)
Scanning dependencies of src
Scanning dependencies of arduino
Scanning dependencies of EEPROM
Scanning dependencies of SPI
Scanning dependencies of Wire
src/Command.cpp
src/inv_mpu_dmp_motion_driver.cpp
src/FreeMem.cpp
src/CalibrationLaser.cpp
src/MinIMU_DCM.cpp
src/Pilot.cpp
src/MPUVector3.cpp
src/MPU9150Lib.cpp
src/MS5803_14BA.cpp
src/Pin.cpp
src/MinIMU9AHRS.cpp
src/CalLib.cpp
src/MinIMU_L3G.cpp
src/Motors.cpp
src/Settings.cpp
src/CameraMount.cpp
src/Device.cpp
src/inv_mpu.cpp
src/MinIMU_I2C.cpp
src/Thrusters2X1.cpp
src/MinIMU9.cpp
src/MinIMU_LSM303.cpp
src/MPU9150.cpp
src/MinIMU_matrix.cpp
src/Timer.cpp
src/I2Cdev.cpp
src/MPU9150BK.cpp
src/MinIMU_Vector.cpp
src/openrov_servo.cpp
src/MinIMU_Output.cpp
src/MPUQuaternion.cpp
src/Cape.cpp
src/Lights.cpp
src/MinIMU_Compass.cpp
src/controllerboard25.cpp
src/OpenROV.cpp
EEPROM/EEPROM.cpp
Linking libEEPROM.a
SPI/SPI.cpp
Linking libSPI.a
Wire/utility/twi.c
Wire/Wire.cpp
Linking libWire.a
arduino/wiring_shift.c
arduino/avr-libc/realloc.c
arduino/avr-libc/malloc.c
arduino/WInterrupts.c
arduino/wiring_analog.c
arduino/wiring.c
arduino/wiring_digital.c
arduino/wiring_pulse.c
arduino/HardwareSerial.cpp
arduino/CDC.cpp
arduino/main.cpp
arduino/new.cpp
arduino/USBCore.cpp
arduino/Tone.cpp
arduino/HID.cpp
arduino/IPAddress.cpp
arduino/WMath.cpp
arduino/Print.cpp
arduino/Stream.cpp
arduino/WString.cpp
Linking libarduino.a
Linking firmware.elf
.build/mega2560/src/MPU9150.o: In function `MPU9150Lib::printAngles(float*)':
/tmp/tmp.NQG9xiRddt/src/MPU9150.cpp:453: multiple definition of `MPU9150Lib::MPU9150Lib()'
.build/mega2560/src/MPU9150Lib.o:/tmp/tmp.NQG9xiRddt/src/MPU9150Lib.cpp:452: first defined here
.build/mega2560/src/MPU9150.o: In function `MPU9150Lib::printAngles(float*)':
/tmp/tmp.NQG9xiRddt/src/MPU9150.cpp:453: multiple definition of `MPU9150Lib::MPU9150Lib()'
.build/mega2560/src/MPU9150Lib.o:/tmp/tmp.NQG9xiRddt/src/MPU9150Lib.cpp:452: first defined here
.build/mega2560/src/MPU9150.o: In function `MPU9150Lib::printAngles(float*)':
/tmp/tmp.NQG9xiRddt/src/MPU9150.cpp:453: multiple definition of `MPU9150Lib::selectDevice(int)'
.build/mega2560/src/MPU9150Lib.o:/tmp/tmp.NQG9xiRddt/src/MPU9150Lib.cpp:452: first defined here
.build/mega2560/src/MPU9150.o: In function `MPU9150Lib::printAngles(float*)':
/tmp/tmp.NQG9xiRddt/src/MPU9150.cpp:453: multiple definition of `MPU9150Lib::useAccelCal(unsigned char)'
.build/mega2560/src/MPU9150Lib.o:/tmp/tmp.NQG9xiRddt/src/MPU9150Lib.cpp:452: first defined here
.build/mega2560/src/MPU9150.o: In function `MPU9150Lib::printAngles(float*)':
/tmp/tmp.NQG9xiRddt/src/MPU9150.cpp:453: multiple definition of `MPU9150Lib::disableAccelCal()'
.build/mega2560/src/MPU9150Lib.o:/tmp/tmp.NQG9xiRddt/src/MPU9150Lib.cpp:452: first defined here
.build/mega2560/src/MPU9150.o: In function `MPU9150Lib::printAngles(float*)':
/tmp/tmp.NQG9xiRddt/src/MPU9150.cpp:453: multiple definition of `MPU9150Lib::useMagCal(unsigned char)'
.build/mega2560/src/MPU9150Lib.o:/tmp/tmp.NQG9xiRddt/src/MPU9150Lib.cpp:452: first defined here
.build/mega2560/src/MPU9150.o: In function `MPU9150Lib::printAngles(float*)':
/tmp/tmp.NQG9xiRddt/src/MPU9150.cpp:453: multiple definition of `MPU9150Lib::init(int, int, int, int)'
.build/mega2560/src/MPU9150Lib.o:/tmp/tmp.NQG9xiRddt/src/MPU9150Lib.cpp:452: first defined here
.build/mega2560/src/MPU9150.o: In function `MPU9150Lib::printAngles(float*)':
/tmp/tmp.NQG9xiRddt/src/MPU9150.cpp:453: multiple definition of `MPU9150Lib::dataFusion()'
.build/mega2560/src/MPU9150Lib.o:/tmp/tmp.NQG9xiRddt/src/MPU9150Lib.cpp:452: first defined here
.build/mega2560/src/MPU9150.o: In function `MPU9150Lib::printAngles(float*)':
/tmp/tmp.NQG9xiRddt/src/MPU9150.cpp:453: multiple definition of `MPU9150Lib::read()'
.build/mega2560/src/MPU9150Lib.o:/tmp/tmp.NQG9xiRddt/src/MPU9150Lib.cpp:452: first defined here
.build/mega2560/src/MPU9150.o: In function `MPU9150Lib::printAngles(float*)':
/tmp/tmp.NQG9xiRddt/src/MPU9150.cpp:453: multiple definition of `MPU9150Lib::printQuaternion(long*)'
.build/mega2560/src/MPU9150Lib.o:/tmp/tmp.NQG9xiRddt/src/MPU9150Lib.cpp:452: first defined here
.build/mega2560/src/MPU9150.o: In function `MPU9150Lib::printAngles(float*)':
/tmp/tmp.NQG9xiRddt/src/MPU9150.cpp:453: multiple definition of `MPU9150Lib::printQuaternion(float*)'
.build/mega2560/src/MPU9150Lib.o:/tmp/tmp.NQG9xiRddt/src/MPU9150Lib.cpp:452: first defined here
.build/mega2560/src/MPU9150.o: In function `MPU9150Lib::printAngles(float*)':
/tmp/tmp.NQG9xiRddt/src/MPU9150.cpp:453: multiple definition of `MPU9150Lib::printVector(short*)'
.build/mega2560/src/MPU9150Lib.o:/tmp/tmp.NQG9xiRddt/src/MPU9150Lib.cpp:452: first defined here
.build/mega2560/src/MPU9150.o: In function `MPU9150Lib::printAngles(float*)':
/tmp/tmp.NQG9xiRddt/src/MPU9150.cpp:453: multiple definition of `MPU9150Lib::printVector(float*)'
.build/mega2560/src/MPU9150Lib.o:/tmp/tmp.NQG9xiRddt/src/MPU9150Lib.cpp:452: first defined here
.build/mega2560/src/MPU9150.o: In function `MPU9150Lib::printAngles(float*)':
/tmp/tmp.NQG9xiRddt/src/MPU9150.cpp:453: multiple definition of `MPU9150Lib::printAngles(float*)'
.build/mega2560/src/MPU9150Lib.o:/tmp/tmp.NQG9xiRddt/src/MPU9150Lib.cpp:452: first defined here
collect2: error: ld returned 1 exit status
make: *** [.build/mega2560/firmware.elf] Error 1
Make failed with code 2
firmware-build.sh: : Compile of the Arduino image failed.
firmware-installfromsource.sh: Building Firmware Failed! Aborting
* Starting OpenROV NodeJS server openrov * ---> started OpenROV NodeJS server openrov


Compass Calibration
#9

I would like to be able to zero the IMU. I changed the MPU9150.cpp file based on my offsets (+4 deg on roll). How can I compile the new image to check if if worked?


#10

Try this guide:


#11

Has anyone written any code on how to easy calibrate (zero out) pan&tilt from the ROV? The background is a couple of instances where IMUs have been potted and ended up getting stuck on an angle, in one case at -11 degrees. Has anyone written any code to fix this from cockpit or similar, or is the only option currently available to edit the Arduino file mentioned above?


#12

Hi Roy, as per Walt’s instructions above, you need to modify the 9150.cpp file. The Pansetti library is deprecated and now lives with Richards Tech, RTIMULib, https://github.com/RTIMULib/RTIMULib, The new library contains a calibration routine and .ini file that is loaded on IMU setup. However, that doesn’t exist in the openrov-arduino world yet. Not sure what the plan is for the next release. badevguru or spiderkeys maybe able to answer that.


#13

Thanx Jim, I’ll try this out.


#14

Happy to take a PR for the change if anyone is in a hurry. The 9150 actually does have a calibration routine that runs (when you hit calibrate, the compass counts down from 360 to 0 allowing you time to move the ROV around much like you would a cell phone to calibrate the compass). I’ve not been very happy with how it works however… hopefully Richard’s new project has refined that process.


#15

Hi guys, someone may explain step by step how to fix roll tilt ? When potted the IMU was not mounted level, is offset about -4 deg on roll. I knew it could be calibrated later but sorry I’m a bit confused on how. I’ve read a lot about on it in the forum, It would be great some step by step guide for people not familiarized with Arduino, modify files etc. I’m about to take apart the IMU and shimming. OpenRov v2,7, IMU 1. I’ve updated to 30.0.2 . Thanks !


#16

Hello Marco,

To fix the roll you need to compensate 4 degrees in the code. To do this, you need to edit the file MPU9150.cpp which is located on the ROV.
You need to use SSH or Cloud9 and locate the file (somewhere like /opt/OpenRov/Arduino/src/, but i am not sure of the exact path)

Then you locate the line at the bottom that calculates the roll (use pico to edit the file, linux command: sudo pico MPU9150.cpp)

navdata::HDGD = MPU.m_fusedEulerPose[VEC3_Z] * RAD_TO_DEGREE;
navdata::PITC = MPU.m_fusedEulerPose[VEC3_X] * RAD_TO_DEGREE;
navdata::ROLL = MPU.m_fusedEulerPose[VEC3_Y] * RAD_TO_DEGREE;
navdata::YAW = MPU.m_fusedEulerPose[VEC3_Z] * RAD_TO_DEGREE;

And then change it to something like

navdata::HDGD = MPU.m_fusedEulerPose[VEC3_Z] * RAD_TO_DEGREE;
navdata::PITC = MPU.m_fusedEulerPose[VEC3_X] * RAD_TO_DEGREE;
navdata::ROLL = (MPU.m_fusedEulerPose[VEC3_Y] * RAD_TO_DEGREE)+4;
navdata::YAW = MPU.m_fusedEulerPose[VEC3_Z] * RAD_TO_DEGREE;

Then you save the file and reupload the arduino code.

You can read more here Problem with IMU/Depth Module


#17

Thank you very much Achraf !! Ok now I understand I’ll try to do that. So I can do that, by accessing to the Openrov dashboard. Right ? Good … This is the point. I didn’t know how to start… and looked for a lot in the forum… :thumbsup:


Introduction for Tilt calibration
#18

Hey there,

unfortunately I was not able to follow those instructions, did the location of that MPU9150.cpp file change in the latest built? Navigating through cloud9 was pretty messy anyway for inexperienced users. Any ideas?

Thanks a lot


#19

Hi, i have changed the the line as shown and saved it by using cloud9 . Them i have restarted the Rov,but no change in the Tilt. i have no idea .:weary:


#20

I haven’t the first idea about modifying the code. I’ve just ordered the IMU module. Does this mean it isn’t going to work out of the box?
Andy