-
Notifications
You must be signed in to change notification settings - Fork 0
Auto ranging #338
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
Open
Glowdisk
wants to merge
17
commits into
main
Choose a base branch
from
auto-ranging
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Auto ranging #338
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d694637
Adding in polartaingTreeMap
Glowdisk 719c294
Unit tests added
Glowdisk 6ded9fa
Merge branch 'main' into auto-ranging
Glowdisk 1c1f9dd
Comment changes
Glowdisk ab9c1cf
Merge branch 'main' into auto-ranging
Glowdisk d3e4748
file name change
Glowdisk f8bbe5b
Merge branch 'main' into auto-ranging
Glowdisk ebf0f33
Re-added TrajectoryCalc in BaseRobotCompponent
Glowdisk 2fbe640
Merge branch 'main' into auto-ranging
Glowdisk 4f30de1
Extra spacing removed
Glowdisk bbd01c5
Merge branch 'main' into auto-ranging
Glowdisk e896fcb
Brining back interpolatingTreeMap stuff
Glowdisk 9b95024
Restore InterpolatingTreeMap
Glowdisk 1b499fc
Merge branch 'main' into auto-ranging
Glowdisk 7aed2e0
Less hardcoding, and small test change
Glowdisk b04dd41
Merge branch 'main' into auto-ranging
Glowdisk 20ab66f
readded some commands from main
Glowdisk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/test/java/competition/subsystems/shooter/TrajectoriesCalculationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| package competition.subsystems.shooter; | ||
|
|
||
| import competition.BaseCompetitionTest; | ||
| import competition.subsystems.pose.Landmarks; | ||
| import competition.subsystems.pose.TrajectoriesCalculation; | ||
| import edu.wpi.first.apriltag.AprilTagFieldLayout; | ||
| import edu.wpi.first.apriltag.AprilTagFields; | ||
| import edu.wpi.first.math.geometry.Pose2d; | ||
| import edu.wpi.first.math.geometry.Rotation2d; | ||
| import edu.wpi.first.units.Units; | ||
| import edu.wpi.first.wpilibj.DriverStation; | ||
| import org.junit.Test; | ||
| import xbot.common.subsystems.pose.GameField; | ||
|
|
||
| import java.util.Random; | ||
|
|
||
| import static org.junit.Assert.assertNotNull; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| public class TrajectoriesCalculationTest extends BaseCompetitionTest { | ||
|
|
||
| public Pose2d hub = Landmarks.getAllianceHubPose( | ||
| AprilTagFieldLayout.loadField(AprilTagFields.k2026RebuiltWelded), DriverStation.Alliance.Blue); | ||
|
|
||
| private TrajectoriesCalculation.ShootingData getData( | ||
| TrajectoriesCalculation calc, | ||
| Pose2d pose, | ||
| boolean zeroHood) { | ||
|
|
||
| return calc.calculateAllianceHubShootingData(pose, zeroHood); | ||
| } | ||
|
|
||
| @Test | ||
| public void testZeroHoodVsNormal() { | ||
| TrajectoriesCalculation calc = getInjectorComponent().trajectoriesCalculation(); | ||
|
|
||
|
|
||
| Pose2d robotPose = new Pose2d(4.0, 2.0, new Rotation2d()); | ||
|
|
||
| var normal = calc.calculateAllianceHubShootingData(robotPose, false); | ||
| var zeroHood = calc.calculateAllianceHubShootingData(robotPose, true); | ||
|
|
||
| // Both should return valid data | ||
| assertNotNull(normal); | ||
| assertNotNull(zeroHood); | ||
|
|
||
| // RPM should exist in both | ||
| assertTrue(normal.shooterRPM().in(Units.RPM) > 0); | ||
| assertTrue(zeroHood.shooterRPM().in(Units.RPM) > 0); | ||
|
|
||
| assertTrue("Zero hood servo should be <= normal servo", | ||
| zeroHood.servoRatio() <= normal.servoRatio()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testInterpolationBetweenTwoPoints() { | ||
| TrajectoriesCalculation calc = getInjectorComponent().trajectoriesCalculation(); | ||
|
|
||
| Pose2d closePose = new Pose2d(hub.getX() + 3.8, hub.getY(), new Rotation2d()); | ||
| Pose2d midPose = new Pose2d(hub.getX() + 4.9, hub.getY(), new Rotation2d()); | ||
| Pose2d farPose = new Pose2d(hub.getX() + 6.0, hub.getY(), new Rotation2d()); | ||
|
|
||
| for (boolean zeroHood : new boolean[]{false, true}) { | ||
|
|
||
| var closeShot = getData(calc, closePose, zeroHood); | ||
| var midShot = getData(calc, midPose, zeroHood); | ||
| var farShot = getData(calc, farPose, zeroHood); | ||
|
|
||
| assertNotNull(closeShot); | ||
| assertNotNull(midShot); | ||
| assertNotNull(farShot); | ||
|
|
||
| if (!zeroHood) { | ||
| // Normal mode → servo should interpolate | ||
| assertTrue(midShot.servoRatio() > closeShot.servoRatio()); | ||
| assertTrue(midShot.servoRatio() < farShot.servoRatio()); | ||
| } else { | ||
| // Zero hood → servo should NOT change (likely 0) | ||
| assertTrue(Math.abs(midShot.servoRatio() - closeShot.servoRatio()) < 0.001); | ||
| assertTrue(Math.abs(midShot.servoRatio() - farShot.servoRatio()) < 0.001); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testTenRandomPointsInAllianceZone() { | ||
| TrajectoriesCalculation calc = getInjectorComponent().trajectoriesCalculation(); | ||
|
|
||
| long seed = System.currentTimeMillis(); | ||
| Random rand = new Random(seed); | ||
|
|
||
| System.out.println("Seed: " + seed); | ||
|
|
||
| for (boolean zeroHood : new boolean[]{false, true}) { | ||
| GameField gameField = getInjectorComponent().gameField(); | ||
| for (int i = 0; i < 10; i++) { | ||
| double randomWidth = rand.nextDouble() * gameField.getFieldWidth().in(Units.Meters); // 4.03 is the width of the alliance zone | ||
| double randomLength = rand.nextDouble() * gameField.getFieldLength().in(Units.Meters); // 8.07 is the height of the alliance zone | ||
|
|
||
| Pose2d randomPose = new Pose2d(randomWidth, randomLength, new Rotation2d(0)); // Random spot in alliance zone | ||
|
|
||
| TrajectoriesCalculation.ShootingData data = calc.calculateAllianceHubShootingData(randomPose,zeroHood); | ||
|
|
||
| assertNotNull(data); | ||
|
|
||
| // Servo ratio should be between 0 (No hood) and 1.0 (Max hood) | ||
| if (data.servoRatio() > 0) { | ||
| assertTrue("Servo should be between 0.0 and 1.0", | ||
| data.servoRatio() <= 1.0); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⭐ What's the reason of this check? Could you write a comment to explain why if servoRatio > 0 then it must be in the range [0.2, 1.0]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considered a lower bound for safety but now I think about it, I dont think i need it. The 1.0 is the maximum ratio, so it should never be over. Changing the bounds to 0.0 to 1.0