Switching between position PID (autonomous) and velocity PID (teleop)

First off, is speed control in teleop really useful? We’ve never used it, and we don’t have a testing platform at the moment, so I can’t hack an implementation to feel the difference.

Second, given that the answer to the previous question is “yes,” how would you implement them both? I know there’s been quite a bit of discussion about using velocity control with the Jaguars, but we’re hoping to use Talons this year, so all of our control loops would have to be in the robot code.

I’d say that speed control in teleop is definitely useful, but mainly for a low speed and high speed setting, or if you want to have a smooth Drivetrain power curve. That smooth curve allows the driver to more smoothly drive instead of accidentally putting too much force and causing the wheels to slip.

In implementation, I think it would be simple to calculate velocity using the encoders, and have that as your actual, and use the input power and gearbox calculations for your value you want on the drivetrain, with the error being the difference in the wanted value and the actual value.

With the amount of robot-to-robot, robot-to-gamepiece, and robot-to-field contact that occurs during teleop, any feedback system on the drive is going to see a LOT of disturbances. Disturbances can make your loops unstable, or have weird “what the heck just happened” consequences. We used velocity PID during teleop for Lunacy initially (to help with traction control), but ultimately removed that in favor of a simpler motor ramp up/down limit and the drivers liked the feel better.

If you want an acceleration limit, you can simply limit the rate of change of your speed commands.

For example:


[pseudocode]
maxChange = 0.05
speed = 0

while(robot is running)
    input = joystick.getY()
    if input > (speed + maxChange)
        speed = speed + maxChange
    else if input < (speed - maxChange)
        speed = speed - maxChange
    else
        speed = input
    end if
   
    motor.set(speed)
end while

…just want to second Jared’s comments…

We’ve used an implementation of his pseudocode on many of our 'bots for driving and other effector applications over the years.

Eric