Tutorial VII: IMU Data Reading Demo

From Waveshare Wiki
Jump to: navigation, search

Modules Usage Tutorial

IMU Data Reading

The General Driver for Robots has a 9-axis IMU on board, which can read the position data of the driver board itself. The IMU data reading demo is provided below.

Demo

Upload Demo

After downloading the zip package, open 9DOF_Demo.ino, connect the multifunctional driver board to the computer with a USB cable (here, the Type-C port of the USB of the multifunctional driver board is plugged in), click on "Tools" -> "Ports", and then click on the new COM (COM26 in my case). Click on the newly appeared COM port.
UGV1 doenload03EN.png
In Arduino IDE, click "Tools" → "Development Board" → "ESP32" → "ESP32 Dev Module". Upload the demo after selecting the board and the port. After uploading the demo, open the serial monitor of Arduino IDE to read the IMU data, and the data will change when you rotate the driver board.
UGV01 tutorial II01.png UGV01 tutorial V02.png

Demo Analysis

#include"IMU.h"

//Set the values for the Roll, Pitch, and Yaw corners, as well as the Temp temperature.
//Roll represents the roll angle of rotation around the X-axis, Pitch represents the pitch angle of rotation around the Y-axis, and Yaw represents the yaw angle of rotation around the Z-axis.
int   IMU_Roll = 100;
int   IMU_Pitch = 100;
int   IMU_Yaw = 100;
int   IMU_Temp = 100;

IMU_ST_ANGLES_DATA stAngles;    //Create structure variable stAngles to store the three angle data
IMU_ST_SENSOR_DATA stGyroRawData;    //For storing raw gyroscope data
IMU_ST_SENSOR_DATA stAccelRawData;    //Stores raw accelerometer data
IMU_ST_SENSOR_DATA stMagnRawData;    //Storing magnetometer raw data

void getIMU(){
  //Obtain IMU data
  imuDataGet( &stAngles, &stGyroRawData, &stAccelRawData, &stMagnRawData);
  IMU_Temp = QMI8658_readTemp();
  IMU_Roll  = stAngles.fRoll;
  IMU_Pitch = stAngles.fPitch;
  IMU_Yaw   = stAngles.fYaw;
}

void DOF(){
  Serial.print("R:");
  Serial.println(IMU_Roll);
  Serial.print("P:");
  Serial.println(IMU_Pitch);
  Serial.print("Y:");
  Serial.println(IMU_Yaw);
  Serial.print("T:");
  Serial.println(IMU_Temp);

}

void setup() {

  Serial.begin(115200);    //Initializing Serial Communications
  while(!Serial){}    //Waiting for serial port connection
  imuInit();    //Initialize IMU
} 


void loop() {
  getIMU();    //Obtain IMU data 
  DOF();    //Output IMU data 
  delay(1000);
}

Resource