MPU-9250 IMU userspace: Difference between revisions

From embeddedTS Manuals
(Fixed path)
(Updated to use our repo)
Line 5: Line 5:
Clone the repository:
Clone the repository:
<source lang="bash">
<source lang="bash">
git clone https://github.com/vmayoral/bb_mpu9150
git clone https://github.com/embeddedarm/bb_mpu9150
cd bb_mpu9150/src/linux-mpu9150/
cd bb_mpu9150/src/linux-mpu9150/
</source>
</source>
Line 12: Line 12:
Build the project:
Build the project:
<source lang="bash">
<source lang="bash">
ln -s Makefile-native Makefile
DEFS="-DMPU9250" make
# If building via a cross compiler, link in the cross Makefile
 
# ln -s Makefile-cross Makefile
# If building via a cross compiler, it can be passed on the command line:
make
CROSS_COMPILE=arm-linux-gnueabihf- DEFS="-DMPU9250" make
 
# It is also possible to specify the default I2C bus on the command line:
DEFS="-DMPU9250 -DDEFAULT_I2C_BUS=<bus>" make
</source>
</source>
See the [[#I2C|I2C section]] for a listing of the I2C buses.




Calibration has two steps, one for the accelerometer and one for the magnetometer.  The output of the calibration is saved in the current directory.  In order to properly calibrate the IMU, the tool must be started and while it is running, the whole physical device must be '''slowly''' rotated completely through every axis.  Being slow is key as this process is measuring the effect of gravity on the device for minimum and maximum values.  Rapid movements during this time will increase the forces applied and will throw off the calibration.  Once all of the axes have been rotated through, press ctrl+c to end the calibration and write the calibration file to disk.
Calibration has two steps, one for the accelerometer and one for the magnetometer.  The output of the calibration is saved in the current directory.  In order to properly calibrate the IMU, the tool must be started and while it is running, the whole physical device must be '''slowly''' rotated completely through every axis.  Being slow is key as this process is measuring the effect of gravity on the device for minimum and maximum values.  Rapid movements during this time will increase the forces applied and will throw off the calibration.  Once all of the axes have been rotated through, press ctrl+c to end the calibration and write the calibration file to disk.


Note the the proper [[#I2C|I2C bus number]] must be passed in order for the tool to communicate with the IMU.  See the [[#I2C|I2C section]] for a listing of the I2C buses.   
Note the the proper [[#I2C|I2C bus number]] must be passed in order for the tool to communicate with the IMU.  See the [[#I2C|I2C section]] for a listing of the I2C buses.  If the tool was built with the correct
<source lang="bash">
<source lang="bash">
./imucal -b<bus> -a  # To calibrate the accelerometer, must move slowly
./imucal -b<bus> -a  # To calibrate the accelerometer, must move slowly

Revision as of 15:55, 18 May 2018

This platform can support an MPU-9250 IMU (Inertial Measurement Unit) device. This provides a MEMS (Microelectromechanical Systems) gyroscope, accelerometer, and magnetometer. The physical interface is over an I2C bus, and the controlling software is entirely userspace. This allows for easy integration in to applications and reduces overhead of kernel calls. Support for this MPU-9250 is provided through a project called BB-MPU9150. While it is targeted at the MPU-9150, the MPU-9250 used on this platform is a lower power variant.

The following commands can be used to download, build, install, calibrate, and run the application for the IMU:

Clone the repository:

git clone https://github.com/embeddedarm/bb_mpu9150
cd bb_mpu9150/src/linux-mpu9150/


Build the project:

DEFS="-DMPU9250" make

# If building via a cross compiler, it can be passed on the command line:
CROSS_COMPILE=arm-linux-gnueabihf- DEFS="-DMPU9250" make

# It is also possible to specify the default I2C bus on the command line:
DEFS="-DMPU9250 -DDEFAULT_I2C_BUS=<bus>" make

See the I2C section for a listing of the I2C buses.


Calibration has two steps, one for the accelerometer and one for the magnetometer. The output of the calibration is saved in the current directory. In order to properly calibrate the IMU, the tool must be started and while it is running, the whole physical device must be slowly rotated completely through every axis. Being slow is key as this process is measuring the effect of gravity on the device for minimum and maximum values. Rapid movements during this time will increase the forces applied and will throw off the calibration. Once all of the axes have been rotated through, press ctrl+c to end the calibration and write the calibration file to disk.

Note the the proper I2C bus number must be passed in order for the tool to communicate with the IMU. See the I2C section for a listing of the I2C buses. If the tool was built with the correct

./imucal -b<bus> -a  # To calibrate the accelerometer, must move slowly
./imucal -b<bus> -m  # To calibrate the magnetometer, can move faster

The calibration tool will output 'accelcal.txt' and 'magcal.txt'. If these files are in the same folder as the 'imu' binary then they will automatically be loaded when the binary is executed.


At this point, the 'imu' binary can be run to gather and display samples of the data. The readings below were taken from a unit sitting flat on a desk after calibration was complete:

./imu -b<bus>

Initializing IMU .......... done


Entering read loop (ctrl-c to exit)

X: 1 Y: 3 Z: 76

For further information on using this tool, the various modes of operation it supports, and developing applications that use it please see the documentation in the BB-MPU9150 project github.