Control Shooter RPM Based on Distance from Target

Hello CD,

Our team has been grilling me to figure out a way to control the RPM of the ball shooter we have built, which uses 2 REV NEOs controlled by 2 SPARK MAXes. The goal is to measure the distance from the target using our Limelight 2+ and calculate how many revolutions are required to launch the ball far enough to hit the target. We are participating in Infinite Recharge at Home, so we put tape on the floor corresponding to 10, 15, 20, and 25 feet away from the base of the target.

At some point I coded this, but it didn’t work
cd

It’s going to be very difficult for Distance to ever equal exactly 15 with floating point numbers.
Integers instead of floating point would be a better choice, or test for a range, e.g., 14.9 to 15.1 feet.

2 Likes

Yeah sorry. Forgot to change that equal operator to an In Range where it can be anything in between, I’ll fix that now

This

Make it a tolerance. What you could do is
abs (Distance - (15 feet)) < threshold (maybe 1 feet)

Alternatively, you could find an equation that relates motor speed to distance so you don’t have to do a lookup table

Or perhaps, after some data collection, you can do a line fit and then you can derive a continuous function:

rpms = distanceToRPMS(distance)

so if you happen to stop 15.11 feet away you can still make a decent shot.

2 Likes

@Mark_McLeod

Also, if you go to the other post I made after I made this one, this actually needs to be fixed before this code can work

What you might want to also consider doing is setting one motor to follow the other. You can set it to inverse follow.

Unless you set them at different speeds sometimes

1 Like

The plan is to keep the bottom RPM the same and adjust the top according to the distance, and I had previously had what you were saying set up, but I had to remove it

1 Like

If you do some testing at different distances you can use some type of interpolation to get the desired RPM = F ( Distance from target ). This VI uses a polynomial fit, but there are others. You could even create your own subVI to do linear interpolation between your testing points. In control system terminology, this is known as a “function generator”.

image

You would need to replace the controls and indicators with the appropriate inputs from the distance sensor and output to your motor controllers.

3 Likes

Labview has so many cool tools. If only it wasn’t extremely slow to deploy and work with

1 Like

This an excellent code block and visualization.

1 Like

Note the inclusion of a time delay (wait) in this sample. This doesn’t exist, but probably should, in the original post picture.

1 Like

Thank you, I will definitely try this tomorrow at the meeting.