Tutorial VII: IMU Data Reading Demo
Modules Usage Tutorial
- How To Install Arduino IDE
- Tutorial I: Motor With Encoder Control Demo
- Tutorial II: Motor With Encoder Control Demo 2
- Tutorial III: Motor With Encoder Control Demo 3
- Tutorial IV: Motor Without Encoder Control Demo
- Tutorial V: ST3215 Serial Bus Servo Control Demo
- Tutorial VI: PWM Servo Control Demo
- Tutorial VII: IMU Data Reading Demo
- Tutorial VIII: SD Card Reading Demo
- Tutorial IX: INA219 Voltage And Current Monitoring Demo
- Tutorial X: OLED Screen Control Demo
- Tutorial XI Lidar and Publishing Lidar Topics in ROS2
- General Driver for Robots WIKI Main Page
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.
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.
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); }