Inertial sensor doesn't work properly

void turnL(int vel,int deg){
Drivetrain.setTurnVelocity(vel,percent);
Drivetrain.turnToRotation(-deg,degrees);
}
void turnR(int vel,int deg){
Drivetrain.setTurnVelocity(vel,percent);
Drivetrain.turnToRotation(deg,degrees);
}

int main() {
turnR(100,90);
vexcodeInit();
}

Here is my code, is there any suggestions about the code, my inertial sensor doesn’t work properly.

And that’s the location of the inertial sensor

You can use the diagnostics to see if the sensor is working as expected:

https://kb.vex.com/hc/en-us/articles/360037382272-Using-the-V5-Inertial-Sensor#PlacementoftheInertialSensor-e6k2X

3 Likes

Actually we don’t have any problem with placement or something

You’ll probably want vexcodeInit(); to run before you try to turn. That’s likely where the inertial sensor is calibrated.

3 Likes

I did the calibration stuff in the beggining of my code with this :
DrivetrainInertial.calibrate();
while(DrivetrainInertial.isCalibrating() )
{ wait(10,msec); }
should i delete and put vexcodeInit() the beggining of my code?

I was more referring to Reading Inertial Sensor Values and going into the Devices tab to see if the numbers reflect the movement of the robot. Can you turn your robot 90 degrees and the sensor shows 90?
image

3 Likes

Without seeing all your code, its hard to provide guidance

Yes, it shows 90 degrees but during my skills autonomous, i called 90 degrees after some codes but it turns 100 degrees or 80 degrees and it changes everytime.

I would slow down the velocity to test if you gain accuracy. I am curious if the maneuver is timing out - does the robot move on to the next instruction before the Drivetrain can self correct. Have you specified the Timeout?

    Drivetrain.setTimeout(5, timeUnits::sec);

// Other frequently used methods
    Drivetrain.setDriveVelocity(50, velocityUnits::pct);
    Drivetrain.setTurnVelocity(50, velocityUnits::pct);
    Drivetrain.setStopping(brakeType::brake);  //coast, hold
4 Likes