Giter VIP home page Giter VIP logo

rtimulib2's Introduction

RTIMULib2 - a versatile C++ and Python 9-dof, 10-dof and 11-dof IMU library

RTIMULib2 is an easy way to connect a 9-dof, 10-dof or 11-dof IMU to an embedded Linux system and obtain RTQF or Kalman-filtered quaternion or Euler angle pose data. Basically, two simple function calls (IMUInit() and IMURead()) are pretty much all that's needed to integrate RTIMULib2.

RTIMULib2 is the second version of the original RTIMULib library. The main change is the addition of the runtime magnetometer calibration functionality.

*** Magnetometer calibration is critical for good performance and, with some IMU chips, meaningful fusion results will not be obtained at all unless the magnetometers have been calibrated ***

Note: We will start long-term support for this project, and new features will be added.

Other versions

RTIMULib2 has been extended to support some other IMUs:

Demo Apps

The Linux directory contains the main demo apps for embedded Linux systems:

  • RTIMULibDrive is a simple app that shows to to use the RTIMULib library in a basic way.
  • RTIMULibDrive10 adds support for pressure/temperature sensors.
  • RTIMULibDrive11 adds support for pressure/temperature/humidity sensors.
  • RTIMULibCal is a command line calibration tool for the magnetometers and accelerometers.
  • RTIMULibvrpn shows how to use RTIMULib with vrpn.
  • RTIMULibDemo is a simple GUI app that displays the fused IMU data in real-time.
  • RTIMULibDemoGL adds OpenGL visualization to RTIMULibDemo.

RTIMULib is a C++ library but there are also Python bindings in Linux/python. Build and install the Python RTIMULib library using the provided setup.py after which any Python script will have access to RTIMULib functionality. See Linux/python.README.md for more details. Two demo scripts show how to use the Python interface.

RTIMULib works with the following IMUs:

  • InvenSense MPU-9150 single chip IMU.
  • InvenSense MPU-6050 plus HMC5883 magnetometer on MPU-6050's aux bus (handled by the MPU-9150 driver).
  • InvenSense MPU-6050 gyros + acclerometers. Treated as MPU-9150 without magnetometers.
  • InvenSense MPU-9250 single chip IMU (I2C and SPI).
  • STM LSM9DS0 single chip IMU.
  • STM LSM9DS1 single chip IMU.
  • L3GD20H + LSM303D (optionally with the LPS25H) as used on the Pololu AltIMU-10 v4.
  • L3GD20 + LSM303DLHC as used on the Adafruit 9-dof (older version with GD20 gyro) IMU.
  • L3GD20H + LSM303DLHC (optionally with BMP180) as used on the new Adafruit 10-dof IMU.
  • Bosch BMX055 (although magnetometer support is experimental currently).
  • Bosch BNO055 IMU with onchip fusion. Note: will not work reliably with RaspberryPi/Pi2 due to clock-stretching issues.
  • HMC5883L compass + ADXL345 accelerometer + L3G4200D gyro.

The LSM9DS1 implementation was generously supplied by XECDesign.

Pressure/temperature sensing works with the following pressure sensors:

  • BMP180
  • LPS25H
  • MS5611
  • MS5637

Humidity/temperature sensing is supported for the following humidity sensors:

  • HTS221
  • HTU21D

The humidity infrastructure and HTS221 support was generously supplied by XECDesign. It follows the model used by the pressure infrastructure - see RTIMULibDrive11 for an example of how to use this.

Note that currently only pressure and humidity sensors connected via I2C are supported. Also, an MS5637 sensor will be auto-detected as an MS5611. To get the correct processing for the MS5637, edit the RTIMULib.ini file and set PressureType=5.

By default, RTIMULib will try to autodiscover IMUs, pressure and humidity sensors on I2C and SPI busses (only IMUs on the SPI bus). This will use I2C bus 1 and SPI bus 0 although this can be changed by hand editing the .ini settings file (usually called RTIMULib.ini) loaded/saved in the current working directory by any of the RTIMULib apps. RTIMULib.ini is self-documenting making it easy to edit. Alternatively, RTIMULibDemo and RTIMULibDemoGL provide a GUI interface for changing some of the major settings in the .ini file.

RTIMULib also supports multiple sensor integration fusion filters such as RTQF and Kalman filters.

Two types of platforms are supported:

  • Embedded Linux. RTIMULib works with the Raspberry Pi (Raspbian). Demo apps for these can be found in the Linux directory and instructions for building and running can be found there. Its prerequisites are very simple - just I2C support on the target system along with the standard build-essential (included in the Raspberry Pi Raspbian distribution by default).

  • Desktop (Ubuntu/Windows/Mac). There are two apps (RTHostIMU and RTHostIMUGL) that allow the sensor fusion to be separated from the sensor interfacing and data collection. An Arduino (running the RTArduLinkIMU sketch from the RTIMULib-Arduino repo) fitted with an IMU chip collects the sensor data and sends it to the desktop. RTHostIMU and RTHostIMUGL (this one has an OpenGL visualization of the data) communicate with the Arduino via a USB connection.

The MPU-9250 and SPI driver code is based on code generously supplied by [email protected] (www.clickdrive.io). I am sure that any bugs that may exist are due to my integration efforts and not the quality of the supplied code!

RTIMULib2 is licensed under the MIT license.

Repo structure

RTIMULib

This is the actual RTIMULib library source. Custom apps only need to include this library.

Linux

This directory contains the embedded Linux demo apps (for Raspberry Pi and Intel Edison) and also the Python interface to RTIMULib.

RTHost

Native Applications

RTHost contains the two apps, RTHost and RTHostGL, that can be used by desktops that don't have direct connection to an IMU (as they don't have I2C or SPI interfaces). An Arduino running RTArduLinkIMU from the RTIMULib-Arduino repo provides the hardware interface and a USB cable provides the connection between the desktop and the Arduino.

ROS support

Thanks apiyap' contributions, RTIMULib2 is available in ROS, the node code is under RTHost/ros

RTEllipsoidFit

This contains Octave code used by the ellipsiod fit data generation in RTIMULibCal, RTIMULibDemo, RTIMULibDemoGL, RTHostIMU and RTHostIMUGL. It's important that a copy of this directory is at the same level, or the one above, the app's working directory or ellipsoid fit data generation will fail.

Note about magnetometer (compass) calibration

For many IMUs, fused data may be completely unusable unless the magnetometers have been calibrated.

RTIMULib2 has two mechanisms that can be used to calibrate the magnetometers:

  • Manual calibration. This is where a tool such as RTIMULibCal has been used to add magnetometer calibration data to the RTIMULib.ini file. Once this is done, there should be no need to repeat calibration unless the magnetic environment changes. Check the Calibration.pdf document for more details regarding manual calibration.

  • Runtime calibration. This mechanism is used if there is no manual calibration data. The magnetometers will remain uncalibrated until a sufficient range of readings has been obtained in each of the axes. The code will continue to monitor magnetometer readings for new maxima and minima and update the calibration data as required. This data is not saved so the procedure will start from scratch if the code is restarted.

Also, if using a non-standard axis rotation, magnetometer calibration (and accelerometer calibration if that has been performed) MUST be run AFTER changing the axis rotation.

rtimulib2's People

Contributors

hongshitan avatar jeff-loughlin avatar jumpy88 avatar r-b-us avatar siverthavso avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

rtimulib2's Issues

[Question] Orientation of MPU9250 and MPU9150 axis

I'm struggling to see why the orientation is handled the way it is for the MPU9250 (and similarly for the MPU9150), and have been getting unexpected outputs from the fusion with an offset on the z axis.

The relevant lines are:

m_imuData.gyro.setX(m_imuData.gyro.x());
m_imuData.gyro.setY(-m_imuData.gyro.y());
m_imuData.gyro.setZ(-m_imuData.gyro.z());
// sort out accel data;
m_imuData.accel.setX(-m_imuData.accel.x());
// use the compass fuse data adjustments
m_imuData.compass.setX(m_imuData.compass.x() * m_compassAdjust[0]);
m_imuData.compass.setY(m_imuData.compass.y() * m_compassAdjust[1]);
m_imuData.compass.setZ(m_imuData.compass.z() * m_compassAdjust[2]);
// sort out compass axes
float temp;
temp = m_imuData.compass.x();
m_imuData.compass.setX(m_imuData.compass.y());
m_imuData.compass.setY(-temp);

Natively, the compass follows a North-East-Down (NED) frame convention, while the accelerometer and gyroscope is using East-North-Up (ENU) convention:

AxisOrientation

As RTIMULib expects the default orientation to be NED, I would have expected the accelerometer and gyroscope to have their x and y axis swapped and z axis flipped to bring it into the same orientation as the compass which is already in NED.

With the current solution, the y and z axis of the gyroscope is flipped which also brings it into NED, but 180 degrees offset from the native compass orientation:

mpu9250

The accelerometer only has its x axis flipped with its z axis left pointing up. Which neither follows NED nor ENU.

The compass has its x axis flipped then swapped with the y axis. Effectively rotating them 90 degrees, but it does not add an accompanying 90 degree offset on the z axis.

I might be misunderstanding completely, and am not very familiar with the core RTIMULib library codebase. What's the reason it's been done this way?

CPP ellipsoid fit used instead of Octave code during calibration

I was recently discovered that there is now a cpp calibration programme for the ellipsoid fit in this repo of RTIMULib2. This is great news.

Is anybody working on using it instead of the Octave (matlab) code from the calibration functions? I am happy to work on this but would prefer to avoid duplication of effort!

Kalman filter design issue in RTIMULib2

I see the process model used in Kalman filter implementation in RTImuLib2 doesn't estimate biases. So it will only work for inputs without biases.

Good Kalman filter process model should have biases of the sensors as state variables and estimate and eliminate them as it goes.

Covariance Matrix not Generated.

After calibrating either using RTQF or Kalman, covariance matrix is not generated. I have tried calibration both through RTIMULibCal and RTIMUDemoGL, and the RTIMULib.ini generated does not contain the covariance matrix for linear acceleration, orientation and angular velocity. Does this library generate the covariance matrices or should it be filled in through some other method?

STM LSM9DS1 using SPI

Hi, I am trying to use RTIMULib2 on a Raspberry Pi model 3B+ running Ubuntu 20.04 with an SPI attached LSM9DS1 IMU. After compiling and installing the library, I get this output whenever I run RTIMULibDrive:

Settings file RTIMULib.ini loaded
********************************************verison : 1.2
Using fusion algorithm RTQF
min/max compass calibration not in use
Ellipsoid compass calibration not in use
Accel calibration not in use
Incorrect LSM9DS1 accel/mag id 104

The modified parts of RTIMULib.ini are:

# #####################################################################
# 
# RTIMULib settings file

# General settings
# 

# IMU type - 
#   0 = Auto discover
#   1 = Null (used when data is provided from a remote IMU
#   2 = InvenSense MPU-9150
#   3 = STM L3GD20H + LSM303D
#   4 = STM L3GD20 + LSM303DLHC
#   5 = STM LSM9DS0
#   6 = STM LSM9DS1
#   7 = InvenSense MPU-9250
#   8 = STM L3GD20H + LSM303DLHC
#   9 = Bosch BMX055
#   10 = Bosch BNX055
#   11 = HMC5883L + ADXL345 + L3G4200D
IMUType=6

# 
# Fusion type type - 
#   0 - Null. Use if only sensor data required without fusion
#   1 - Kalman STATE4
#   2 - RTQF
FusionType=2

# 
# Is bus I2C: 'true' for I2C, 'false' for SPI
BusIsI2C=false

# 
# I2C Bus (between 0 and 7) 
I2CBus=1

# 
# SPI Bus (between 0 and 7) 
SPIBus=0

# 
# SPI select (between 0 and 1) 
SPISelect=0

# 
# SPI Speed in Hz
SPISpeed=500000

# 
# I2C slave address (filled in automatically by auto discover) 
I2CSlaveAddress=107

If the IMU is connected on the I2C bus, RTIMULib works correctly.

Using AccelGyroMag.py and modifying lsm9ds1.py on lines 34 and 35, where SPI device is 0 for Accelerometer and Gyroscope and 1 for the Magnetometer, works. So I am assuming it is not a SPI port configuration issue.

If there is some information missing just let me know and I add as needed.

Thanks in advance!

Some questions about the RTIMUHal class

Hello @HongshiTan
I'm using code from another repo written for teensy, and I rewrote it for Arduino and compiling it for stm32f411.

https://github.com/uutzinger/RTIMULib2-Teensy/

Unfortunately for me, there is no way to discuss code and stuff in this repo.
In the repository

https://github.com/HongshiTan/RTIMULib2/

there is such a possibility, but the RTIMUHal class is a little different, or rather more functional and advanced, but the meaning is the same.
I'm wondering what the case-insensitive read functionality is used for?

 bool HALRead(unsigned char slaveAddr, unsigned char regAddr, unsigned char length,
 unsigned char *data, const char *errorMsg); // normal read with register select
 bool HALRead(unsigned char slaveAddr, unsigned char length,
 unsigned char *data, const char *errorMsg); // read without register select

Actually, I had a problem with compilation when the code had such a strange reading initialization:
I2Cdev::readBytes(slaveAddr, regAddr, length, data, 10)
which I replaced with:
I2Cdev::readBytes(slaveAddr, regAddr, length, data)
And also had to add a new function to the library
I2Cdev.h and I2Cdev.cpp
static int8_t readBytes(uint8_t devAddr, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout, void *wireObj=0);
But this is not used anywhere in the code, which is why it caused strangeness.
Can someone tell me what this is used for?
I mean, when is regAddr not needed?
P.S. Perhaps this issue can be converted into discussions?

Support for new IMU/MAG ISM330DHCX/MMC5983MA from sparkfun

Hi there, I am trying to calibrate the following Sparkfun IMU/MAG SparkFun 9DoF IMU Breakout - ISM330DHCX, MMC5983MA, the device is not detected, I get the following:

$ RTIMULibCal
RTIMULibCal - using RTIMULib.ini
Settings file RTIMULib.ini loaded
Failed to open SPI bus 0, select 0
Failed to open SPI bus 0, select 1
No IMU detected
Using fusion algorithm RTQF
No IMU found

Devices are detected here

$ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: 30 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- 6b -- -- -- --
70: -- -- -- -- -- -- -- --

From the hookup-guide there is sample code to be used on an Arduino, I am using a rpi3 with Ubuntu 20.04.

I was hoping you can point me feasibility to add a new device to the list and make it work? Not sure where and what to modify? From the previous link the libraries are here

thanks in advance, regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.