Hello. My team has asked me to see if it would be possible to create a command that can calculate trajectory with our shooter and make the best shot. We’re using a limelight as our camera and was wondering if this was possible and if I can use limelight to help,
Any help would be greatly appreciated
Short answer: yes it’s definitely possible
The question is how. For any kind of answer to that, we’d need to know more about your robot design. Best if you could share what you’ve already tried and how its not working for you
You can use the limelight to track your robot’s distance from the speaker to calculate a shooter angle/speed using an InterpolatingDoubleTreeMap. You just have to manually test a few setpoints first
We have an arm with two pivots one part run by a cim motor and one run by a neo. Both motors have throughbore encoders. The shooter is run by to side by side redlines geared 4:1. i have honestly not tried anything else as i did not really know where to start
If I missed anything you might need let me know
The quickest and often most accurate way to do this is empirically:
Measure shots taken by your robot at various angles and/or speeds [whichever you are controlling] and map them to your limelight range measurements.
This would work but we want to find the best shot angle from anywhere on the field
You can use this example code from Limelight itself to calculate distance and thus estimate the desired power
I wouldn’t recommend using Interpolation as @amb mentioned, unless you some good experience with Java and/or know what your doing…
That said, I’d recommend taking measurements for your robots shooter speeds (and anything else that changes to shoot a note) that will reliably score a know at known distances (5in, 10in, 100in, etc.)
With that data, put it on Desmos, look at what type of equation it is, whether its quadratic, linear, exponential, or something else.
With that, you can easily make an equation inside your code, provided you can calculate distance with your limelight.
For example:
double speed;
speed = 5; //y-intercept value, or speed @ 0 inches from sub
speed = speed + ((Limelight.getDistance()) * ShooterConstants.Slope); //add calculated speed to y-intercept, slope is change in speed per 1 unit of distance
There are many methods of doing a spline that are really easy. We use a PolynomialSplineFunction
from the Apache Commons Math library. It’s as simple as plugging in an array for your X values (in this case distance), and another array for your output (flywheel speed, angle or whatever).
Then it spits out a function that you can query. You can do m_function.value(targetDistance);
and it’ll give you the corresponding Y value. You’ll just want to make sure you only query values inside the range you defined initially.
Then Much like @Xactlysharp suggested - find the best angle and speed at a variety of ranges. Note that if you have your camera fairly high (not too far below the AprilTag), the height of the AprilTag image on the SPEAKER will relate inversely to the distance.
With that data, put it on Desmos, look at what type of equation it is, whether its quadratic, linear, exponential, or something else.
With that, you can easily make an equation inside your code, provided you can calculate distance with your limelight.
The point of using an InterpolatingTreeMap is so you can put in empirically gathered points and it interpolates them for you (thanks WPILib). This is far easier than generating a curve and is still used by teams like 1678 & 4414 because it makes changing values so easy at competitions if the field is off or for any other reason.
Out of curiosity, why are you using a polynomial? I thought the relationship between distance, velocity, and shooter angle was linear. Did you empirically determine that maybe one thing, like distance and velocity, was linear and distance and shooter angle were quadratic, or how exactly did you decide that a certain relationship wouldn’t follow linear interpolation?
It’s just more versatile. I haven’t had an issue with it even when the relationship happens to be linear. We use this universally in many places, including for joystick input maps, to customize the response curve for throttle and rotation for swerve driving.
The SplineInterpolator and PolynomialSplineFunction is capable of handling linear and non-linear relationships very well.
We use the Apache SplineInterpolator to produce our functions, which produces a set of cubic functions.
https://commons.apache.org/proper/commons-math/javadocs/api-3.6.1/org/apache/commons/math3/analysis/interpolation/SplineInterpolator.html
I see. Could you post some data and code snippets of your implantation with the interpolation that gets passed into the shooter angle and velocity based on distance?
Not sure what data you’re looking for. But you can take a look at our code, its public. The lookup table is in Constants.java
, and the logic for the shooter angle/velocity is in ShooterSubsystem.java
.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.