1616import org .littletonrobotics .urcl .URCL ;
1717import org .photonvision .PhotonCamera ;
1818
19+ import edu .wpi .first .math .geometry .Pose2d ;
1920import edu .wpi .first .math .geometry .Rotation2d ;
2021import edu .wpi .first .math .geometry .Transform2d ;
2122import edu .wpi .first .wpilibj .DataLogManager ;
@@ -74,8 +75,8 @@ public void bindDriveControls() {
7475 () -> m_driverController .getR2Axis () - m_driverController .getL2Axis (),
7576 m_driverController .getHID ()::getSquareButton ));
7677
77- double distanceTolerance = 0.05 ;
78- double angleTolerance = 5 ;
78+ double distanceTolerance = 0.03 ;
79+ double angleTolerance = 3 ;
7980 m_driverController .button (Button .kSquare ) // home
8081 .whileTrue (
8182 new DriveCommand (
@@ -90,36 +91,46 @@ public void bindDriveControls() {
9091 DriveCommand .moveForward (m_driveSubsystem , -1.8 , distanceTolerance , angleTolerance )));
9192
9293 Transform2d robotToTarget = new Transform2d (1 , 0 , Rotation2d .fromDegrees (180 ));
93- m_driverController .button (Button .kTriangle )
94- .whileTrue (
95- AlignCommand .moveTo (
96- m_driveSubsystem , m_poseEstimationSubystem ,
97- kFieldLayout .getTagPose (17 ).get ().toPose2d ().plus (robotToTarget ),
98- distanceTolerance , angleTolerance ));
99-
10094 double angleOfCoverageInDegrees = 90 ;
10195 double distanceThresholdInMeters = 4 ;
102- m_driverController .button (Button .kLeftBumper )
96+ m_driverController .button (Button .kTriangle )
10397 .whileTrue (
104- AlignCommand .turnToClosestTag (
105- m_driveSubsystem , m_poseEstimationSubystem , angleOfCoverageInDegrees ,
106- distanceThresholdInMeters ,
107- distanceTolerance , angleTolerance ));
98+ alignTest (1 , robotToTarget , distanceTolerance , angleTolerance ));
99+ // m_driverController.button(Button.kTriangle)
100+ // .whileTrue(
101+ // AlignCommand.turnToClosestTag(
102+ // m_driveSubsystem, m_poseEstimationSubystem, angleOfCoverageInDegrees,
103+ // distanceThresholdInMeters,
104+ // distanceTolerance, angleTolerance));
108105
109- m_driverController .button (Button .kRightBumper )
106+ m_driverController .button (Button .kLeftBumper )
110107 .whileTrue (
111108 AlignCommand .moveToClosestTag (
112109 m_driveSubsystem , m_poseEstimationSubystem , angleOfCoverageInDegrees ,
113110 distanceThresholdInMeters , robotToTarget ,
114111 distanceTolerance , angleTolerance ));
115112
116- m_driverController .button (Button .kLeftTrigger )
113+ m_driverController .button (Button .kRightBumper )
117114 .whileTrue (
118115 tourCommand (
119- m_driveSubsystem , m_poseEstimationSubystem , distanceTolerance , angleTolerance ,
116+ m_driveSubsystem , m_poseEstimationSubystem , distanceTolerance ,
117+ angleTolerance ,
120118 robotToTarget , 12 , 15 , 14 , 16 , 17 , 18 , 19 , 20 , 21 , 22 ));
121119 }
122120
121+ private Command alignTest (int tagIDs , Transform2d robotToTarget , double distanceTolerance , double angleTolerance ) {
122+ return sequence (
123+ AlignCommand .moveTo (
124+ m_driveSubsystem , m_poseEstimationSubystem ,
125+ kFieldLayout .getTagPose (1 ).get ().toPose2d ().plus (robotToTarget ),
126+ distanceTolerance , angleTolerance ),
127+ AlignCommand .moveTo (
128+ m_driveSubsystem , m_poseEstimationSubystem ,
129+ () -> m_poseEstimationSubystem .getEstimatedPose ()
130+ .plus (pose (-2 , 0 , 0 ).minus (Pose2d .kZero )),
131+ distanceTolerance , angleTolerance ));
132+ }
133+
123134 Command tourCommand (DriveSubsystem driveSubsystem , PoseEstimationSubsystem poseEstimationSubystem ,
124135 double distanceTolerance , double angleTolerance , Transform2d robotToTarget , int ... tagIDs ) {
125136 List <Command > commands = Arrays .stream (tagIDs ).mapToObj (i -> kFieldLayout .getTagPose (i ))
0 commit comments