I'm using inertial sensor in the drivetrain in my code but i want to use inertial specifically

As i mentioned in the title, how can i do this in my code, i’m using vexcode pro v5.

When you configure stuff in the config window, VEX generates code to actually configure it in the code, and (I think) hides it at the top and says don’t touch it. If you copy and paste all the stuff that’s automatically generated, I could probably help you. (Put ``` on the lines before and after your code so it formats properly.)

This is what it looks like in IQ.
#pragma region VEXcode Generated Robot Configuration
// Make sure all required headers are included.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>

#include "vex.h"

using namespace vex;

// Brain should be defined by default
brain Brain;

#define waitUntil(condition)                                                   \
  do {                                                                         \
    wait(5, msec);                                                             \
  } while (!(condition))

#define repeat(iterations)                                                     \
  for (int iterator = 0; iterator < iterations; iterator++)

// Robot configuration code.
motor LeftDriveSmart = motor(PORT1, 1.5, false);
motor RightDriveSmart = motor(PORT6, 1.5, true);
drivetrain Drivetrain = drivetrain(LeftDriveSmart, RightDriveSmart, 200, 203.2, 152.39999999999998, mm, 1);
motor combineMotorA = motor(PORT12, true);
motor combineMotorB = motor(PORT11, false);
motor_group combine = motor_group(combineMotorA, combineMotorB);

colorsensor resetter = colorsensor(PORT9);
motor catapultMotorA = motor(PORT5, true);
motor catapultMotorB = motor(PORT10, false);
motor_group catapult = motor_group(catapultMotorA, catapultMotorB);

touchled touch = touchled(PORT2);
gyro GYro = gyro(PORT7);

#pragma endregion VEXcode Generated Robot Configuration

It’s also usually hidden with a little + button next to the first line, like this:
If you copy and paste all that hidden code, with ``` before and after, I might be able to help you.

Otherwise, when you add the inertial to your drivetrain config, do inertial sensor commands get added to your command menu? In IQ, we can drag the commands from the menu and it will automatically fill the name part with the name of our real sensor, i.e. when we drag Gyro.heading() from the menu, it will appear where we drop it as Gyro7.heading() or whatever our gyro is named. If you drag an inertial command from your command menu, maybe it will fill Drivetrain.Inertial or something.

1 Like

robot configuration

And Drivetrain.Inertial doesn’t work :frowning:


You can bring it into your main.cpp with the extern command.

#include "vex.h"
using namespace vex;

// A global instance of competition
competition Competition;

// Use extern to  reference the sensor from the robot-config.cpp
extern inertial DrivetrainInertial;  

void pre_auton(void) {

double robotHeading;
void autonomous(void) {
  //Then use the reference in your code.
  robotHeading = DrivetrainInertial.heading();