33import static edu .wpi .first .math .util .Units .*;
44import static edu .wpi .first .wpilibj2 .command .Commands .*;
55import static frc .robot .Constants .*;
6- import static frc .robot .Constants .DriveConstants .*;
76import static frc .robot .subsystems .PoseEstimationSubsystem .*;
87
98import java .util .LinkedList ;
109import java .util .List ;
1110import java .util .function .Supplier ;
1211
1312import edu .wpi .first .math .geometry .Pose2d ;
14- import edu .wpi .first .math .geometry .Rotation2d ;
1513import edu .wpi .first .math .geometry .Transform2d ;
1614import edu .wpi .first .wpilibj2 .command .Command ;
1715import edu .wpi .first .wpilibj2 .command .Commands ;
16+ import edu .wpi .first .wpilibj2 .command .WaitCommand ;
1817import frc .robot .commands .DriveCommand ;
1918import frc .robot .commands .PathDriveCommand ;
2019import frc .robot .subsystems .DriveSubsystem ;
@@ -40,38 +39,6 @@ public static Command testAllSubsystems() {
4039 m_driveSubsystem .testCommand ());
4140 }
4241
43- /**
44- * Returns a {@code Command} for testing the rotation capability of the robot.
45- *
46- * @return a {@code Command} for testing the rotation capability of the robot
47- */
48- public static Command testRotation () {
49- double rotionalSpeed = kTurnMaxAngularSpeed * 0.9 ;
50- double duration = 2.0 ;
51- return sequence (
52- m_driveSubsystem .run (() -> m_driveSubsystem .setModuleAngles (0 )).withTimeout (0.1 ),
53- m_driveSubsystem .run (() -> m_driveSubsystem .drive (.5 , 0 , rotionalSpeed , true ))
54- .withTimeout (duration ),
55- m_driveSubsystem .run (() -> m_driveSubsystem .drive (-.5 , 0 , -rotionalSpeed , true ))
56- .withTimeout (duration ),
57- m_driveSubsystem .run (() -> m_driveSubsystem .drive (0.05 , 0 , 0 , false ))
58- .withTimeout (duration ),
59- m_driveSubsystem .run (() -> m_driveSubsystem .drive (0 , 0 , rotionalSpeed , false ))
60- .withTimeout (duration ),
61- m_driveSubsystem .run (() -> m_driveSubsystem .drive (0.05 , 0 , 0 , false ))
62- .withTimeout (duration ),
63- m_driveSubsystem .run (() -> m_driveSubsystem .drive (0 , 0 , -rotionalSpeed , false ))
64- .withTimeout (duration ),
65- m_driveSubsystem .run (() -> m_driveSubsystem .drive (0.05 , 0 , 0 , false ))
66- .withTimeout (duration ),
67- m_driveSubsystem .run (() -> m_driveSubsystem .drive (0 , 0 , rotionalSpeed , false ))
68- .withTimeout (duration ),
69- m_driveSubsystem .run (() -> m_driveSubsystem .drive (0.05 , 0 , 0 , false ))
70- .withTimeout (duration ),
71- m_driveSubsystem .run (() -> m_driveSubsystem .drive (0 , 0 , -rotionalSpeed , false ))
72- .withTimeout (duration ));
73- }
74-
7542 /**
7643 * Returns a {@code Command} for moving forward and then backward.
7744 *
@@ -81,7 +48,7 @@ public static Command testRotation() {
8148 *
8249 * @return a {@code Command} for moving forward and then backward.
8350 */
84- public static Command moveForwardBackward2Controllers (double distanceInFeet , double distanceTolerance ,
51+ public static Command moveForwardBackward (double distanceInFeet , double distanceTolerance ,
8552 double angleTolerance ) {
8653 return sequence (
8754 new DriveCommand (m_driveSubsystem , distanceTolerance , angleTolerance , pose (0.0 , 0 , 0 )),
@@ -119,58 +86,6 @@ distanceTolerance, angleTolerance, pose(0.0, 0, 0)).withTimeout(1),
11986 new DriveCommand (m_driveSubsystem , distanceTolerance , angleTolerance , pose (0.0 , 0 , 0 )));
12087 }
12188
122- /**
123- * Returns a {@code Command} for moving the robot on a circle.
124- *
125- * @param radius the radius of the circle in meters
126- * @param initialAngularIncrement the initial angular increment in degrees which
127- * describes how quickly the robot to move on the circle
128- * @param finalAngularIncrement the final angular increment in degrees which
129- * describes how quickly the robot to move on the circle
130- * @param distanceTolerance the distance error in meters which is tolerable
131- * @param angleTolerance the angle error in degrees which is tolerable
132- * @param intermediateDistanceTolerance the distance error in meters which is
133- * tolerable for intermeidate target {@code Pose2d}s
134- * @param intermediateAngleToleranceInDegrees the angle error in degrees which
135- * is tolerable for intermeidate target {@code Pose2d}s
136- * @param poseCount the number of {@code Pose2d}s on the circle
137- *
138- * @return a {@code Command} for moving the robot on a circle
139- */
140- public static Command moveOnOval (double radius , double initialAngularIncrement , double finalAngularIncrement ,
141- double distanceTolerance , double angleTolerance , double intermediateDistanceTolerance ,
142- double intermediateAngleToleranceInDegrees , int poseCount ) {
143- Rotation2d angle = Rotation2d .kZero ;
144- var l = new LinkedList <Pose2d >();
145- for (double i = 0 ; i < poseCount ; i ++) {
146- var t = translation (radius , 0 ).rotateBy (angle );
147- l .add (new Pose2d (translation (t .getX () + radius , t .getY () / 2 ), angle ));
148- double progress = i / poseCount ;
149- double angularVelocity = progress * finalAngularIncrement + (1 - progress ) * initialAngularIncrement ;
150- angle = angle .plus (rotation (angularVelocity ));
151- }
152- return new PathDriveCommand (m_driveSubsystem , distanceTolerance , angleTolerance , intermediateDistanceTolerance ,
153- intermediateAngleToleranceInDegrees , l .toArray (new Pose2d [0 ]));
154- }
155-
156- /**
157- * Returns a {@code Command} for turning the robot toward the specified
158- * {@code AprilTag}.
159- *
160- * @param tagID the ID of the {@code AprilTag}
161- * @return a {@code Command} for turning the robot toward the specified
162- * {@code AprilTag}
163- */
164- public static Command turnTowardTag (int tagID ) {
165- return m_driveSubsystem .run (() -> {
166- Rotation2d a = m_poseEstimationSubsystem .angularDisplacement (1 );
167- if (a != null )
168- m_driveSubsystem .drive (
169- 0 , 0 , a .getRadians () * kTurnP ,
170- false );
171- }).withTimeout (1 );
172- }
173-
17489 /**
17590 * Returns a {@code Command} for aligning the robot to the specified
17691 * {@code AprilTag}s.
@@ -209,7 +124,7 @@ public static Command alignToTags(double distanceTolerance, double angleToleranc
209124 intermediateDistanceTolerance , intermediateAngleToleranceInDegrees , l .stream ()
210125 .map (p -> (Supplier <Pose2d >) (() -> m_poseEstimationSubsystem .odometryCentricPose (p )))
211126 .toList ());
212- commands .add (command );
127+ commands .add (command . andThen ( new WaitCommand ( .5 )) );
213128 }
214129 return sequence (commands .toArray (new Command [0 ]));
215130 }
0 commit comments