11package frc .robot .subsystems .pathHandler ;
22
33import choreo .Choreo ;
4-
54import choreo .trajectory .SwerveSample ;
65import choreo .trajectory .Trajectory ;
76import edu .wpi .first .wpilibj .Timer ;
8- import frc .robot .Robot ;
97import frc .robot .constants .RobotStateConstants ;
108import frc .robot .constants .TagServoingConstants ;
119import frc .robot .subsystems .drive .DriveSubsystem ;
12- import net .jafama .FastMath ;
13-
1410import java .util .List ;
1511import java .util .Optional ;
1612import java .util .Set ;
13+ import net .jafama .FastMath ;
1714import org .strykeforce .telemetry .measurable .MeasurableSubsystem ;
1815import org .strykeforce .telemetry .measurable .Measure ;
1916
@@ -133,13 +130,16 @@ private void drivePath() {
133130
134131 private void drivePathServo () {
135132 if (isHandling && runningPath && currPath != null && isServoing ) {
136- driveSubsystem .calculateControllerServo (currPath .sampleAt (timer .get (), mirrorTrajectory ).get (), 0.0 ); // TODO: use tag servoing here when ready
133+ driveSubsystem .calculateControllerServo (
134+ currPath .sampleAt (timer .get (), mirrorTrajectory ).get (),
135+ 0.0 ); // TODO: use tag servoing here when ready
137136 if (timer .hasElapsed (currPath .getTotalTime ())) {
138137 driveSubsystem .setAutoDebugMsg ("End " + currPathString );
139138 runningPath = false ;
140139 timer .stop ();
141140 timer .reset ();
142- driveSubsystem .calculateControllerServo (currPath .getFinalSample (mirrorTrajectory ).get (), 0.0 );
141+ driveSubsystem .calculateControllerServo (
142+ currPath .getFinalSample (mirrorTrajectory ).get (), 0.0 );
143143 if (currState == PathStates .DRIVE_FETCH ) {
144144 currState = PathStates .FETCH ;
145145 } else if (currState == PathStates .DRIVE_PLACE_SERVO ) {
@@ -186,17 +186,25 @@ public void killPathHandlerAfterPath() {
186186
187187 private boolean shouldTransitionToServoing () {
188188 boolean isCloseEnough = false ;
189- double preNormalizedAngle = FastMath .toRadians (RobotStateConstants .kNodeAngles [FastMath .floorToInt ((NodeNames .get (0 ) - 'a' ) / 2 )]);
190- double goal = mirrorTrajectory ? FastMath .normalizeMinusPiPi (preNormalizedAngle + Math .PI ) : preNormalizedAngle ;
189+ double preNormalizedAngle =
190+ FastMath .toRadians (
191+ RobotStateConstants .kNodeAngles [FastMath .floorToInt ((NodeNames .get (0 ) - 'a' ) / 2 )]);
192+ double goal =
193+ mirrorTrajectory
194+ ? FastMath .normalizeMinusPiPi (preNormalizedAngle + Math .PI )
195+ : preNormalizedAngle ;
191196 double pos = driveSubsystem .getGyroRotation2d ().getRadians ();
192- if (goal < -Math .PI /2 || goal > Math .PI /2 ) {
193- isCloseEnough = FastMath .abs (FastMath .normalizeZeroTwoPi (pos ) - FastMath .normalizeZeroTwoPi (goal )) < FastMath .toRadians (TagServoingConstants .kAngleCloseEnough );
197+ if (goal < -Math .PI / 2 || goal > Math .PI / 2 ) {
198+ isCloseEnough =
199+ FastMath .abs (FastMath .normalizeZeroTwoPi (pos ) - FastMath .normalizeZeroTwoPi (goal ))
200+ < FastMath .toRadians (TagServoingConstants .kAngleCloseEnough );
194201 } else {
195- isCloseEnough = FastMath .abs (pos - goal ) < FastMath .toRadians (TagServoingConstants .kAngleCloseEnough );
202+ isCloseEnough =
203+ FastMath .abs (pos - goal ) < FastMath .toRadians (TagServoingConstants .kAngleCloseEnough );
196204 }
197205 return currState == PathStates .DRIVE_PLACE
198- && timer .hasElapsed (currPath .getTotalTime () - 1.0 )
199- && isCloseEnough ;
206+ && timer .hasElapsed (currPath .getTotalTime () - 1.0 )
207+ && isCloseEnough ;
200208 }
201209
202210 public void periodic () {
@@ -209,8 +217,8 @@ public void periodic() {
209217 break ;
210218 case FETCH :
211219 // if (robotStateSubsystem.hasPiece) {
212- advanceNodes ();
213- currState = PathStates .DRIVE_PLACE ;
220+ advanceNodes ();
221+ currState = PathStates .DRIVE_PLACE ;
214222 // }
215223 break ;
216224 case DRIVE_PLACE :
@@ -226,7 +234,7 @@ public void periodic() {
226234 break ;
227235 case PLACE :
228236 // if (RobotStateSubsystem.State != RobotStateSubsystem.hasPiece) {
229- currState = PathStates .DRIVE_FETCH ;
237+ currState = PathStates .DRIVE_FETCH ;
230238 // }
231239 break ;
232240 case DONE :
0 commit comments