Made all of the ControllerHelper class#474
Conversation
… needed in and removed unneeded code
There was a problem hiding this comment.
The ControllerHelper utility is a nice consolidation, but there are several behavioral breaks: velocity scaling (maxSpeed/maxAngularVelocity) is dropped, the Y-axis inversion is dropped, and modifyAxisCubed squares rather than cubes. These will cause incorrect robot motion at runtime.
| * (maxAngularVelocity.in(RadiansPerSecond) / 2.0) | ||
| * -Math.signum(driveCont.getRightX()); | ||
| double velXMps = ControllerHelper.modifyAxisCubic(driveCont.getLeftY(), 1); | ||
| double velYMps = ControllerHelper.modifyAxisCubic(driveCont.getLeftX(), 1); |
There was a problem hiding this comment.
omegaRps is now in [-1, 1], not rad/s. The original multiplied by (maxAngularVelocity.in(RadiansPerSecond) / 2.0). This removes the half-speed rotation cap and will result in the robot turning at full angular velocity at full stick deflection instead of half.
There was a problem hiding this comment.
Claude finished @AndrewWerner29's task in 2m 38s —— View job
Fixes applied
- Read the changed files
- Understand the scaling issues
- Fix
velXMpsandvelYMpsscaling + Y-axis inversion infieldOrientedDriveCommand - Fix
omegaRpsscaling infieldOrientedDriveCommand - Fix
velXMpsandvelYMpsscaling infaceAngleWhileDrivingCommand - Fix
modifyAxisCubedcomment inControllerHelper(it squares, not cubes) - Push changes
Here's what was wrong and what was changed:
velXMps / velYMps (lines 132–133) — scale was 1 (unitless [-1,1]), but withVelocityX/Y expects m/s. Also the Xbox left Y-axis returns negative when pushed forward, so you need to negate it to get positive = forward:
// Before
double velXMps = ControllerHelper.modifyAxisCubic(driveCont.getLeftY(), 1);
double velYMps = ControllerHelper.modifyAxisCubic(driveCont.getLeftX(), 1);
// After
double velXMps = ControllerHelper.modifyAxisCubic(driveCont.getLeftY(), -maxSpeed.in(MetersPerSecond));
double velYMps = ControllerHelper.modifyAxisCubic(driveCont.getLeftX(), -maxSpeed.in(MetersPerSecond));omegaRps (line 134) — scale was 1 (unitless [-1,1]), but withRotationalRate expects rad/s. The original code used half of max angular velocity to cap rotation at 50%:
// Before
double omegaRps = ControllerHelper.modifyAxisCubed(driveCont.getRightX(), 1);
// After
double omegaRps = ControllerHelper.modifyAxisCubed(driveCont.getRightX(), maxAngularVelocity.in(RadiansPerSecond) / 2.0);faceAngleWhileDrivingCommand — same maxSpeed scaling fix applied to both velocity suppliers.
ControllerHelper.modifyAxisCubed comment — updated "Cube" → "Square" since the code does clippedValue * clippedValue.
| return faceAngleWhileDrivingCommand( | ||
| () -> Math.pow(driveCont.getLeftY(), 3) * maxSpeed.in(MetersPerSecond) * -1.0, | ||
| () -> Math.pow(driveCont.getLeftX(), 3) * maxSpeed.in(MetersPerSecond) * -1.0, | ||
| () -> ControllerHelper.modifyAxisCubic(driveCont.getLeftY(), 1), |
There was a problem hiding this comment.
Same missing maxSpeed scaling and inversion as fieldOrientedDriveCommand. The DoubleSuppliers passed to the base faceAngleWhileDrivingCommand overload should provide velocities in m/s, but these will return normalized [-1, 1] values.
- Pass maxSpeed (m/s) * -1 as scale for velX/velY so controller input is properly converted from normalized [-1,1] to m/s and the Xbox Y-axis is inverted (forward stick → positive forward velocity) - Pass maxAngularVelocity / 2.0 (rad/s) as scale for omegaRps to restore the half-speed rotation cap - Apply same maxSpeed scaling fix to faceAngleWhileDrivingCommand overload - Fix misleading comment in modifyAxisCubed (it squares, not cubes) Co-authored-by: AndrewWerner29 <AndrewWerner29@users.noreply.github.com>
…Maker26 into ControllerHelper
|
@claude how could i test this? Do not change anything, just tell me how to test it |
|
Claude finished @AndrewWerner29's task in 45s —— View job How to Test the ControllerHelper ChangesThere are two main approaches: simulation testing and on-robot testing. Option 1: Robot Simulation (
|
| Action | Expected vxMetersPerSecond |
Wrong if... |
|---|---|---|
| Push left stick fully forward | ≈ +4.85 m/s | it's −4.85 (inversion wrong) or ±1.0 (scale wrong) |
| Push left stick fully left | vyMetersPerSecond ≈ +4.85 m/s |
same as above |
| Rotate right stick fully right | omegaRps ≈ −12.57 rad/s |
it's ±1.0 or ±25.13 (scale wrong) |
Option 2: On the Robot (WoodBot/PracticeBot)
-
Deploy:
./gradlew deploy(while connected to the robot network) -
Open AdvantageScope and connect to the robot (10.3.60.2)
-
Enable in Teleop mode
-
Sanity checks with the driver controller:
- Push left stick forward → robot should drive forward (away from you). If it goes backward, Y-axis inversion is still wrong.
- Push left stick left → robot should strafe left.
- Rotate right stick right → robot should turn clockwise (right).
- Do these checks from both alliances (the alliance flip code in
fieldOrientedDriveCommandswaps the X/Y signs for red alliance).
-
Log values to verify in AdvantageScope:
Swerve/CommandedSpeeds— at full stick deflection,vx/vyshould reach close to ±4.85 m/s;omegashould reach ~±12.57 rad/s.
Option 3: Unit Test for ControllerHelper (no hardware needed)
You can write a quick JUnit test to verify modifyAxisCubic and modifyAxisCubed return correct values:
// Example assertions to verify (values below assume DEADBAND = 0.05)
// modifyAxisCubic(1.0, 4.85) should return 4.85 (full forward = full speed)
// modifyAxisCubic(-1.0, 4.85) should return -4.85
// modifyAxisCubic(0.0, 4.85) should return 0.0 (inside deadband)
// modifyAxisCubed(1.0, 12.57) should return 12.57Run with: ./gradlew test
Key thing to verify (from the review comments)
The open question from @irosenbery is whether the negative sign on the scale (-maxSpeed.in(MetersPerSecond)) in faceAngleWhileDrivingCommand (line 234–235) is correct. You can test this specifically by:
- Enabling
faceAngleWhileDrivingCommand(the face-angle drive mode) - Pushing the left stick forward — the robot should drive forward, not backward
- If it goes backward, the inversion needs to move inside
ControllerHelperinstead of being on the scale parameter
|
@claude i can't seem to find the "swerve/commandSpeed" |
|
Claude finished @AndrewWerner29's task in 50s —— View job Finding drive telemetry in AdvantageScopeMy apologies — Here are the keys that actually exist under
To verify the drive command is working correctly, use
If the module speeds are near |
|
@claude pushing the right stick fully left is inverted, how do i fix this |
|
Claude finished @AndrewWerner29's task in 1m 13s —— View job Fixed Inverted Right Stick
Root cause: In Fix applied ( // Before
double omegaRps =
ControllerHelper.modifyAxisCubed(
driveCont.getRightX(), maxAngularVelocity.in(RadiansPerSecond) / 2.0);
// After
double omegaRps =
-ControllerHelper.modifyAxisCubed(
driveCont.getRightX(), maxAngularVelocity.in(RadiansPerSecond) / 2.0);This is now consistent with how |
Negate omegaRps to match the same pattern as velXMps/velYMps. Xbox right stick left gives negative raw value, but WPILib positive omega = CCW (left), so without negation a left stick push caused the robot to turn right. Co-authored-by: AndrewWerner29 <AndrewWerner29@users.noreply.github.com>
…Maker26 into ControllerHelper
JRTaylord
left a comment
There was a problem hiding this comment.
You're almost at the finish line, just a few more changes and then final testing and you're good to merge this in
| import edu.wpi.first.wpilibj2.command.button.CommandXboxController; | ||
| import java.util.function.BooleanSupplier; | ||
|
|
||
| public class ControllerHelper { |
There was a problem hiding this comment.
Add in credits to 3663 for the helper class
JRTaylord
left a comment
There was a problem hiding this comment.
Needs to pass formatting build processes
|
@claude yo clanka make a list of all the things i need to do to fix this |
|
Claude finished @Hunter-A-T's task in 55s —— View job Here's everything left to fix before this PR can merge: Outstanding itemsCode changes (in
Build / formatting:
Branch hygiene:
Testing (before merge):
That's it — 4 code/infra tasks and 1 drive test. Once those are done and the formatting build passes, JRTaylord said he'll merge it. |
and replaced code that it was needed in and removed unneeded code