55import edu .wpi .first .math .geometry .Pose2d ;
66import edu .wpi .first .math .geometry .Transform2d ;
77import edu .wpi .first .math .geometry .Translation2d ;
8+ import edu .wpi .first .wpilibj2 .command .Command ;
89import frc .robot .subsystems .DriveSubsystem ;
910import frc .robot .subsystems .PoseEstimationSubsystem ;
1011
1415 * @author Jeong-Hyon Hwang (jhhbrown@gmail.com)
1516 * @author Andrew Hwang (u.andrew.h@gmail.com)
1617 */
17- public class AlignCommand extends DriveCommand {
18+ public class AlignCommand {
1819
1920 /**
20- * Constructs a new {@code DriveCommand } whose purpose is to move the
21+ * Constructs a new {@code Command } whose purpose is to move the
2122 * robot to a certain target pose.
2223 *
2324 * @param driveSubsystem the {@code DriveSubsystem} to use
2425 * @param poseEstimationSubsystem the {@code PoseEstimationSubsystem} to use
2526 * @param targetPoseSupplier a {@code Supplier<Pose2d>} that provides the
2627 * target pose to which the robot should move.
2728 * This is used at the commencement of this
28- * {@code DriveCommand } (i.e., when the scheduler
29+ * {@code Command } (i.e., when the scheduler
2930 * begins to periodically execute this
30- * {@code DriveCommand })
31+ * {@code Command })
3132 * @param distanceTolerance the distance error in meters which is tolerable
3233 * @param angleTolerance the angle error in degrees which is tolerable
34+ * @return a new {@code Command} whose purpose is to move the
35+ * robot to a certain target pose
3336 */
34- public AlignCommand (DriveSubsystem driveSubsystem , PoseEstimationSubsystem poseEstimationSubsystem ,
37+ public static Command driveCommand (DriveSubsystem driveSubsystem , PoseEstimationSubsystem poseEstimationSubsystem ,
3538 Supplier <Pose2d > targetPoseSupplier ,
3639 double distanceTolerance ,
3740 double angleTolerance ) {
38- super (driveSubsystem , () -> poseEstimationSubsystem .getEstimatedPose (), targetPoseSupplier , distanceTolerance ,
41+ return new DriveCommand (driveSubsystem , () -> poseEstimationSubsystem .getEstimatedPose (), targetPoseSupplier ,
42+ distanceTolerance ,
3943 angleTolerance );
4044 }
4145
4246 /**
43- * Constructs a {@code DriveCommand } for moving the robot to the specified
47+ * Constructs a {@code Command } for moving the robot to the specified
4448 * target.
4549 *
4650 * @param driveSubsystem the {@code DriveSubsystem} to use
@@ -51,35 +55,38 @@ public AlignCommand(DriveSubsystem driveSubsystem, PoseEstimationSubsystem poseE
5155 * @return a {@code Commmand} for moving the robot to the specified
5256 * target
5357 */
54- public static DriveCommand moveTo (DriveSubsystem driveSubsystem , PoseEstimationSubsystem poseEstimationSubsystem ,
58+ public static Command moveTo (DriveSubsystem driveSubsystem ,
59+ PoseEstimationSubsystem poseEstimationSubsystem ,
5560 Pose2d targetPose , double distanceTolerance , double angleTolerance ) {
5661 return moveTo (driveSubsystem , poseEstimationSubsystem , () -> targetPose , distanceTolerance , angleTolerance );
5762 }
5863
5964 /**
60- * Constructs a {@code DriveCommand } for moving the robot to the specified
65+ * Constructs a {@code Command } for moving the robot to the specified
6166 * target.
6267 *
6368 * @param driveSubsystem the {@code DriveSubsystem} to use
6469 * @param poseEstimationSubsystem the {@code PoseEstimationSubsystem} to use
6570 * @param targetPoseSupplier a {@code Supplier<Pose2d>} that provides the
6671 * {@code Pose2d} of the target.
67- * This is used at the commencement of the {@code DriveCommand } (i.e.,
72+ * This is used at the commencement of the {@code Command } (i.e.,
6873 * when the scheduler begins to periodically execute the
69- * {@code DriveCommand })
74+ * {@code Command })
7075 * @param distanceTolerance the distance error in meters which is tolerable
7176 * @param angleTolerance the angle error in degrees which is tolerable
7277 * @return a {@code Commmand} for moving the robot to the specified
7378 * target
7479 */
75- public static DriveCommand moveTo (DriveSubsystem driveSubsystem , PoseEstimationSubsystem poseEstimationSubsystem ,
80+ public static Command moveTo (DriveSubsystem driveSubsystem ,
81+ PoseEstimationSubsystem poseEstimationSubsystem ,
7682 Supplier <Pose2d > targetPoseSupplier , double distanceTolerance , double angleTolerance ) {
77- return new AlignCommand (driveSubsystem , poseEstimationSubsystem , targetPoseSupplier ,
83+ return driveCommand (
84+ driveSubsystem , poseEstimationSubsystem , targetPoseSupplier ,
7885 distanceTolerance , angleTolerance );
7986 }
8087
8188 /**
82- * Constructs a {@code DriveCommand } for turning the robot to the specified
89+ * Constructs a {@code Command } for turning the robot to the specified
8390 * target.
8491 *
8592 * @param driveSubsystem the {@code DriveSubsystem} to use
@@ -90,30 +97,33 @@ public static DriveCommand moveTo(DriveSubsystem driveSubsystem, PoseEstimationS
9097 * @return a {@code Commmand} for turning the robot to the specified
9198 * target
9299 */
93- public static DriveCommand turnTo (DriveSubsystem driveSubsystem , PoseEstimationSubsystem poseEstimationSubsystem ,
100+ public static Command turnTo (DriveSubsystem driveSubsystem ,
101+ PoseEstimationSubsystem poseEstimationSubsystem ,
94102 Pose2d targetPose , double distanceTolerance , double angleTolerance ) {
95103 return turnTo (driveSubsystem , poseEstimationSubsystem , () -> targetPose , distanceTolerance , angleTolerance );
96104 }
97105
98106 /**
99- * Constructs a {@code DriveCommand } for turning the robot to the specified
107+ * Constructs a {@code Command } for turning the robot to the specified
100108 * target.
101109 *
102110 * @param driveSubsystem the {@code DriveSubsystem} to use
103111 * @param poseEstimationSubsystem the {@code PoseEstimationSubsystem} to use
104112 * @param targetPoseSupplier a {@code Supplier<Pose2d>} that provides the
105113 * {@code Pose2d} of the target.
106- * This is used at the commencement of the {@code DriveCommand } (i.e.,
114+ * This is used at the commencement of the {@code Command } (i.e.,
107115 * when the scheduler begins to periodically execute the
108- * {@code DriveCommand })
116+ * {@code Command })
109117 * @param distanceTolerance the distance error in meters which is tolerable
110118 * @param angleTolerance the angle error in degrees which is tolerable
111119 * @return a {@code Commmand} for turning the robot to the specified
112120 * target
113121 */
114- public static DriveCommand turnTo (DriveSubsystem driveSubsystem , PoseEstimationSubsystem poseEstimationSubsystem ,
122+ public static Command turnTo (DriveSubsystem driveSubsystem ,
123+ PoseEstimationSubsystem poseEstimationSubsystem ,
115124 Supplier <Pose2d > targetPoseSupplier , double distanceTolerance , double angleTolerance ) {
116- return new AlignCommand (driveSubsystem , poseEstimationSubsystem ,
125+ return driveCommand (
126+ driveSubsystem , poseEstimationSubsystem ,
117127 () -> {
118128 var transform = new Transform2d (0 , 0 ,
119129 poseEstimationSubsystem .angularDisplacement (targetPoseSupplier .get ()));
@@ -123,7 +133,7 @@ public static DriveCommand turnTo(DriveSubsystem driveSubsystem, PoseEstimationS
123133 }
124134
125135 /**
126- * Constructs a {@code DriveCommand } for moving the robot toward the specified
136+ * Constructs a {@code Command } for moving the robot toward the specified
127137 * target position while ensuring that the robot is away from the target by the
128138 * specified distance.
129139 *
@@ -138,7 +148,7 @@ public static DriveCommand turnTo(DriveSubsystem driveSubsystem, PoseEstimationS
138148 * @return a {@code Commmand} for turning the robot to the specified target
139149 * position
140150 */
141- public static DriveCommand moveToward (DriveSubsystem driveSubsystem ,
151+ public static Command moveToward (DriveSubsystem driveSubsystem ,
142152 PoseEstimationSubsystem poseEstimationSubsystem , Translation2d targetPosition , double distanceToTarget ,
143153 double distanceTolerance , double angleTolerance ) {
144154 return moveToward (
@@ -147,28 +157,29 @@ public static DriveCommand moveToward(DriveSubsystem driveSubsystem,
147157 }
148158
149159 /**
150- * Constructs a {@code DriveCommand } for moving the robot toward the specified
160+ * Constructs a {@code Command } for moving the robot toward the specified
151161 * target position while ensuring that the robot is away from the target by the
152162 * specified distance.
153163 *
154164 * @param driveSubsystem the {@code DriveSubsystem} to use
155165 * @param poseEstimationSubsystem the {@code PoseEstimationSubsystem} to use
156166 * @param targetPositionSupplier a {@code Supplier<Pose2d>} that provides the
157167 * target position.
158- * This is used at the commencement of the {@code DriveCommand } (i.e.,
168+ * This is used at the commencement of the {@code Command } (i.e.,
159169 * when the scheduler begins to periodically execute the
160- * {@code DriveCommand })
170+ * {@code Command })
161171 * @param distanceToTarget the desired distance between the robot and the
162172 * target position
163173 * @param distanceTolerance the distance error in meters which is tolerable
164174 * @param angleTolerance the angle error in degrees which is tolerable
165175 * @return a {@code Commmand} for turning the robot to the specified target
166176 * position
167177 */
168- public static DriveCommand moveToward (DriveSubsystem driveSubsystem ,
178+ public static Command moveToward (DriveSubsystem driveSubsystem ,
169179 PoseEstimationSubsystem poseEstimationSubsystem , Supplier <Translation2d > targetPositionSupplier ,
170180 double distanceToTarget , double distanceTolerance , double angleTolerance ) {
171- return new AlignCommand (driveSubsystem , poseEstimationSubsystem ,
181+ return driveCommand (
182+ driveSubsystem , poseEstimationSubsystem ,
172183 () -> {
173184 var transform = poseEstimationSubsystem
174185 .transformationToward (targetPositionSupplier .get (), distanceToTarget );
@@ -178,7 +189,7 @@ public static DriveCommand moveToward(DriveSubsystem driveSubsystem,
178189 }
179190
180191 /**
181- * Constructs a {@code DriveCommand } for turning the robot to the specified
192+ * Constructs a {@code Command } for turning the robot to the specified
182193 * target.
183194 *
184195 * @param driveSubsystem the {@code DriveSubsystem} to use
@@ -192,7 +203,7 @@ public static DriveCommand moveToward(DriveSubsystem driveSubsystem,
192203 * @return a {@code Commmand} for turning the robot to the specified
193204 * target
194205 */
195- public static DriveCommand turnToClosestTag (DriveSubsystem driveSubsystem ,
206+ public static Command turnToClosestTag (DriveSubsystem driveSubsystem ,
196207 PoseEstimationSubsystem poseEstimationSubsystem , double angleOfCoverageInDegrees ,
197208 double distanceThresholdInMeters , double distanceTolerance , double angleTolerance ) {
198209 return turnTo (
@@ -202,7 +213,7 @@ public static DriveCommand turnToClosestTag(DriveSubsystem driveSubsystem,
202213 }
203214
204215 /**
205- * Constructs a {@code DriveCommand } for moving the robot to the specified
216+ * Constructs a {@code Command } for moving the robot to the specified
206217 * target.
207218 *
208219 * @param driveSubsystem the {@code DriveSubsystem} to use
@@ -212,13 +223,13 @@ public static DriveCommand turnToClosestTag(DriveSubsystem driveSubsystem,
212223 * @param distanceThresholdInMeters the maximum distance (in meters) within
213224 * which {@code AprilTag}s are considered
214225 * @param robotToTarget the {@code Pose2d} of the target relative to the
215- * {@code Pose2d} of the robot for the {@code DriveCommand } to finish
226+ * {@code Pose2d} of the robot for the {@code Command } to finish
216227 * @param distanceTolerance the distance error in meters which is tolerable
217228 * @param angleTolerance the angle error in degrees which is tolerable
218229 * @return a {@code Commmand} for moving the robot to the specified
219230 * target
220231 */
221- public static DriveCommand moveToClosestTag (DriveSubsystem driveSubsystem ,
232+ public static Command moveToClosestTag (DriveSubsystem driveSubsystem ,
222233 PoseEstimationSubsystem poseEstimationSubsystem , double angleOfCoverageInDegrees ,
223234 double distanceThresholdInMeters , Transform2d robotToTarget , double distanceTolerance ,
224235 double angleTolerance ) {
0 commit comments