|
5 | 5 | package frc.robot.subsystems.swervedrive;
|
6 | 6 |
|
7 | 7 | import com.pathplanner.lib.auto.AutoBuilder;
|
| 8 | +import com.pathplanner.lib.path.PathConstraints; |
8 | 9 | import com.pathplanner.lib.path.PathPlannerPath;
|
9 | 10 | import com.pathplanner.lib.util.HolonomicPathFollowerConfig;
|
10 | 11 | import com.pathplanner.lib.util.PIDConstants;
|
@@ -147,6 +148,28 @@ public Command getAutonomousCommand(String pathName, boolean setOdomToStart)
|
147 | 148 | return AutoBuilder.followPath(path);
|
148 | 149 | }
|
149 | 150 |
|
| 151 | + /** |
| 152 | + * Use PathPlanner Path finding to go to a point on the field. |
| 153 | + * |
| 154 | + * @param pose Target {@link Pose2d} to go to. |
| 155 | + * @return PathFinding command |
| 156 | + */ |
| 157 | + public Command driveToPose(Pose2d pose) |
| 158 | + { |
| 159 | +// Create the constraints to use while pathfinding |
| 160 | + PathConstraints constraints = new PathConstraints( |
| 161 | + swerveDrive.getMaximumVelocity(), 4.0, |
| 162 | + swerveDrive.getMaximumAngularVelocity(), Units.degreesToRadians(720)); |
| 163 | + |
| 164 | +// Since AutoBuilder is configured, we can use it to build pathfinding commands |
| 165 | + return AutoBuilder.pathfindToPose( |
| 166 | + pose, |
| 167 | + constraints, |
| 168 | + 0.0, // Goal end velocity in meters/sec |
| 169 | + 0.0 // Rotation delay distance in meters. This is how far the robot should travel before attempting to rotate. |
| 170 | + ); |
| 171 | + } |
| 172 | + |
150 | 173 | /**
|
151 | 174 | * Command to drive the robot using translative values and heading as a setpoint.
|
152 | 175 | *
|
@@ -177,7 +200,7 @@ public Command driveCommand(DoubleSupplier translationX, DoubleSupplier translat
|
177 | 200 | *
|
178 | 201 | * @param translationX Translation in the X direction.
|
179 | 202 | * @param translationY Translation in the Y direction.
|
180 |
| - * @param rotation Rotation as a value between [-1, 1] converted to radians. |
| 203 | + * @param rotation Rotation as a value between [-1, 1] converted to radians. |
181 | 204 | * @return Drive command.
|
182 | 205 | */
|
183 | 206 | public Command simDriveCommand(DoubleSupplier translationX, DoubleSupplier translationY, DoubleSupplier rotation)
|
@@ -336,9 +359,8 @@ public void setMotorBrake(boolean brake)
|
336 | 359 | }
|
337 | 360 |
|
338 | 361 | /**
|
339 |
| - * Gets the current yaw angle of the robot, as reported by the swerve pose estimator in the underlying |
340 |
| - * drivebase. Note, this is not the raw gyro reading, this may be corrected from calls to |
341 |
| - * resetOdometry(). |
| 362 | + * Gets the current yaw angle of the robot, as reported by the swerve pose estimator in the underlying drivebase. |
| 363 | + * Note, this is not the raw gyro reading, this may be corrected from calls to resetOdometry(). |
342 | 364 | *
|
343 | 365 | * @return The yaw angle
|
344 | 366 | */
|
|
0 commit comments