Skip to content

Commit 999c010

Browse files
Added go to pose functionality.
Signed-off-by: thenetworkgrinch <[email protected]>
1 parent b26816b commit 999c010

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

simgui-ds.json

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
{
2+
"Keyboard 0 Settings": {
3+
"window": {
4+
"visible": true
5+
}
6+
},
27
"keyboardJoysticks": [
38
{
49
"axisConfig": [

src/main/java/frc/robot/RobotContainer.java

+9
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
package frc.robot;
66

77
import edu.wpi.first.math.MathUtil;
8+
import edu.wpi.first.math.geometry.Pose2d;
9+
import edu.wpi.first.math.geometry.Rotation2d;
10+
import edu.wpi.first.math.geometry.Translation2d;
811
import edu.wpi.first.wpilibj.Filesystem;
912
import edu.wpi.first.wpilibj.RobotBase;
1013
import edu.wpi.first.wpilibj.XboxController;
1114
import edu.wpi.first.wpilibj2.command.Command;
15+
import edu.wpi.first.wpilibj2.command.Commands;
1216
import edu.wpi.first.wpilibj2.command.InstantCommand;
1317
import edu.wpi.first.wpilibj2.command.button.CommandJoystick;
1418
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
@@ -100,6 +104,11 @@ private void configureBindings()
100104

101105
new JoystickButton(driverXbox, 1).onTrue((new InstantCommand(drivebase::zeroGyro)));
102106
new JoystickButton(driverXbox, 3).onTrue(new InstantCommand(drivebase::addFakeVisionReading));
107+
new JoystickButton(driverXbox,
108+
2).whileTrue(
109+
Commands.deferredProxy(() -> drivebase.driveToPose(
110+
new Pose2d(new Translation2d(4, 4), Rotation2d.fromDegrees(0)))
111+
));
103112
// new JoystickButton(driverXbox, 3).whileTrue(new RepeatCommand(new InstantCommand(drivebase::lock, drivebase)));
104113
}
105114

src/main/java/frc/robot/subsystems/swervedrive/SwerveSubsystem.java

+26-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package frc.robot.subsystems.swervedrive;
66

77
import com.pathplanner.lib.auto.AutoBuilder;
8+
import com.pathplanner.lib.path.PathConstraints;
89
import com.pathplanner.lib.path.PathPlannerPath;
910
import com.pathplanner.lib.util.HolonomicPathFollowerConfig;
1011
import com.pathplanner.lib.util.PIDConstants;
@@ -147,6 +148,28 @@ public Command getAutonomousCommand(String pathName, boolean setOdomToStart)
147148
return AutoBuilder.followPath(path);
148149
}
149150

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+
150173
/**
151174
* Command to drive the robot using translative values and heading as a setpoint.
152175
*
@@ -177,7 +200,7 @@ public Command driveCommand(DoubleSupplier translationX, DoubleSupplier translat
177200
*
178201
* @param translationX Translation in the X direction.
179202
* @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.
181204
* @return Drive command.
182205
*/
183206
public Command simDriveCommand(DoubleSupplier translationX, DoubleSupplier translationY, DoubleSupplier rotation)
@@ -336,9 +359,8 @@ public void setMotorBrake(boolean brake)
336359
}
337360

338361
/**
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().
342364
*
343365
* @return The yaw angle
344366
*/

0 commit comments

Comments
 (0)