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.
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.
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.
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.