Sections:
The inertial sensor is a combined 3 axis Gyro and a 3 axis Accelerometer. The three axis are x,y,z and are perpendicular to each other. Rotations about these axes are measured by the gyro. The accelerometer measures the acceleration in each of these directions. To understand the 3 axis measurement of the gyro we need to understand the possible rotations of the robot. We will use the standard aerospace terms to name the different rotations, Pitch, Roll and Yaw.
A visual representation of rotations. This is from the Nasa Glenn Research Center beginners guide to aeronautics. You can find a bunch more information by clicking through to their site.
In this section we will take a look at what data we can get from the sensor and print it to the screen.
First be sure you have the most up to date version of vexCode V5 Text. I am using version 1.0.3
Using the configuration wizard select add device / Inertial. Select the port in which it is connected. You can change the name if you like but I found it best to keep the default name which is the type of sensor and the port number, in my case Inertial20.
When complete the Robot Configuration should look like this.
By doing this we have created an object of class Inertial and named it Inertial20, now all of the methods associated with this class will be available in the command help window.
void readIMU()
{
double heading20 = 0; //These are all the variables the inertial sensor can measure
double pitch20 = 0;
double roll20 = 0;
double yaw20 = 0;
double rotation20 = 0;
double ax = 0;
double ay = 0;
double az = 0;
heading20 = Inertial20.heading(degrees);
pitch20 = Inertial20.orientation(pitch, degrees);
roll20 = Inertial20.orientation(roll, degrees);
yaw20 = Inertial20.orientation(yaw, degrees);
rotation20 = Inertial20.rotation(degrees);
ax = Inertial20.acceleration(xaxis);
ay = Inertial20.acceleration(yaxis);
az = Inertial20.acceleration(zaxis);
Brain.Screen.clearScreen();
Brain.Screen.printAt(1, 40, "IMU values");
Brain.Screen.printAt(1, 40, "Heading = %.2f Degrees ", heading20);
Brain.Screen.printAt(1, 60, "Pitch = %.2f Degrees ", pitch20);
Brain.Screen.printAt(1, 80, "Roll= %.2f Degrees ", roll20);
Brain.Screen.printAt(1, 100, "Yaw = %.2f Degrees ", yaw20);
Brain.Screen.printAt(1, 120, "rotation = %.2f Degrees ", rotation20);
Brain.Screen.printAt(1, 140, "X accel = %.2f ", ax);
Brain.Screen.printAt(1, 160, "Y accel = %.2f ", ay);
Brain.Screen.printAt(1, 180, "Z accel = %.2f ", az);
wait(20,msec);
}
int main() { // Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
while(Inertial20.isCalibrating()){ // Wait for Gyro Calibration , Sleep but Allow other tasks to run
this_thread::sleep_for(20);
}
while (true){
readIMU();
// Sleep but Allow other tasks to run
this_thread::sleep_for(50);
}
}