99import java .util .Arrays ;
1010import java .util .LinkedList ;
1111import java .util .List ;
12+ import java .util .function .Supplier ;
1213
1314import edu .wpi .first .math .geometry .Pose2d ;
1415import edu .wpi .first .math .geometry .Rotation2d ;
@@ -129,14 +130,17 @@ distanceTolerance, angleTolerance, pose(0.0, 0, 0)).withTimeout(1),
129130 * describes how quickly the robot to move on the circle
130131 * @param distanceTolerance the distance error in meters which is tolerable
131132 * @param angleTolerance the angle error in degrees which is tolerable
132- * @param intermediateToleranceRatio the ratio to apply to the distance and
133- * angle tolerances for intermeidate target {@code Pose2d}s
133+ * @param intermediateDistanceTolerance the distance error in meters which is
134+ * tolerable for intermeidate target {@code Pose2d}s
135+ * @param intermediateAngleToleranceInDegrees the angle error in degrees which
136+ * is tolerable for intermeidate target {@code Pose2d}s
134137 * @param poseCount the number of {@code Pose2d}s on the circle
135138 *
136139 * @return a {@code Command} for moving the robot on a circle
137140 */
138141 public static Command moveOnOval (double radius , double initialAngularIncrement , double finalAngularIncrement ,
139- double distanceTolerance , double angleTolerance , double intermediateToleranceRatio , int poseCount ) {
142+ double distanceTolerance , double angleTolerance , double intermediateDistanceTolerance ,
143+ double intermediateAngleToleranceInDegrees , int poseCount ) {
140144 Rotation2d angle = Rotation2d .kZero ;
141145 var l = new LinkedList <Pose2d >();
142146 for (double i = 0 ; i < poseCount ; i ++) {
@@ -146,8 +150,8 @@ public static Command moveOnOval(double radius, double initialAngularIncrement,
146150 double angularVelocity = progress * finalAngularIncrement + (1 - progress ) * initialAngularIncrement ;
147151 angle = angle .plus (rotation (angularVelocity ));
148152 }
149- return new PathDriveCommand (m_driveSubsystem , distanceTolerance , angleTolerance , intermediateToleranceRatio ,
150- l .toArray (new Pose2d [0 ]));
153+ return new PathDriveCommand (m_driveSubsystem , distanceTolerance , angleTolerance , intermediateDistanceTolerance ,
154+ intermediateAngleToleranceInDegrees , l .toArray (new Pose2d [0 ]));
151155 }
152156
153157 /**
@@ -175,26 +179,27 @@ public static Command turnTowardTag(int tagID) {
175179 * @param tagID the ID of the {@code AprilTag}
176180 * @param distanceTolerance the distance error in meters which is tolerable
177181 * @param angleTolerance the angle error in degrees which is tolerable
178- * @param intermediateToleranceRatio the ratio to apply to the distance and
179- * angle tolerances for intermeidate target {@code Pose2d}s
180- * @param robotToTag the {@code Pose2d}s of the {@code AprilTag} relative to the
181- * center of the robot when the alignment is completed
182- * @param robotToTagReady the {@code Pose2d}s of the {@code AprilTag} relative
183- * to the center of the robot when the alignment ready step is completed
182+ * @param intermediateDistanceTolerance the distance error in meters which is
183+ * tolerable for intermeidate target {@code Pose2d}s
184+ * @param intermediateAngleToleranceInDegrees the angle error in degrees which
185+ * is tolerable for intermeidate target {@code Pose2d}s
186+ * @param robotToTagTransforms the {@code Pose2d}s of the {@code AprilTag}s
187+ * relative to the center of the robot to complete alignment
184188 *
185189 * @return a {@code Command} for aligning the robot to the specified
186190 * {@code AprilTag}
187191 */
188192 public static Command alignToTag (int tagID , double distanceTolerance , double angleTolerance ,
189- double intermediateToleranceRatio , Transform2d robotToTag , Transform2d robotToTagReady ) {
190- return new PathDriveCommand (m_driveSubsystem , distanceTolerance , angleTolerance , intermediateToleranceRatio ,
191- List .of (
192- () -> m_poseEstimationSubsystem
193- .odometryCentricPose (kFieldLayout .getTagPose (tagID ).get ().toPose2d ())
194- .plus (robotToTagReady ),
195- () -> m_poseEstimationSubsystem
196- .odometryCentricPose (kFieldLayout .getTagPose (tagID ).get ().toPose2d ())
197- .plus (robotToTag )));
193+ double intermediateDistanceTolerance , double intermediateAngleToleranceInDegrees ,
194+ List <Transform2d > robotToTagTransforms ) {
195+ return new PathDriveCommand (
196+ m_driveSubsystem , distanceTolerance , angleTolerance , intermediateDistanceTolerance ,
197+ intermediateAngleToleranceInDegrees , robotToTagTransforms
198+ .stream ().map (
199+ r -> (Supplier <Pose2d >) (() -> m_poseEstimationSubsystem
200+ .odometryCentricPose (kFieldLayout .getTagPose (tagID ).get ().toPose2d ())
201+ .plus (r )))
202+ .toList ());
198203 }
199204
200205 /**
@@ -203,8 +208,10 @@ public static Command alignToTag(int tagID, double distanceTolerance, double ang
203208 *
204209 * @param distanceTolerance the distance error in meters which is tolerable
205210 * @param angleTolerance the angle error in degrees which is tolerable
206- * @param intermediateToleranceRatio the ratio to apply to the distance and
207- * angle tolerances for intermeidate target {@code Pose2d}s
211+ * @param intermediateDistanceTolerance the distance error in meters which is
212+ * tolerable for intermeidate target {@code Pose2d}s
213+ * @param intermediateAngleToleranceInDegrees the angle error in degrees which
214+ * is tolerable for intermeidate target {@code Pose2d}s
208215 * @param robotToTag the {@code Pose2d}s of the {@code AprilTag} relative to the
209216 * center of the robot when the alignment is completed
210217 * @param robotToTagReady the {@code Pose2d}s of the {@code AprilTag} relative
@@ -215,10 +222,12 @@ public static Command alignToTag(int tagID, double distanceTolerance, double ang
215222 * {@code AprilTag}s
216223 */
217224 public static Command alignToTags (double distanceTolerance , double angleTolerance ,
218- double intermediateToleranceRatio , Transform2d robotToTag , Transform2d robotToTagReady , int ... tagIDs ) {
225+ double intermediateDistanceTolerance , double intermediateAngleToleranceInDegrees ,
226+ List <Transform2d > robotToTagTransforms , int ... tagIDs ) {
219227 List <Command > l = Arrays .stream (tagIDs ).mapToObj (
220228 i -> alignToTag (
221- i , distanceTolerance , angleTolerance , intermediateToleranceRatio , robotToTag , robotToTagReady ))
229+ i , distanceTolerance , angleTolerance , intermediateDistanceTolerance ,
230+ intermediateAngleToleranceInDegrees , robotToTagTransforms ))
222231 .toList ();
223232 return sequence (l .toArray (new Command [0 ]));
224233 }
0 commit comments