V5 internal sensor Code

Where can I find sample code for the new V5 internal sensor?

It’s an “inertial” sensor (not internal)
There’s a example with VEXcode, but the simplest use is to replace a gyro, in which case you would use Inertial.heading( degrees ); or Inertial.rotation( degrees ); to get the amount of rotation around the Z axis.

I’ll post something more complicated next week.


Here’s something a little more comprehensive that would print more information

imu example
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       james                                                     */
/*    Created:      Fri Nov 01 2019                                           */
/*    Description:  V5 project                                                */
/*                                                                            */
#include "vex.h"

using namespace vex;

// This would need moving to robot-config.cpp if using graphical configuration
// A global instance of vex::brain used for printing to the V5 brain screen
vex::brain       Brain;

// define your global instances of motors and other devices here
vex::inertial    Inertial( vex::PORT2 );
vex::limit       sw1( Brain.ThreeWirePort.A );


void InertialStartCal() {

int main() {
    inertial::quaternion  Inertial_quaternion;


    while(1) {
        // get the quaternion data
        Inertial_quaternion = Inertial.orientation();


        Brain.Screen.setFont( mono15 );
        Brain.Screen.setPenColor( white );
        Brain.Screen.setFillColor( black );
        Brain.Screen.printAt( 20,  30, "GX  %8.3f", Inertial.gyroRate( xaxis, dps ) );
        Brain.Screen.printAt( 20,  45, "GY  %8.3f", Inertial.gyroRate( yaxis, dps ) );
        Brain.Screen.printAt( 20,  60, "GZ  %8.3f", Inertial.gyroRate( zaxis, dps ) );

        Brain.Screen.printAt( 20,  90, "AX  %8.3f", Inertial.acceleration( xaxis ) );
        Brain.Screen.printAt( 20, 105, "AY  %8.3f", Inertial.acceleration( yaxis ) );
        Brain.Screen.printAt( 20, 120, "AZ  %8.3f", Inertial.acceleration( zaxis ) );

        Brain.Screen.printAt( 20, 150, "A   %8.3f", Inertial_quaternion.a );
        Brain.Screen.printAt( 20, 165, "B   %8.3f", Inertial_quaternion.b );
        Brain.Screen.printAt( 20, 180, "C   %8.3f", Inertial_quaternion.c );
        Brain.Screen.printAt( 20, 195, "D   %8.3f", Inertial_quaternion.d );

        Brain.Screen.printAt( 150, 30, "Roll     %7.2f", Inertial.roll() );
        Brain.Screen.printAt( 150, 45, "Pitch    %7.2f", Inertial.pitch() );
        Brain.Screen.printAt( 150, 60, "Yaw      %7.2f", Inertial.yaw() );

        Brain.Screen.printAt( 150, 90, "Heading  %7.2f", Inertial.heading() );
        Brain.Screen.printAt( 150,105, "Rotation %7.2f", Inertial.rotation() );

        if( Inertial.isCalibrating() )
          Brain.Screen.printAt( 20,225, "Calibration  In Progress" );
          Brain.Screen.printAt( 20,225, "Calibration  Done" );


        // Allow other tasks to run

Question: my team wanted to incorporate the intertial sensor this weekend but when looking at the drivetrains in version 1.0.1 only got an option for a 3-wire gyro. They were at a tournament and didn’t want to update the code to the latest version at the time. In the latest version, 1.0.2, are there options for the new inertial sensor?


Would love to see more details before the holiday break so students that want to master this during the break have something to work with. As always, your assistance and input is much appreciated!

1 Like


The “advanced API” has some more details on the command available.


I just found some code in the Examples in the latest VexCode update.
“inertial” sensor makes more sense than what I typed.

Question about the api. What are acceptable VelocityUnits (for example, other units are degrees, seconds, etc) - what can be used for velocityUnits ? And, besides asking here, how can I figure out other units and what can be used in the future.

1 Like


pct, percent
rpm, rounder per minute
dps, degrees per second


This is the example code given.

#include “vex.h”

using namespace vex;

int main() {


while (Inertial20.isCalibrating()) {
wait(100, msec);


waitUntil((Inertial20.rotation(degrees) >= 90.0));
wait(1, seconds);


I loaded the example Accurate Turns(Inertial Sensor) with VexCode 1.0.3 19.121916 into a B1(VEXos 1…0.7) and get thevJump Table Error 03800EE8. I tried a second B1 and second sensor and got the same Error. I tried the sensor code lines in another program and got another Jump Code Error 038019F8.
I must be missing something simple.

vexos 1.0.7 is not compatible with the Inertial sensor, update to 1.0.9, VEXcode should have prompted you to do that, click on the green brain icon when the V5 is connected via USB.


Thank you. It works. I appreciate your quick response, especially on a holiday.

1 Like

when I copy and past the config code ( vex::inertial Inertial( vex::PORT2 ); ) it gives me the error:

[clang] No type named ‘inertial’ in namespace ‘vex’

I’m running the most updated version of vexcode, what can I do to fix this?

Which version is that ? you need the 1.0.3 version released in December.

1 Like

1.0.3 is working for me on PC but not on Mac

you could check the sdk version, but inertial sensor is working on both Mac and PC in 1.0.3
Anything unusual about the installation ? perhaps reinstall, I don’t know.


1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.