viewtopic.php?f=104&t=109064&p=750616#p810193
Steps 8 to 19 are still relevant.
Hi all, okay so Astro Pi kits are imminently going to be landing on doorsteps so I thought I should get this information online asap!
You'll probably have noticed the file RTIMULib.ini appearing in the same folder as your python programs. This is because the Astro Pi python module uses a another library behind the scenes called RTIMU.
The ini file mentioned above is used to store the Magnetometer calibration data. By default your ini files will be empty of calibration data though. Without this data you'll find that the compass functions don't behave in the way you expect them to.
For example I expect many of you have found that the compass.py example program shows a blue pixel that doesn't move very much?
To fix this we need to do two things:
- Run the calibration program. This will then create a new copy of RTIMULib.ini containing the Magnetometer calibration data.
- Copy the new RTIMULib.ini file to the folder where your python programs are.
- Log in to your Astro Pi in the usual way and from the command prompt (or a Terminal window) and enter the following command:
Code: Select all
cd ~/RTIMULib/Linux/RTIMULibCal/ - Then enter the command:
Code: Select all
make - If you see the following error...
...then do the following steps, otherwise go straight to step 4.
Code: Select all
RTIMU.cpp:(.text+0x1c8): undefined reference to `RTIMULSM9DS1::RTIMULSM9DS1(RTIMUSettings*)' collect2: ld returned 1 exit status Makefile:102: recipe for target 'Output/RTIMULibCal' failed make: *** [Output/RTIMULibCal] Error 1
I know this looks complex but it's easy, you're just editing a text file and running the make command again. Easy as pie!Locate the following line:Code: Select all
nano MakefilePlace your cursor at the start of the line and press ALT-6 followed by CTRL-U and this should duplicate the line.Code: Select all
$(RTIMULIBPATH)/IMUDrivers/RTIMULSM9DS0.h \
Edit the DS0 at the end of the new line so that it says DS1 like this:Then locate this line further down:Code: Select all
$(RTIMULIBPATH)/IMUDrivers/RTIMULSM9DS0.h \ $(RTIMULIBPATH)/IMUDrivers/RTIMULSM9DS1.h \Place your cursor at the start of the line and press ALT-6 followed by CTRL-U and this should duplicate the line.Code: Select all
objects/RTIMULSM9DS0.o \
Edit the DS0 at the end of the new line so that it says DS1 like this:Press CTRL-O followed by Enter to save.Code: Select all
objects/RTIMULSM9DS0.o \ objects/RTIMULSM9DS1.o \
Then press CTRL-X to quit nano.
Now run make again and it should work.Code: Select all
make - Now run the ls command and you should see that two folders were created, objects and Output.
Code: Select all
ls - Go into the Output folder using the following commands:
Code: Select all
cd Output ls - The file RTIMULibCal should show in green text. This is the calibration program we need to run.
- Run the program with this command:
Code: Select all
sudo ./RTIMULibCal - You will then see this menu:
Code: Select all
Options are: m - calibrate magnetometer with min/max e - calibrate magnetometer with ellipsoid (do min/max first) a - calibrate accelerometers x - exit Enter option: - Press lower case m
- This message will then show, press any key to start.
Code: Select all
Magnetometer min/max calibration -------------------------------- Waggle the IMU chip around, ensuring that all six axes (+x, -x, +y, -y and +z, -z) go through their extrema. When all extrema have been achieved, enter 's' to save, 'r' to reset or 'x' to abort and discard the data. Press any key to start... - After it starts you will see this kind of thing scrolling up the screen.
Code: Select all
Min x: 51.60 min y: 69.39 min z: 65.91 Max x: 53.15 max y: 70.97 max z: 67.97 - Focus on the two lines at the very bottom of the screen as these are the most recently posted measurements from the program.
- Now you have to move the Astro Pi around in every possible way you can think of.
It helps if you unplug all non essential cables so you don't create a birds nest
- Try and get a complete circle in each of the pitch, roll and yaw axes.
- TAKE CARE TO NOT ACCIDENTALLY EJECT THE SD CARD WHEN YOU'RE DOING THIS.
- Spend a few minutes doing this and stop when you find that the numbers are not changing any more.
- Now press lower case s
- Now press lower case x to exit the program.
- If you run the ls command now you'll see a new RTIMULib.ini file has been created.
Code: Select all
ls - This is the file we need to copy. You can copy this to wherever your python programs are saved to make use of the calibration data.
- If your python programs are saved in the home folder then use this command to copy it:
Code: Select all
sudo cp ./RTIMULib.ini ~ - Or if you want to try out the compass.py example with the calibration data then use this command to copy it:
Code: Select all
sudo cp ./RTIMULib.ini ~/astro-pi-hat/examples/ - Then to run the compass demo you would use these commands:
If you rotate the Astro Pi around like a compass now the blue pixel should chase around the edge.
Code: Select all
cd ~/astro-pi-hat/examples/ sudo ./compass.py
Thanks for reading.
P.S. ShiftPlusOne may reply with further information on how to do the ellipsoid calibration in due course, which is a more advanced form of calibration for the best possible results.

