Skip to content

Commit 5c73868

Browse files
AudreyZ19edreed
authored andcommitted
Integrate PathPlannerLib and add Example Auto
1 parent 06d0e11 commit 5c73868

File tree

7 files changed

+145
-1
lines changed

7 files changed

+145
-1
lines changed

gradlew

100644100755
File mode changed.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"version": 1.0,
3+
"startingPose": null,
4+
"command": {
5+
"type": "sequential",
6+
"data": {
7+
"commands": [
8+
{
9+
"type": "path",
10+
"data": {
11+
"pathName": "Example Path"
12+
}
13+
}
14+
]
15+
}
16+
},
17+
"folder": null,
18+
"choreoAuto": false
19+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"version": 1.0,
3+
"waypoints": [
4+
{
5+
"anchor": {
6+
"x": 2.8394326015162217,
7+
"y": 4.188891299550061
8+
},
9+
"prevControl": null,
10+
"nextControl": {
11+
"x": 3.6904589462008053,
12+
"y": 4.940665233394327
13+
},
14+
"isLocked": false,
15+
"linkedName": null
16+
},
17+
{
18+
"anchor": {
19+
"x": 5.78231056307781,
20+
"y": 4.370352406171121
21+
},
22+
"prevControl": {
23+
"x": 4.860483855805502,
24+
"y": 5.074315409542372
25+
},
26+
"nextControl": {
27+
"x": 7.141587777045881,
28+
"y": 3.3323255596822756
29+
},
30+
"isLocked": false,
31+
"linkedName": null
32+
},
33+
{
34+
"anchor": {
35+
"x": 4.085944870919574,
36+
"y": 0.8637961970806275
37+
},
38+
"prevControl": {
39+
"x": 6.4054472640776625,
40+
"y": 0.7463117434053165
41+
},
42+
"nextControl": {
43+
"x": 1.7664424777614869,
44+
"y": 0.9812806507559387
45+
},
46+
"isLocked": false,
47+
"linkedName": null
48+
},
49+
{
50+
"anchor": {
51+
"x": 2.8394326015162217,
52+
"y": 4.188891299550061
53+
},
54+
"prevControl": {
55+
"x": 2.3424992022139515,
56+
"y": 3.371763469412239
57+
},
58+
"nextControl": null,
59+
"isLocked": false,
60+
"linkedName": null
61+
}
62+
],
63+
"rotationTargets": [],
64+
"constraintZones": [],
65+
"eventMarkers": [],
66+
"globalConstraints": {
67+
"maxVelocity": 3.0,
68+
"maxAcceleration": 3.0,
69+
"maxAngularVelocity": 540.0,
70+
"maxAngularAcceleration": 720.0
71+
},
72+
"goalEndState": {
73+
"velocity": 0,
74+
"rotation": 0,
75+
"rotateFast": false
76+
},
77+
"reversed": false,
78+
"folder": null,
79+
"previewStartingState": null,
80+
"useDefaultConstraints": false
81+
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
package frc.robot;
66

7+
import com.pathplanner.lib.auto.AutoBuilder;
8+
import com.pathplanner.lib.util.HolonomicPathFollowerConfig;
9+
import com.pathplanner.lib.util.PIDConstants;
10+
import com.pathplanner.lib.util.ReplanningConfig;
11+
712
import edu.wpi.first.wpilibj2.command.Command;
813
import edu.wpi.first.wpilibj2.command.Commands;
914
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
@@ -33,6 +38,20 @@ public class RobotContainer {
3338
/** The container for the robot. Contains subsystems, OI devices, and commands. */
3439
public RobotContainer() {
3540
m_driveTrain.setDefaultCommand(new DriveUsingController(m_driveTrain, m_driverController));
41+
42+
AutoBuilder.configureHolonomic(
43+
m_driveTrain::getPosition,
44+
m_driveTrain::resetPosition,
45+
m_driveTrain::getChassisSpeeds,
46+
m_driveTrain::setChassisSpeeds,
47+
new HolonomicPathFollowerConfig(
48+
new PIDConstants(1.0, 0, 0),
49+
new PIDConstants(1.0,0,0),
50+
m_driveTrain.getMaxSpeed(),
51+
m_driveTrain.getWheelBaseRadius(),
52+
new ReplanningConfig()
53+
),
54+
m_driveTrain);
3655

3756
// Configure the trigger bindings
3857
configureBindings();

src/main/java/frc/robot/commands/Autos.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
package frc.robot.commands;
66

77
import frc.robot.subsystems.ExampleSubsystem;
8+
9+
import com.pathplanner.lib.commands.PathPlannerAuto;
10+
811
import edu.wpi.first.wpilibj2.command.Command;
912
import edu.wpi.first.wpilibj2.command.Commands;
1013

1114
public final class Autos {
1215
/** Example static factory for an autonomous command. */
1316
public static Command exampleAuto(ExampleSubsystem subsystem) {
14-
return Commands.sequence(subsystem.exampleMethodCommand(), new ExampleCommand(subsystem));
17+
return new PathPlannerAuto("Example Auto");
1518
}
1619

1720
private Autos() {

src/main/java/frc/robot/parameters/SwerveDriveParameters.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ public double getMaxRotationalSpeed() {
261261
return this.maxRotationalSpeed;
262262
}
263263

264+
264265
/**
265266
* Returns the maximum rotational acceleration of the robot in rad/s^2.
266267
*
@@ -270,6 +271,18 @@ public double getMaxRotationalAcceleration() {
270271
return this.maxRotationalAcceleration;
271272
}
272273

274+
/**
275+
* Return the wheel base radius in meters.
276+
*
277+
* @return The wheel base radius in meters.
278+
*/
279+
public double getWheelBaseRadius(){
280+
double halfWheelDistanceX = wheelDistanceX/2;
281+
double halfWheelDistanceY = wheelDistanceY/2;
282+
283+
return Math.sqrt(halfWheelDistanceX*halfWheelDistanceX +halfWheelDistanceY*halfWheelDistanceY);
284+
}
285+
273286
/**
274287
* Returns a {@link TrapezoidProfile.Constraints} object used to enforce
275288
* velocity and acceleration constraints on the {@link ProfilePIDController}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,15 @@ public TrapezoidProfile.Constraints getRotationalConstraints() {
286286
return PARAMETERS.getRotationalConstraints();
287287
}
288288

289+
/**
290+
* Return the wheel base radius in meters.
291+
*
292+
* @return The wheel base radius in meters.
293+
*/
294+
public double getWheelBaseRadius(){
295+
return PARAMETERS.getWheelBaseRadius();
296+
}
297+
289298
/**
290299
* Creates a HolonomicDriveController for the subsystem.
291300
*

0 commit comments

Comments
 (0)