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

2 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.

2 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.