Inertial Help

I am using VexCode V5 text 1.0.3. Our robot is using an inertial sensor. It is programmed to turn 90 degrees to the left. It is turning, but too far. Looking for some advice.

//The robot turns to face the goal.
FL.spin(directionType::rev, 20,velocityUnits::pct);
BL.spin(directionType::rev, 20,velocityUnits::pct);
FR.spin(directionType::fwd, 20,velocityUnits::pct);
BR.spin(directionType::fwd, 20,velocityUnits::pct);
waitUntil((Inertial6.rotation(degrees) <= -90.0));
task::sleep(5);
FL.stop(brakeType::brake);
BL.stop(brakeType::brake);
FR.stop(brakeType::brake);
BR.stop(brakeType::brake);

This is expected behavior to some extent, since the motors take some distance to stop, and take longer to stop the faster they’re spinning. So, if you go from full speed to 0% speed when the robot has turned the target distance, the motors with “coast” quite a bit, and the robot will overshoot its target.

Some things you can try to mitigate this:

  • Turn slower, so the robot “coasts” for a shorter distance
  • Setting the motors’ brake type to “stop” or “hold”, which will help to reduce the stopping distance.
  • Initializing a drivetrain object and using its turnFor function
  • Implementing your own PID (search the forum for lots of info about how to do this)
4 Likes

Thanks for the input, but we did try most of this. It only turns at 20%, we are using brake, not coast, and had the same problem with the drivetrain. It is not slight overshooting either, it is about 45 degrees too far. We did not try a PID though. We will look into that. Thanks.

You are sleeping for 5 sec after the desired turn, with the motors still running.

4 Likes

There is also a hold braking function that @holbrook suggested using. The stopping code would look something like this instead.

FL.stop(brakeType::hold);
BL.stop(brakeType::hold));
FR.stop(brakeType::hold));
BR.stop(brakeType::hold));
3 Likes

Another option is to have multiple segments. You turn at higher speed first but only 90% of the way, then turn remaining 10% at the lower speed.

If that doesn’t work you could start exploring using drivetrains

2 Likes