-
Notifications
You must be signed in to change notification settings - Fork 0
Fix OTF aiming at field walls with velocity clamping #554
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -413,7 +413,7 @@ public AngularVelocity getHubAngularVelocity(Pose2d pose) { | |
|
|
||
| double robotTargetAngle = getTargetAngle(pose).in(Radians); | ||
|
|
||
| Translation2d fieldRelativeVelocity = new Translation2d(drivetrain.getCurrentRobotChassisSpeeds().vxMetersPerSecond, drivetrain.getCurrentRobotChassisSpeeds().vyMetersPerSecond).rotateBy(drivetrain.getPose().getRotation()); | ||
| Translation2d fieldRelativeVelocity = new Translation2d(drivetrain.getWallCorrectedChassisSpeeds().vxMetersPerSecond, drivetrain.getWallCorrectedChassisSpeeds().vyMetersPerSecond).rotateBy(drivetrain.getPose().getRotation()); | ||
|
|
||
| double hubRotation = (-fieldRelativeVelocity.getX() * Math.sin(robotTargetAngle) + fieldRelativeVelocity.getY() * Math.cos(robotTargetAngle)) / getTargetDistance().in(Meters); | ||
|
Comment on lines
414
to
418
|
||
| return RadiansPerSecond.of(hubRotation); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -430,8 +430,39 @@ public ChassisSpeeds getCurrentRobotChassisSpeeds(){ | |
| return getState().Speeds; | ||
| } | ||
|
|
||
| public Pose2d getFuturePoseFromTime(Time time) { | ||
| // When the robot is pressed against a field wall, wheels spin but the robot | ||
| // doesn't actually move into the wall. This zeros the velocity component | ||
| // pointing off-field so the OTF solver doesn't lead shots based on phantom motion. | ||
| private static final double WALL_MARGIN = 0.20; // meters (~8 in, bumper width + tolerance) | ||
|
|
||
|
Comment on lines
+433
to
+437
|
||
| public ChassisSpeeds getWallCorrectedChassisSpeeds() { | ||
| ChassisSpeeds speeds = getCurrentRobotChassisSpeeds(); | ||
| Pose2d pose = getPose(); | ||
|
|
||
| double sin = pose.getRotation().getSin(); | ||
| double cos = pose.getRotation().getCos(); | ||
|
|
||
| // Robot-relative to field-relative | ||
| double fieldVx = speeds.vxMetersPerSecond * cos - speeds.vyMetersPerSecond * sin; | ||
| double fieldVy = speeds.vxMetersPerSecond * sin + speeds.vyMetersPerSecond * cos; | ||
|
|
||
| Translation2d pos = pose.getTranslation(); | ||
|
|
||
| // Clamp velocity component pointing out of the field near each wall | ||
| if (pos.getX() < WALL_MARGIN && fieldVx < 0) fieldVx = 0; | ||
| if (pos.getX() > FieldConstants.FIELD_LENGTH - WALL_MARGIN && fieldVx > 0) fieldVx = 0; | ||
| if (pos.getY() < WALL_MARGIN && fieldVy < 0) fieldVy = 0; | ||
| if (pos.getY() > FieldConstants.FIELD_WIDTH - WALL_MARGIN && fieldVy > 0) fieldVy = 0; | ||
|
|
||
| // Field-relative back to robot-relative | ||
| double rrVx = fieldVx * cos + fieldVy * sin; | ||
| double rrVy = -fieldVx * sin + fieldVy * cos; | ||
|
|
||
| return new ChassisSpeeds(rrVx, rrVy, speeds.omegaRadiansPerSecond); | ||
| } | ||
|
|
||
| public Pose2d getFuturePoseFromTime(Time time) { | ||
| ChassisSpeeds speeds = getWallCorrectedChassisSpeeds(); | ||
| double dt = time.in(Seconds); | ||
|
|
||
| double driveMultiplier = LightningShuffleboard.getDouble("Cannon", "OTF Multiplier", 1); | ||
|
|
||
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.
FIELD_LENGTH/FIELD_WIDTHintroduce a second source of truth for the same dimensions already hard-coded elsewhere in this file (e.g.,FIELD). To avoid future drift, consider defining the field dimensions in one place (haveFIELDand other rectangles reference these constants, or derive these constants fromFIELD).