I have a problem with my Inartial Sensor. Every time I make my robot turn in my autonomous code it just keeps spining.
void TurnRight (int velocity, double angle) {
Drivetrain.setHeading(0, degrees);
Drivetrain.setDriveVelocity(velocity, percent);
Drivetrain.turnToHeading(angle-2.5, degrees);
Brain.Screen.print(Drivetrain.heading(degrees));
}
void TurnLeft (int velocity, double angle) {
Drivetrain.setHeading(0, degrees);
Drivetrain.setDriveVelocity(velocity, percent);
Drivetrain.turnToHeading(360-angle+2, degrees);
Brain.Screen.print(Drivetrain.heading(degrees));
}
That’s often an indication that drivetrain motors are reversed. The code behind turnToHeading assumes the robot needs to turn right (clockwise) to increase the heading value (ie. 0->90 etc.), if the robot actually turns left it will be confused. so try something simple, Drivetrain.turnToHeading(90, degrees) and make sure the robot turns clockwise.
7 Likes
I am have the same issue however I am in vexcode V5 c++ and I have no idea what is going on I am using a drivtrain.turnfor(left,90,degrees); . After the preditermined code is set. Does anyone have a way that may fix it? I give it 2 seconds to calibrate in my pre auto/when started and set rotation and heading to zero. I have tryed setting a range and for some reason it just doesn’t turn and skips to the next line of code. It seems to only ever work when i set the velocity to 5 percent above 25 percent it spins. Below that it just goes back and forth. This is for heading and turnfor. Also sorry for not posting code couldn’t figure out how to on my phone.