1414
1515/**
1616 * This {@code DriveCommand2Controllers} aims to maneuver the robot to a certain
17- * {@code Pose2d}.
18- * It utilizes two {@code ProfiledPIDController}s to precisely control the
19- * robot in the x, y, and yaw dimensions.
17+ * {@code Pose2d}. It utilizes two {@code ProfiledPIDController}s to precisely
18+ * control the robot in the x, y, and yaw dimensions.
2019 *
2120 * @author Jeong-Hyon Hwang (jhhbrown@gmail.com)
2221 * @author Andrew Hwang (u.andrew.h@gmail.com)
@@ -72,13 +71,6 @@ public class DriveCommand2Controllers extends Command {
7271 */
7372 protected double m_angleTolerance ;
7473
75- /**
76- * A boolean indicating whether or not the target needs to be determined
77- * continuously or only once at the commencement of the
78- * {@code DriveCommand2Controllers}.
79- */
80- protected boolean m_continuousTargeting ;
81-
8274 /**
8375 * Constructs a new {@code DriveCommand2Controllers} whose purpose is to move
8476 * the
@@ -91,7 +83,7 @@ public class DriveCommand2Controllers extends Command {
9183 */
9284 public DriveCommand2Controllers (DriveSubsystem driveSubsystem , Pose2d targetPose , double distanceTolerance ,
9385 double angleToleranceInDegrees ) {
94- this (driveSubsystem , () -> driveSubsystem .getPose (), () -> targetPose , false , distanceTolerance ,
86+ this (driveSubsystem , () -> driveSubsystem .getPose (), () -> targetPose , distanceTolerance ,
9587 angleToleranceInDegrees );
9688 }
9789
@@ -106,16 +98,12 @@ public DriveCommand2Controllers(DriveSubsystem driveSubsystem, Pose2d targetPose
10698 * {@code DriveCommand2Controllers} (i.e., when the scheduler
10799 * begins to periodically execute this
108100 * {@code DriveCommand2Controllers})
109- * @param continuousTargeting a boolean value indicating whether or not the
110- * targetPoseSupplier needs to be used continuously or only once at the
111- * commencement of the {@code DriveCommand2Controllers}.
112101 * @param distanceTolerance the distance error in meters which is tolerable
113102 * @param angleToleranceInDegrees the angle error in degrees which is tolerable
114103 */
115104 public DriveCommand2Controllers (DriveSubsystem driveSubsystem , Supplier <Pose2d > targetPoseSupplier ,
116- boolean continuousTargeting , double distanceTolerance , double angleToleranceInDegrees ) {
117- this (driveSubsystem , () -> driveSubsystem .getPose (), targetPoseSupplier , continuousTargeting ,
118- distanceTolerance ,
105+ double distanceTolerance , double angleToleranceInDegrees ) {
106+ this (driveSubsystem , () -> driveSubsystem .getPose (), targetPoseSupplier , distanceTolerance ,
119107 angleToleranceInDegrees );
120108 }
121109
@@ -133,16 +121,12 @@ public DriveCommand2Controllers(DriveSubsystem driveSubsystem, Supplier<Pose2d>
133121 * {@code DriveCommand2Controllers} (i.e., when the scheduler
134122 * begins to periodically execute this
135123 * {@code DriveCommand2Controllers})
136- * @param continuousTargeting a boolean value indicating whether or not the
137- * targetPoseSupplier needs to be used continuously or only once at the
138- * commencement of the {@code DriveCommand2Controllers}.
139124 * @param distanceTolerance the distance error in meters which is tolerable
140125 * @param angleToleranceInDegrees the angle error in degrees which is tolerable
141126 */
142127 public DriveCommand2Controllers (DriveSubsystem driveSubsystem , Supplier <Pose2d > poseSupplier ,
143- Supplier <Pose2d > targetPoseSupplier , boolean continuousTargeting , double distanceTolerance ,
144- double angleToleranceInDegrees ) {
145- this (driveSubsystem , poseSupplier , targetPoseSupplier , continuousTargeting , distanceTolerance ,
128+ Supplier <Pose2d > targetPoseSupplier , double distanceTolerance , double angleToleranceInDegrees ) {
129+ this (driveSubsystem , poseSupplier , targetPoseSupplier , distanceTolerance ,
146130 angleToleranceInDegrees ,
147131 new ProfiledPIDController (kDriveP , kDriveI , kDriveD ,
148132 new TrapezoidProfile .Constraints (kDriveMaxSpeed , kDriveMaxAcceleration )),
@@ -165,9 +149,6 @@ public DriveCommand2Controllers(DriveSubsystem driveSubsystem, Supplier<Pose2d>
165149 * {@code DriveCommand2Controllers} (i.e., when the scheduler
166150 * begins to periodically execute this
167151 * {@code DriveCommand2Controllers})
168- * @param continuousTargeting a boolean value indicating whether or not the
169- * targetPoseSupplier needs to be used continuously or only once at the
170- * commencement of the {@code DriveCommand2Controllers}
171152 * @param distanceTolerance the distance error in meters which is tolerable
172153 * @param angleToleranceInDegrees the angle error in degrees which is tolerable
173154 * @param controllerXY the {@code ProfiledPIDController} for controlling the
@@ -177,12 +158,11 @@ public DriveCommand2Controllers(DriveSubsystem driveSubsystem, Supplier<Pose2d>
177158 *
178159 */
179160 public DriveCommand2Controllers (DriveSubsystem driveSubsystem , Supplier <Pose2d > poseSupplier ,
180- Supplier <Pose2d > targetPoseSupplier , boolean continuousTargeting , double distanceTolerance ,
161+ Supplier <Pose2d > targetPoseSupplier , double distanceTolerance ,
181162 double angleToleranceInDegrees , ProfiledPIDController controllerXY , ProfiledPIDController controllerYaw ) {
182163 m_driveSubsystem = driveSubsystem ;
183164 m_poseSupplier = poseSupplier ;
184165 m_targetPoseSupplier = targetPoseSupplier ;
185- m_continuousTargeting = continuousTargeting ;
186166 m_distanceTolerance = distanceTolerance ;
187167 m_angleTolerance = Math .toRadians (angleToleranceInDegrees );
188168 m_controllerXY = controllerXY ;
@@ -228,22 +208,17 @@ public void execute() {
228208 */
229209 public ChassisSpeeds chassisSpeeds () {
230210 var currentPose = m_poseSupplier .get ();
231- if (m_continuousTargeting )
232- try {
233- m_targetPose = m_targetPoseSupplier .get ();
234- } catch (Exception e ) {
235- // e.printStackTrace();
236- }
237211 Translation2d current2target = m_targetPose .getTranslation ()
238212 .minus (currentPose .getTranslation ());
239213 double velocityX = 0 , velocityY = 0 ;
240- double distance = current2target . getNorm ();
241- double speed = Math . abs ( m_controllerXY . calculate ( distance , 0 ) );
242- if ( distance > 0 ) {
214+ try {
215+ double distance = current2target . getNorm ( );
216+ double speed = Math . abs ( m_controllerXY . calculate ( distance , 0 ));
243217 speed = applyThreshold (speed , kDriveMinSpeed );
244218 var angle = current2target .getAngle ();
245219 velocityX = speed * angle .getCos ();
246220 velocityY = speed * angle .getSin ();
221+ } catch (Exception e ) {
247222 }
248223 double angularVelocityRadiansPerSecond = m_controllerYaw
249224 .calculate (currentPose .getRotation ().getRadians (), m_targetPose .getRotation ().getRadians ());
0 commit comments