Velocity PID shooter based on Limelight distance from target

Hello, our team has a robot that has a limelight installed, as well as a Falcon 500 hooked up to a flywheel. We were looking into using PID to control the velocity of the motor based on the distance from the target. Any tips on where to get started would be appreciated!

2 Likes

Can you get the distance using the limelight?

2 Likes

Yes

1 Like

We create a table of hood angles and shooter rpm with a distance number tied to it. Where we see the limelight distance says for example 3, and we know that at 3 we need to set x angle and y rpm. we plot a bunch of these points and linearly interpolate between the points. If you find that the rpm and the distance relation is pretty linear you could just make an equation. Plug in distance get an rpm setpoint. From there you can use some controller to control the rpm of the shooter.

3 Likes

We put out the motor speed and Ty to the smart dashboard. We made controller buttons to increase or decrease the speed of the motor. Then from each distance (limelight ty angle) we recorded a speed that worked best. We then created a table of those angles and speeds and interpolated between them for speed we need.

LinearInterpolator.java

Shooter Speed table in our constants class

Our TurnToTarget would interpolate based on the angle and set the desired velocity on the CargoShooter

5 Likes

Actually, your plan seems correct and your’e on the right path. Once you know how to calculate distance to the target, you need some function which converts it to angle/speed of shot. I know a lot of teams this year that place their robot in several distances from the target, measure the correct speed/angle of shot that works well for that distance, and then interpolate between these points and get the desired function. You could interpolate linearly between points, or do some kind of polynomial regression.
Last year, we had a 3rd degree polynomial interpolation, created with a lot of shots. In competitions, we tuned the offset of the function, in order to deal with damaged balls. This worked pretty well for us at all distances.

4 Likes

Ok, cool. We actually did this last year with LabVIEW using PolynomialInterpolate.vi. Wasn’t sure if there was an interpolation program built into WPILib. Guess I’ll have to create my own

2 Likes

You can just do an easy linear interpolation. The goal is very big, so slight variations will not affect it too much

1 Like

This is what we did this year too. Our house is currently fixed but our next event we plan to do both hood and rpm adjustment.

2 Likes

We have a two position hood. We just did some testing where we found a base rpm we liked at a distance then moved a given distance say 15 “. Changed rpms by say 125 rpms. Then moved back another 15 inches and checked our rpm increase. We were lucky and found it very linear. We then coded that linear equation to vary our rpms

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