Tutorial V: IMU Data Reading Demo

From Waveshare Wiki
Revision as of 01:47, 5 September 2023 by Eng52 (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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"

int   IMU_Roll = 100;
int   IMU_Pitch = 100;
int   IMU_Yaw = 100;
int   IMU_Temp = 100;

IMU_ST_ANGLES_DATA stAngles;
IMU_ST_SENSOR_DATA stGyroRawData;
IMU_ST_SENSOR_DATA stAccelRawData;
IMU_ST_SENSOR_DATA stMagnRawData;

void getIMU(){
  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);
  while(!Serial){}
  imuInit();
} 


void loop() {
  getIMU();
  DOF();
  delay(1000);
}

Resource