Tag Archives: inertial measurement unit

Tutorial: How to read data from IMU

In the previous post I described how to setup raspberry pi for connection with the IMU.

Now it is time to see how to read some data from the sensor.

First yuo need sw that manage the i2c interface.there are many examples.You can find one called adafruit_i2c.py on github.

Then it is necessary to have the code specific for the sensor,in my case a MPU6050.

I tryied for some days to build my own code, but I encountered problems related to unconsistent results: even if I did not move the sensor, the returned results were always different. I suspect it was a problem on how I formatted the values.

Finally, Thanks to the great job done by Hove in  his blog, I used his code and I’m now able to collect correct data from the sensor.

I did some minor modification and prepare this IMU_test files.

So I started some preliminary tests to verify which is the sensor behaviour.

I fixed the sensor on a bar ,horizontally, than turned the bar by a known angle ( 13 degrees,measured with my smartphone level) then move back to horizontal.

IMU_test1

I recorded on a file the sensor data : acceleration along axis (from ACCelerometer) and rotational speed (from GYRO scope). On excel sheet  I calculated the angle around x  respect the ACC and respect the GYRO:

  • rx ACC=DEGREES(ATAN2(accZ+9.8;accY))
  • rx(i) GYRO=wx(i) *dt+wx(i-1)

Below you can see the graph.

IMU

I underline in the picture the 2 tipical problems on the IMU :

  • the Gyro drift (you can see an angle of 1  degree while it reality it was 0)
  • the Accelerometer sensibility to noise.

So next  development step is to filter/reduce this 2 problems by combining the 2 sensors results.

Advertisements

IMU Sensor Installation

Since a week ago, I ‘ve been looking into my new IMU: Inertial Measurement Unit.

I bought  from e-bay a MPU6050, a sensor including:

  • a gyroscope that can return the angular speed around the 3  axis x,y,z.
  • an accelerometer  that can return the linear acceleration along the 3  axis x,y,z.

This sensor can communicate trou I2C interface.

Below the electrical drawing:

wiring_IMUIMU_conn

 

 

 

 

 

 

 

For the sw installation I fuond a clear tutorial on the Adafruit website ,so I just report here a memo for the necessary steps:

in sudo nano /etc/modules add:

  • i2c-bcm2708
  • i2c-dev

sudo apt-get install python-smbus

sudo apt-get install i2c-tools

in sudo nano /etc/modprobe.d/raspi-blacklist.conf comment:

  • #blacklist spi-bcm2708
  • #blacklist i2c-bcm2708

Now ,running the command sudo i2cdetect -y 1  yuo have to see the address 0x68, corresponding to the default sensor address.