# Autonomous rotate in place control algorithm

Hello everyone.
My team is looking for better ways to implement a control algorithm to make the robot to rotate to a given setpoint (to a given degree) as quickly as possible and give a valid indication that it is stable on the desired angle to signal the drivetrain to move forward.
One example that we are very curious about is the 2056’s autonomous sequence from 2018, which made the robot rotate very quickly and precisely (as it looks in the video):

I’m also curious to hear about your solutions to this problem.

PID off a gyro angle is the go-to. Don’t need anything more complicated than that.

7 Likes

At a higher level, you’ll probably want something to perform “sequencing” of the different steps. The command-based architecture has these concepts built in.

The past few years, we rolled our own timeline/event-sequencer thingy that lets us create “events” - just a class with init/update methods, as well as a “isFinished” method. We create lots of different events (ex: drive forward 5 feet, rotate 30 degrees left, raise elevator, etc.). We register each event with the sequencer class. The sequencer class then just runs each event one by one, starting with the first init then calling update repeatedly until the event reports that it is done. After that, it moves on to the next event init, then update… until there’s no more events.

Really, this is just a specialized form of a Finite state machine.

PID is probably the way to go, but this P with an exponent of 2.4 and a minimum and maximum speed works for us. I can’t say this is better than PID. PID is probably the way to go and I’ll probably try to see how well PID works for us during the 2020 season.

I stop the action/command when it’s less than 3 degrees to the target.

You also have to be careful when you’re dealing with continuous angles. (You don’t want something to try to rotate counter clockwise to go from -90 to 180 (270 degrees). You would instead want to rotate -90 to -180 (-90 degrees).
This helps with that.

Depending on how aggressively you’re turning, you may want to have some form of a “debunce” on the condition for being complete on the turn. IE, have actual angle be within the disired angle +/- 3 degress for half a second… or something like that.

For a low-friction drivetrain that spins in circles easily, the 2.4 power will definitely help reel in the control effort as your error gets closer to zero. If your drivetrain gets stuck while rotating easily (pneumatic wheels, too small of a center drop, etc). you’ll likely make the control effort too small as you get close to zero. Just depends.

What online(?) function plotting tool is that? It looks really handy.

Yeah we have a minimum turn amount of .15 so if it does get to close to zero, it will still turn some amount of it hasn’t reached the 3 degrees threshold.

Also, we use swerve drive. So different drivetrains will work better with different values probably.

Yup, Desmos graphic calculator. Apparently it’s all the rage with the younguns these days. Back in the day all I had was a TI-84…

Bingo. Definitely a key fact to keep in mind. WCD will have different dynamics.

2 Likes

To build on this, you could also try waiting to finish a PID turn command until the velocity lowers past a threshold, rather than just position, to avoid overshooting.
(e.g. gyro is within +/- 3 degrees AND is turning less than +/- 3 degrees per second)

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