LMS9DS0 - Orientation, Position, and Velocity
Project Description
Use the LMS9DS0 IMU to obtain the orientatin, position, and velocity from the IMU's accelerometer data. I have included details on how to interface with the uLCD-144-G2 128x128 pixel LCD breakout. This is not necessary, but will provide the user with a means to view the output data from the IMU
Components
mbed pin | IMU pin |
---|---|
p9 | SDA |
p10 | SCL |
Vout | Vdd |
Gnd | Gnd |
mben pin | uLCD Cable |
---|---|
p27 | Rx |
p28 | Tx |
p30 | RES |
Vu | 5V |
Gnd | Gnd |
Library
Import programimu_lab4
Demo for finding orientation (pitch,roll) and velocity
Code
#include
#include "mbed.h" #include "LSM9DS0.h" #include "uLCD_4DGL.h" LSM9DS0 imu(p9, p10, LSM9DS0_G_ADDR, LSM9DS0_XM_ADDR); uLCD_4DGL lcd(p28, p27, p30);
Demo
int main() { setup(); //Setup sensor and Serial lcd.printf("------ LSM0DS0 Demo -----------\n"); while (true) { // lcd.cls(); imu.calcPitchRoll(); //calls member function to calculate pitch and roll lcd.printf("\nPitch: "); lcd.printf("%2f\n",imu.pitch); lcd.printf("Roll: "); lcd.printf("%2f\n\n",imu.roll); //print out accelerometer values from amu lcd.printf("X Accel: %2f\n",imu.ax); lcd.printf(", "); lcd.printf("Y Accel:%2f\n",imu.ay); lcd.printf(", "); lcd.printf("Z Accel: %2f\n\n",imu.az); //use global variables to integrate over discrete values //Integrate acceleration once to obtain velocity and twice to obtain position velx = oldVelx + REFRESH_TIME_MS * oldX/1000; posx = oldPosx + REFRESH_TIME_MS * oldVelx/1000; vely = oldVely + REFRESH_TIME_MS * oldY/1000; posy = oldPosy + REFRESH_TIME_MS * oldVely/1000; velz = oldVelz + REFRESH_TIME_MS * oldZ/1000; posz = oldPosx + REFRESH_TIME_MS * oldVelz/1000; lcd.printf("X Vel: %2f\n",velx); lcd.printf(", "); lcd.printf("Y Vel:%2f\n",vely); lcd.printf(", "); lcd.printf("Z Vel: %2f\n",velz); oldVelx = velx; oldPosx = posx; oldVely = vely; oldPosy = posy; oldPosz = posz; oldVelz = velz; oldX = imu.ax; oldY = imu.ay; oldZ = imu.az; wait_ms(REFRESH_TIME_MS); } }
Be aware that there will be an accumulating error in the velocity calculations due to there always being force read by the IMU even when at rest.
Video Demo
Please log in to post comments.