Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shooter distances #13

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

shooter distances #13

wants to merge 11 commits into from

Conversation

ev118
Copy link
Contributor

@ev118 ev118 commented Mar 23, 2022

No description provided.

@ev118 ev118 requested a review from PepperLola March 23, 2022 23:10
@PepperLola
Copy link
Member

I would actually make a class that stores a double distance and two int RPMs, and have a single ArrayList with all of them in it. You could define this in its own file or as a static class in the ShooterDistances class. We need to be able to enter and interpolate between arbitrary distances instead of each having a constant offset, because we'll probably only be able to enter like three or four, and they will likely be the set locations we've decided on.

In order to get the two distances it's between, you would want a fori loop over every element until you reach one where its distance is greater than the one Gloworm is calculating. You can store the element at that index and the one before it, and those are the two distances and sets of RPMs that you'll have to interpolate between.

You would figure out how far between the distances the robot is by dividing the robot distance minus the lower distance by the upper distance minus the lower distance. Then to interpolate between the sets of RPMs, you can take the one for the smaller distance and add it to the difference between the smaller and larger distance ones times that percent you calculated earlier.

However, WPILib provides the MathUtil.interpolate(double startValue, double endValue, double t) method that I would suggest you use instead, just to make it clearer to other people what it's doing and to make it faster to implement. I'm guessing you already knew how linear interpolation works, but I would rather explain too much than not enough.

Using an ArrayList for this helps as well, because it scales dynamically as you add elements to it, and you can declare one easily by saying

private final List<ShooterData> shooterData = List.of(new ShooterData(0, 0, 0), new ShooterData(0, 0, 0));

or

private final List<ShooterData> shooterData = Arrays.from(new ShooterData(0, 0, 0), new ShooterData(0, 0, 0));

assuming your class is called ShooterData and takes in the distance, top RPM, and bottom RPM.

Copy link
Member

@PepperLola PepperLola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to review changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants