Skip to content

Java Example: Create a Path On‐the‐fly

Michael Jansen edited this page Oct 13, 2023 · 3 revisions

You can create a PathPlannerPath on-the-fly using the available constructors, however, there is a simplified constructor and a helper method available that makes doing so a lot easier.

// Create a list of bezier points from poses. Each pose represents one waypoint. 
// The rotation component of the pose should be the direction of travel. Do not use holonomic rotation.
List<Translation2d> bezierPoints = PathPlannerPath.bezierFromPoses(
    new Pose2d(1.0, 1.0, Rotation2d.fromDegrees(0)),
    new Pose2d(3.0, 1.0, Rotation2d.fromDegrees(0)),
    new Pose2d(5.0, 3.0, Rotation2d.fromDegrees(90))
);

// Create the path using the bezier points created above
PathPlannerPath path = new PathPlannerPath(
    bezierPoints,
    new PathConstraints(3.0, 3.0, 2 * Math.PI, 4 * Math.PI), // The constraints for this path. If using a differential drivetrain, the angular constraints have no effect.
    new GoalEndState(0.0, Rotation2d.fromDegrees(-90)) // Goal end state. You can set a holonomic rotation here. If using a differential drivetrain, the rotation will have no effect.
);
Clone this wiki locally