Driving straight using gyro or encoders?

Right now my team is set up with just some plain ol’ wheels and just for testing i’m using the arcadeDrive method. I plan on expanding outside of that so we can focus on driving straight and smoothly drive with limelight.

Just curious, to drive straight would it be best to go with encoders or a gyro? I’ve seen both be used. Also what would be the best way to implement it?

Thanks.

Either work, but using a gyro is probably simpler to start with. Implement a proportional controller with gyro angle error as the feedback term.

Example:
Error = gyro angle - desired gyro angle
Left = wanted_speed + (error * kp)
Right = wanted_speed - (error * kp)

Start with kp at 0 and increase until your robot starts to oscillate while driving, then back it off until it doesn’t.

If you are using normalized units for your motors (-1 to 1) and degrees as the gyro unit, I’d start with something like 0.05 for kp. That way, at 10 degrees of error your motors will be commanded to go 5% slower and faster to turn, which is probably a good place to start. If your robot goes straight for a little bit then starts driving in wild circles, make kp negative.

9 Likes

Cool thanks :slight_smile:

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.