@@ -230,22 +230,7 @@ public Command customFollowPathComamnd(PathPlannerPath path, PPHolonomicDriveCon
230230 this );
231231 }
232232
233- /*
234- * If you broke it into functions: updateData -> setChassisSpeeds(data, state) -> runSwerve(speeds)
235- * Periodic Logic:
236- * Data Collection(Modules, gyro, Vision, odometry)
237- * Update Controllers use
238- * Setting Chassis Speeds based on driveState
239- * Teleop sets based of joystick, Autons sets based on pathplanner(ppDesiredSpeeds), etc. etc.
240- * runSwerve() function sets the desired state to modules
241- * State is set by setDriveState() and related commands which also resets the controllers
242- */
243- @ Override
244- public void periodic () {
245- ///////////////////// DATA COLLECTION AND UPDATE CONTROLLERS AND ODOMETRY \\\\\\\\\\\\\\\\\\
246- /* Modules */
247- for (Module module : modules ) module .periodic ();
248-
233+ private void updateSensorsAndOdometry () {
249234 /* GYRO */
250235 gyro .updateInputs (gyroInputs );
251236 Logger .processInputs ("Drive/Gyro" , gyroInputs );
@@ -265,31 +250,24 @@ public void periodic() {
265250 if (observation .hasObserved ())
266251 poseEstimator .addVisionMeasurement (observation .pose (), observation .timeStamp (), observation .stdDevs ());
267252
268- Logger .recordOutput (
269- observation .camName () + "/stdDevX" , observation .stdDevs ().get (0 ));
270- Logger .recordOutput (
271- observation .camName () + "/stdDevY" , observation .stdDevs ().get (1 ));
272- Logger .recordOutput (
273- observation .camName () + "/stdDevTheta" ,
274- observation .stdDevs ().get (2 ));
275- // Logger.recordOutput(observation.camName()+"/TransformFromOdometry",
276- // odometry.getPoseMeters().minus(observation.pose()));
253+ Logger .recordOutput (observation .camName () + "/stdDevX" , observation .stdDevs ().get (0 ));
254+ Logger .recordOutput (observation .camName () + "/stdDevY" , observation .stdDevs ().get (1 ));
255+ Logger .recordOutput (observation .camName () + "/stdDevTheta" , observation .stdDevs ().get (2 ));
277256 }
278257
279258 poseEstimator .update (robotRotation , getModulePositions ());
280259 odometry .update (robotRotation , getModulePositions ());
281260
282261 field .setRobotPose (getPoseEstimate ());
262+ }
283263
284- // Logger.recordOutput("Drive/Odometry/FieldCurrentChassisSpeeds",
285- // ChassisSpeeds.fromRobotRelativeSpeeds(getRobotChassisSpeeds(), robotRotation));
286-
287- /* Updating Controllers */
264+ private void updateDriveControllers () {
288265 headingController .updateHeadingController ();
289266 autoAlignController .updateAlignmentControllers ();
290267 GoalPoseChooser .updateSideStuff ();
268+ }
291269
292- ///////////////////// SETTING DESIRED SPEEDS FROM DRIVE STATE \\\\\\\\\\\\\\\\\\
270+ private void computeDesiredSpeeds () {
293271 ChassisSpeeds teleopSpeeds =
294272 teleopController .computeChassiSpeeds (getPoseEstimate ().getRotation (), getRobotChassisSpeeds (), false );
295273 switch (driveState ) {
@@ -312,8 +290,7 @@ public void periodic() {
312290 headingController .getSnapOutput (getPoseEstimate ().getRotation ()));
313291 break ;
314292 case INTAKE_HEADING_ALIGN :
315- goalRotation = AllianceFlipUtil .apply (
316- GoalPoseChooser .getIntakePose (getPoseEstimate ()).getRotation ());
293+ goalRotation = AllianceFlipUtil .apply (GoalPoseChooser .getIntakePose (getPoseEstimate ()).getRotation ());
317294 desiredSpeeds = new ChassisSpeeds (
318295 teleopSpeeds .vxMetersPerSecond ,
319296 teleopSpeeds .vyMetersPerSecond ,
@@ -327,8 +304,6 @@ public void periodic() {
327304 headingController .getSnapOutput (getPoseEstimate ().getRotation ()));
328305 break ;
329306 case DRIVE_TO_CORAL :
330- desiredSpeeds = autoAlignController .calculate (goalPose , getPoseEstimate ());
331- break ;
332307 case DRIVE_TO_INTAKE :
333308 desiredSpeeds = autoAlignController .calculate (goalPose , getPoseEstimate ());
334309 break ;
@@ -343,9 +318,10 @@ public void periodic() {
343318 case DRIVE_TO_ALGAE :
344319 // desiredSpeeds = autoAlignController.calculate(goalPose, getPoseEstimate());
345320 ChassisSpeeds algaeAlignSpeeds = autoAlignController .calculate (goalPose , getPoseEstimate ());
346- double forwardJoy = (goalPose .getX () > AllianceFlipUtil .apply (frc .robot .game .FieldConstants .kReefCenter .getX ()))
347- ? -teleopSpeeds .vxMetersPerSecond
348- : teleopSpeeds .vxMetersPerSecond ;
321+ double forwardJoy =
322+ (goalPose .getX () > AllianceFlipUtil .apply (frc .robot .game .FieldConstants .kReefCenter .getX ()))
323+ ? -teleopSpeeds .vxMetersPerSecond
324+ : teleopSpeeds .vxMetersPerSecond ;
349325 if (AllianceFlipUtil .shouldFlip ()) forwardJoy *= -1 ;
350326 desiredSpeeds = new ChassisSpeeds (
351327 /* Flips speed to preserve field relative. Not best solution, but probably good enough? */
@@ -389,8 +365,16 @@ public void periodic() {
389365 default :
390366 /* Defaults to Teleop control if no other cases are run*/
391367 }
368+ }
392369
393- ///////////////////////// SETS DESIRED CHASSIS SPEED TO MODULES \\\\\\\\\\\\\\\\\\\\\\\\
370+ @ Override
371+ public void periodic () {
372+ for (Module module : modules ) module .periodic ();
373+
374+ updateSensorsAndOdometry ();
375+ updateDriveControllers ();
376+ computeDesiredSpeeds ();
377+
394378 if (desiredSpeeds != null ) runSwerve (desiredSpeeds );
395379 }
396380
@@ -409,8 +393,6 @@ public void setDriveState(DriveState state) {
409393 driveState = state ;
410394 switch (driveState ) {
411395 case PROCESSOR_HEADING_ALIGN :
412- headingController .reset (getPoseEstimate ().getRotation (), gyroInputs .yawVelocityPS );
413- break ;
414396 case REEF_HEADING_ALIGN :
415397 headingController .reset (getPoseEstimate ().getRotation (), gyroInputs .yawVelocityPS );
416398 break ;
0 commit comments