1616import com .pathplanner .lib .pathfinding .Pathfinding ;
1717import com .pathplanner .lib .util .HolonomicPathFollowerConfig ;
1818import com .pathplanner .lib .util .PIDConstants ;
19+ import com .pathplanner .lib .util .PathPlannerLogging ;
1920import com .pathplanner .lib .util .ReplanningConfig ;
2021import edu .wpi .first .math .controller .PIDController ;
2122import edu .wpi .first .math .geometry .Pose2d ;
@@ -550,6 +551,31 @@ public void driveToPose(Pose2d targetPose) {
550551 pathfindCommand .schedule ();
551552 }
552553
554+ public void driveToPath (String pathName ) {
555+ this .setAlignState (AlignState .MANUAL );
556+
557+ PathPlannerPath path = PathPlannerPath .fromPathFile (pathName );
558+
559+ // if(DriverStation.getAlliance() === Alliance.Blue) {
560+ // path.flipPath();
561+ // }
562+
563+ PathConstraints constraints =
564+ new PathConstraints (
565+ 3.0 ,
566+ 4.0 ,
567+ Constants .ConversionConstants .kDegreesToRadians * 540 ,
568+ Constants .ConversionConstants .kDegreesToRadians * 720 );
569+
570+ PathPlannerLogging .setLogTargetPoseCallback (
571+ (target ) -> {
572+ Logger .recordOutput ("targetPose" , target );
573+ });
574+
575+ pathfindCommand = AutoBuilder .pathfindThenFollowPath (path , constraints , 0.0 );
576+ pathfindCommand .schedule ();
577+ }
578+
553579 public void stopDriveToPose () {
554580 if (pathfindCommand != null ) {
555581 pathfindCommand .cancel ();
@@ -562,50 +588,12 @@ public void setPoseTarget(Pose2d pose) {
562588 targetTightPose = pose ;
563589 }
564590
565- public Pose2d getEndgamePose () {
566- // Blue Alliance Poses
567- Pose2d leftClimbPose2d = new Pose2d (4.61 , 4.48 , Rotation2d .fromDegrees (-60 ));
568- Pose2d rightClimbPose2d = new Pose2d (4.66 , 3.67 , Rotation2d .fromDegrees (60 ));
569- Pose2d farClimbPose2d = new Pose2d (5.38 , 4.11 , Rotation2d .fromDegrees (180 ));
570-
571- if (DriverStation .getAlliance ().isPresent ()
572- && DriverStation .getAlliance ().get () == DriverStation .Alliance .Red ) {
573- // Red Alliance Poses
574- leftClimbPose2d = new Pose2d (11.882 , 3.67 , Rotation2d .fromDegrees (120 ));
575- rightClimbPose2d = new Pose2d (11.932 , 4.48 , Rotation2d .fromDegrees (-120 ));
576- farClimbPose2d = new Pose2d (11.162 , 4.11 , Rotation2d .fromDegrees (0 ));
577- }
578-
579- double distanceToTargetLeft =
580- Math .hypot (
581- getFieldToRobot .get ().getX () - leftClimbPose2d .getX (),
582- getFieldToRobot .get ().getY () - leftClimbPose2d .getY ());
583- double distanceToTargetRight =
584- Math .hypot (
585- getFieldToRobot .get ().getX () - rightClimbPose2d .getX (),
586- getFieldToRobot .get ().getY () - rightClimbPose2d .getY ());
587- double distanceToTargetFar =
588- Math .hypot (
589- getFieldToRobot .get ().getX () - farClimbPose2d .getX (),
590- getFieldToRobot .get ().getY () - farClimbPose2d .getY ());
591-
592- Pose2d targetPose = new Pose2d (new Translation2d (), Rotation2d .fromDegrees (180 ));
593-
594- if (distanceToTargetLeft < distanceToTargetRight
595- && distanceToTargetLeft < distanceToTargetFar ) {
596- targetPose = leftClimbPose2d ;
597- } else if (distanceToTargetRight < distanceToTargetLeft
598- && distanceToTargetRight < distanceToTargetFar ) {
599- targetPose = rightClimbPose2d ;
600- } else {
601- targetPose = farClimbPose2d ;
602- }
603-
604- return targetPose ;
591+ public void driveToSpeaker () {
592+ driveToPath ("speaker" );
605593 }
606594
607- public void driveToSpeaker () {
608- driveToPose ( new Pose2d ( AllianceUtil . getFieldToSpeaker (), new Rotation2d ()) );
595+ public void driveToSource () {
596+ driveToPath ( "shopSource" );
609597 }
610598
611599 public void driveToEndgame () {
@@ -635,29 +623,15 @@ public void driveToEndgame() {
635623 getFieldToRobot .get ().getX () - farClimbPose2d .getX (),
636624 getFieldToRobot .get ().getY () - farClimbPose2d .getY ());
637625
638- PathPlannerPath path = null ;
639-
640626 if (distanceToTargetLeft < distanceToTargetRight
641627 && distanceToTargetLeft < distanceToTargetFar ) {
642- path = PathPlannerPath . fromPathFile ( "LeftEndgame " );
628+ driveToPath ( "leftEndgame " );
643629 } else if (distanceToTargetRight < distanceToTargetLeft
644630 && distanceToTargetRight < distanceToTargetFar ) {
645- path = PathPlannerPath . fromPathFile ( "RightEndgame " );
631+ driveToPath ( "rightEndgame " );
646632 } else {
647- path = PathPlannerPath . fromPathFile ( "FarEndgame " );
633+ driveToPath ( "farEndgame " );
648634 }
649-
650- this .setAlignState (AlignState .MANUAL );
651-
652- PathConstraints constraints =
653- new PathConstraints (
654- 3.0 ,
655- 4.0 ,
656- Constants .ConversionConstants .kDegreesToRadians * 540 ,
657- Constants .ConversionConstants .kDegreesToRadians * 720 );
658-
659- pathfindCommand = AutoBuilder .pathfindThenFollowPath (path , constraints , 0.0 );
660- pathfindCommand .schedule ();
661635 }
662636
663637 public boolean isAligned () {
0 commit comments