Robot spins in circles with inertial sensor

I have to exact same code as another team and their’s works fine, but for some reason my robot just spins in circles. I have the calibrate part also.

can you upload the code you currently have? its way easier to debug if we can see the code

3 Likes

It’s just this,
void rightTurn(int speed, int units){
Inertial20.resetRotation();
while(Inertial20.rotation(deg) < units){
setDrive(speed,-speed);
task::sleep(10);
}
setDrive(0,0);
}

Print out the values that the inertial sensor is reporting. You can do this with:

Brain.Screen.printf("%f", Intertial20.rotation(deg));
1 Like

It just says a bunch of 0’s

The function you sent looks ok.

If you go to the devices screen on the V5 brain and select the inertial sensor, what does it show? Can you calibrate it from there, and if you turn the robot, do the sensor readings respond?

1 Like

Yes the values change

What does this code display on the brain screen?

void rightTurn(int speed, int units){
Inertial20.resetRotation();
while(Inertial20.rotation(deg) < units){
setDrive(speed,-speed);
task::sleep(10);
Brain.Screen.clearScreen();
Brain.Screen.print("%f", Inertial20.rotation(deg));
}
setDrive(0,0);
}
3 Likes

I don’t have my robot right now, but I tried it without the clear screen part and it looked something like this
0.000000000.000000000000.000000000000.000

Check the inertial sensor is working in the V5 brain dashboard. Check that you have it configured for the correct port.

3 Likes

When I move it, the values change

I just checked and the inertial sensor seems to be working fine.

If it malfunctions again, you can also use an inertial heading instead of rotation. I forget the exact difference, but I do remember heading being easier to debug.

I actually tried heading earlier and it stop, but it was turning weird amounts. I would reset heading and then 10 would turn more than 200 on a right turn.

It works with positives and negatives, so try a negative of that degree (ex: 6 to -6)

For printing on the brain, you have to reset the cursor everytime or it goes too far to the right. Add in a Brain.Screen.setCursor(1,1); right after the clear. Also, use heading, because rotation can go over 360 degrees.

The numbers fluctuate a lot and increase by about 2 per rotation.

Bumping this thread because we have a bot doing the exact same thing. Here is the code we are using. Robot will drive forward and then just spin forever.

void pre_auton() {
Inertial.calibrate();
Brain.Screen.print(“Calibrating Inertial for Drivetrain”);
while (Inertial.isCalibrating()) {
wait(250, msec);
}
Brain.Screen.clearScreen();
}

void autonomous() {
Drivetrain.driveFor(12, inches, true);
Drivetrain.turnToRotation(-90, deg, 50, pct, true);
}

void usercontrol() {
while (true) {
wait(20, msec);
}
}

int main() {
Competition.autonomous(autonomous);
Competition.drivercontrol(usercontrol);
pre_auton();
while (true) {
wait(100, msec);
}
}

I have swapped sensors with other working sensors, so I am confident that it is not the sensor. Also, we have verified on the brain that the sensor is working. Any ideas on what might be goin on here?

In the future, if you have a problem, could you create a new topic instead of replying to a year old one? also, please format your code, so other people can read it. to do this:

[code]

copy-paste your code here

[/code]

Make sure the 1st and last lines only have one word and the brackets, nothing more.

formated code
void pre_auton() {
Inertial.calibrate();
Brain.Screen.print(“Calibrating Inertial for Drivetrain”);
while (Inertial.isCalibrating()) {
wait(250, msec);
}
Brain.Screen.clearScreen();
}

void autonomous() {
Drivetrain.driveFor(12, inches, true);
Drivetrain.turnToRotation(-90, deg, 50, pct, true);
}

void usercontrol() {
while (true) {
wait(20, msec);
}
}

int main() {
Competition.autonomous(autonomous);
Competition.drivercontrol(usercontrol);
pre_auton();
while (true) {
wait(100, msec);
}
}

are you using the built-in drivetrain, or is this your own custom code? When you go into the devices menu, what does it report? When you print the output to the screen, what is shown?