### Configure Build Installation Rules Source: https://github.com/mjansen4857/pathplanner/blob/main/windows/CMakeLists.txt Defines the installation process for the application, including the executable, Flutter ICU data, and native assets. It ensures that all necessary files are bundled into the output directory for deployment. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### PathPlannerAuto Class Usage Source: https://github.com/mjansen4857/pathplanner/wiki/Java-Example:-Path-Groups Demonstrates how to use the PathPlannerAuto class to get a path group and the starting pose from an auto file. ```APIDOC ## PathPlannerAuto Class Usage ### Description This section details how to utilize the `PathPlannerAuto` class to extract path data and starting poses from autos generated by PathPlanner. It's recommended to use `AutoBuilder` and `PathPlannerAuto` for a streamlined auto creation process. ### Method N/A (This is a class usage example, not an API endpoint) ### Endpoint N/A ### Parameters N/A ### Request Example ```java // Use the PathPlannerAuto class to get a path group from an auto List pathGroup = PathPlannerAuto.getPathGroupFromAutoFile("Example Auto"); // You can also get the starting pose from the auto. Only call this if the auto actually has a starting pose. Pose2d startingPose = PathPlannerAuto.getStartingPoseFromAutoFile("Example Auto"); ``` ### Response #### Success Response (N/A) N/A #### Response Example N/A ``` -------------------------------- ### Load Autonomous Command with PathPlannerAuto Source: https://github.com/mjansen4857/pathplanner/blob/main/Writerside/topics/pplib-Build-an-Auto.md Demonstrates how to load an autonomous command using PathPlannerAuto. It is recommended to load autos when the code starts, not when they are needed, to avoid delays. This example shows loading within the getAutonomousCommand function for simplicity. ```Java public class RobotContainer { // ... public Command getAutonomousCommand() { // This method loads the auto when it is called, however, it is recommended // to first load your paths/autos when code starts, then return the // pre-loaded auto/path return new PathPlannerAuto("Example Auto"); } } ``` ```C++ #include using namespace pathplanner; frc2::CommandPtr RobotContainer::getAutonomousCommand(){ // This method loads the auto when it is called, however, it is recommended // to first load your paths/autos when code starts, then return the // pre-loaded auto/path return PathPlannerAuto("Example Auto").ToPtr(); } ``` ```Python from pathplannerlib.auto import PathPlannerAuto class RobotContainer: def getAutonomousCommand(): # This method loads the auto when it is called, however, it is recommended # to first load your paths/autos when code starts, then return the # pre-loaded auto/path return PathPlannerAuto('Example Auto') ``` -------------------------------- ### Configure AutoBuilder with PPLTVController Source: https://github.com/mjansen4857/pathplanner/blob/main/Writerside/topics/pplib-Build-an-Auto.md This setup demonstrates how to initialize the AutoBuilder for a differential drive subsystem using the PPLTVController for path following. ```APIDOC ## AutoBuilder Configuration (Differential Drive) ### Description Configures the AutoBuilder to use the PPLTVController for differential drive trains. This requires providing pose suppliers, odometry reset methods, and chassis speed suppliers. ### Method N/A (Library Configuration Method) ### Parameters #### Path Parameters - **config** (RobotConfig) - Required - Robot configuration loaded from GUI settings. - **controller** (PPLTVController) - Required - The LTV controller instance with a specified lookahead time (e.g., 0.02s). ### Request Example // Java Example AutoBuilder.configure( this::getPose, this::resetPose, this::getRobotRelativeSpeeds, (speeds, feedforwards) -> driveRobotRelative(speeds), new PPLTVController(0.02), config, () -> DriverStation.getAlliance().orElse(Alliance.Blue) == Alliance.Red, this ); ``` -------------------------------- ### Configure Application Installation and Bundling Source: https://github.com/mjansen4857/pathplanner/blob/main/linux/CMakeLists.txt These rules define how the application executable, Flutter assets, and required libraries are installed into a bundle directory. It includes logic to clean the bundle directory and copy necessary files for a relocatable distribution. ```cmake set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Manually Create Path Following Commands - LTV Source: https://github.com/mjansen4857/pathplanner/wiki/Python-Example:-Follow-a-Single-Path This section provides an example of manually creating a path following command for a Linear Time-Varying (LTV) drive system. It uses `FollowPathLTV` wrapped in `FollowPathWithEvents` to ensure event markers are triggered. ```APIDOC ## Manually Create Path Following Commands - LTV ### Description This section provides an example of manually creating a path following command for a Linear Time-Varying (LTV) drive system. It uses `FollowPathLTV` wrapped in `FollowPathWithEvents` to ensure event markers are triggered. ### Method `FollowPathWithEvents(FollowPathLTV(...), path, getPose)` ### Endpoint N/A (This is a library function, not an API endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from pathplannerlib.path import PathPlannerPath from pathplannerlib.commands import FollowPathWithEvents, FollowPathLTV from pathplannerlib.config import ReplanningConfig, PIDConstants # Assuming this is a method in your drive subsystem def followPathCommand(pathName: str): path = PathPlannerPath.fromPathFile(pathName) # You must wrap the path following command in a FollowPathWithEvents command in order for event markers to work return FollowPathWithEvents( FollowPathLTV( path, self.getPose, # Robot pose supplier self.getCurrentSpeeds, # Current ChassisSpeeds supplier self.drive, # Method that will drive the robot given ChassisSpeeds (0.0625, 0.125, 2.0), # qelems/error tolerances (1.0, 2.0), # relems/control effort 0.02, # Robot control loop period in seconds. Default is 0.02 ReplanningConfig(), # Default path replanning config. See the API for the options here self # Reference to this subsystem to set requirements ), path, # FollowPathWithEvents also requires the path self.getPose # FollowPathWithEvents also requires the robot pose supplier ) ``` ### Response #### Success Response (200) N/A (This is a library function, not an API endpoint) #### Response Example N/A ``` -------------------------------- ### On-the-fly Path Generation (C++) Source: https://github.com/mjansen4857/pathplanner/wiki/PathPlannerLib:-Cpp-Usage Illustrates generating robot paths dynamically using the generatePath method without pre-defined .path files. Supports simple paths, paths with holonomic rotation, and paths with specified starting velocities and intermediate points. ```C++ #include #include #include using namespace pathplanner; // Simple path without holonomic rotation. Stationary start/end. Max velocity of 4 m/s and max accel of 3 m/s^2 PathPlannerTrajectory traj1 = PathPlanner::generatePath( PathConstraints(4_mps, 3_mps_sq), PathPoint(frc::Translation2d(1_m, 1_m), frc::Rotation2d(0_deg)), // position, heading PathPoint(frc::Translation2d(3_m, 3_m), frc::Rotation2d(45_deg)) // position, heading ); // Simple path with holonomic rotation. Stationary start/end. Max velocity of 4 m/s and max accel of 3 m/s^2 PathPlannerTrajectory traj2 = PathPlanner::generatePath( PathConstraints(4_mps, 3_mps_sq), PathPoint(frc::Translation2d(1_m, 1_m), frc::Rotation2d(0_deg), frc::Rotation2d(0_deg)), // position, heading(direction of travel), holonomic rotation PathPoint(frc::Translation2d(3_m, 3_m), frc::Rotation2d(45_deg), frc::Rotation2d(-90_deg) // position, heading(direction of travel) holonomic rotation ); // More complex path with holonomic rotation. Non-zero starting velocity of 2 m/s. Max velocity of 4 m/s and max accel of 3 m/s^2 PathPlannerTrajectory traj2 = PathPlanner::generatePath( PathConstraints(4_mps, 3_mps_sq), PathPoint(frc::Translation2d(1_m, 1_m), frc::Rotation2d(0_deg), frc::Rotation2d(0_deg), 2_mps), // position, heading(direction of travel), holonomic rotation, velocity override PathPoint(frc::Translation2d(3_m, 3_m), frc::Rotation2d(45_deg), frc::Rotation2d(-90_deg) // position, heading(direction of travel), holonomic rotation { PathPoint(frc::Translation2d(5_m, 3_m), frc::Rotation2d(0_deg), frc::Rotation2d(-30_deg)) // position, heading(direction of travel), holonomic rotation } ); ``` -------------------------------- ### Manually Create Path Following Commands - Ramsete Source: https://github.com/mjansen4857/pathplanner/wiki/Python-Example:-Follow-a-Single-Path This section provides an example of manually creating a path following command for a differential drive (Ramsete) system. It uses `FollowPathRamsete` wrapped in `FollowPathWithEvents` to ensure event markers are triggered. ```APIDOC ## Manually Create Path Following Commands - Ramsete ### Description This section provides an example of manually creating a path following command for a differential drive (Ramsete) system. It uses `FollowPathRamsete` wrapped in `FollowPathWithEvents` to ensure event markers are triggered. ### Method `FollowPathWithEvents(FollowPathRamsete(...), path, getPose)` ### Endpoint N/A (This is a library function, not an API endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from pathplannerlib.path import PathPlannerPath from pathplannerlib.commands import FollowPathWithEvents, FollowPathRamsete from pathplannerlib.config import ReplanningConfig, PIDConstants # Assuming this is a method in your drive subsystem def followPathCommand(pathName: str): path = PathPlannerPath.fromPathFile(pathName) # You must wrap the path following command in a FollowPathWithEvents command in order for event markers to work return FollowPathWithEvents( FollowPathRamsete( path, self.getPose, # Robot pose supplier self.getCurrentSpeeds, # Current ChassisSpeeds supplier self.drive, # Method that will drive the robot given ChassisSpeeds ReplanningConfig(), # Default path replanning config. See the API for the options here self # Reference to this subsystem to set requirements ), path, # FollowPathWithEvents also requires the path self.getPose # FollowPathWithEvents also requires the robot pose supplier ) ``` ### Response #### Success Response (200) N/A (This is a library function, not an API endpoint) #### Response Example N/A ``` -------------------------------- ### Manually Create Path Following Commands - Holonomic Source: https://github.com/mjansen4857/pathplanner/wiki/Python-Example:-Follow-a-Single-Path This section provides an example of manually creating a path following command for a holonomic drive system. It uses `FollowPathHolonomic` wrapped in `FollowPathWithEvents` to ensure event markers are triggered. ```APIDOC ## Manually Create Path Following Commands - Holonomic ### Description This section provides an example of manually creating a path following command for a holonomic drive system. It uses `FollowPathHolonomic` wrapped in `FollowPathWithEvents` to ensure event markers are triggered. ### Method `FollowPathWithEvents(FollowPathHolonomic(...), path, getPose)` ### Endpoint N/A (This is a library function, not an API endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from pathplannerlib.path import PathPlannerPath from pathplannerlib.commands import FollowPathWithEvents, FollowPathHolonomic from pathplannerlib.config import HolonomicPathFollowerConfig, ReplanningConfig, PIDConstants # Assuming this is a method in your drive subsystem def followPathCommand(pathName: str): path = PathPlannerPath.fromPathFile(pathName) # You must wrap the path following command in a FollowPathWithEvents command in order for event markers to work return FollowPathWithEvents( FollowPathHolonomic( path, self.getPose, # Robot pose supplier self.getRobotRelativeSpeeds, # ChassisSpeeds supplier. MUST BE ROBOT RELATIVE self.driveRobotRelative, # Method that will drive the robot given ROBOT RELATIVE ChassisSpeeds HolonomicPathFollowerConfig( # HolonomicPathFollowerConfig, this should likely live in your Constants class PIDConstants(5.0, 0.0, 0.0), # Translation PID constants PIDConstants(5.0, 0.0, 0.0), # Rotation PID constants 4.5, # Max module speed, in m/s 0.4, # Drive base radius in meters. Distance from robot center to furthest module. ReplanningConfig() # Default path replanning config. See the API for the options here ), self # Reference to this subsystem to set requirements ), path, # FollowPathWithEvents also requires the path self.getPose # FollowPathWithEvents also requires the robot pose supplier ) ``` ### Response #### Success Response (200) N/A (This is a library function, not an API endpoint) #### Response Example N/A ``` -------------------------------- ### Pathfind to Pose using AutoBuilder (C++) Source: https://github.com/mjansen4857/pathplanner/wiki/Cpp-Example:-Automatic-Pathfinding This snippet demonstrates how to use AutoBuilder to create a command that pathfinds a holonomic drivetrain to a target pose. It requires a navgrid.json file for obstacle avoidance and defines path constraints for movement. The command calculates the shortest path and does not offer control over the robot's heading at the start or end points. ```C++ #include using namespace pathplanner; // Since we are using a holonomic drivetrain, the rotation component of this pose // represents the goal holonomic rotation frc::Pose2d targetPose = frc::Pose2d(10_m, 5_m, frc::Rotation2d(180_deg)); // Create the constraints to use while pathfinding PathConstraints constraints = PathConstraints( 3.0_mps, 4.0_mps_sq, 540_deg_per_s, 720_deg_per_s); // Since AutoBuilder is configured, we can use it to build pathfinding commands frc2::CommandPtr pathfindingCommand = AutoBuilder::pathfindToPose( targetPose, constraints, 0.0_mps, // Goal end velocity in meters/sec 0.0_m // Rotation delay distance in meters. This is how far the robot should travel before attempting to rotate. ).ToPtr(); ``` -------------------------------- ### Load and Sample a Basic Path in C++ Source: https://github.com/mjansen4857/pathplanner/wiki/PathPlannerLib:-Cpp-Usage Demonstrates how to load a path from a file and sample its state at a specific time. This function utilizes the WPILib Units Library for handling units like meters per second and meters per second squared. It requires the 'pathplanner/lib/PathPlanner.h' header. ```C++ #include using namespace pathplanner; // This will load the file "Example Path.path" and generate it with a max velocity of 4 m/s and a max acceleration of 3 m/s^2 PathPlannerTrajectory examplePath = PathPlanner::loadPath("Example Path", PathConstraints(4_mps, 3_mps_sq)); // Sample the state of the path at 1.2 seconds PathPlannerTrajectory::PathPlannerState exampleState = examplePath.sample(1.2_s); ``` -------------------------------- ### Load and Sample Basic Path in Java Source: https://github.com/mjansen4857/pathplanner/wiki/PathPlannerLib:-Java-Usage Demonstrates loading a path from a file and sampling its state at a specific time. This path can be used as a drop-in replacement for WPILib trajectories. ```Java PathPlannerTrajectory examplePath = PathPlanner.loadPath("Example Path", new PathConstraints(4, 3)); PathPlannerState exampleState = (PathPlannerState) examplePath.sample(1.2); System.out.println(exampleState.velocityMetersPerSecond); ``` -------------------------------- ### Get Path Group and Starting Pose from PathPlanner Auto (Python) Source: https://github.com/mjansen4857/pathplanner/wiki/Python-Example:-Path-Groups Demonstrates how to retrieve a path group and the starting pose from an autonomous routine file using the PathPlannerAuto class in Python. This is useful for integrating PathPlanner autos into your robot code, especially when mimicking older path group functionalities. ```Python from pathplannerlib.auto import PathPlannerAuto # Use the PathPlannerAuto class to get a path group from an auto pathGroup = PathPlannerAuto.getPathGroupFromAutoFile('Example Auto'); # You can also get the starting pose from the auto. Only call this if the auto actually has a starting pose. startingPose = PathPlannerAuto.getStartingPoseFromAutoFile('Example Auto'); ``` -------------------------------- ### Retrieve Path Group from Auto File (Java) Source: https://github.com/mjansen4857/pathplanner/wiki/Java-Example:-Path-Groups This Java code snippet demonstrates how to use the PathPlannerAuto class to retrieve a list of PathPlannerPath objects that form a path group from a specified auto file. It also shows how to get the starting pose of the auto, if available. Ensure the auto file exists and has a starting pose if calling the latter method. ```Java List pathGroup = PathPlannerAuto.getPathGroupFromAutoFile("Example Auto"); Pose2d startingPose = PathPlannerAuto.getStartingPoseFromAutoFile("Example Auto"); ``` -------------------------------- ### Execute Path with Event Markers in Java Source: https://github.com/mjansen4857/pathplanner/wiki/PathPlannerLib:-Java-Usage Demonstrates how to load a pre-defined path and wrap it in a FollowPathWithEvents command. This allows the robot to trigger specific actions, such as printing to the console or activating an intake, when passing specific markers. ```Java PathPlannerTrajectory examplePath = PathPlanner.loadPath("Example Path", new PathConstrains(4, 3)); HashMap eventMap = new HashMap<>(); eventMap.put("marker1", new PrintCommand("Passed marker 1")); eventMap.put("intakeDown", new IntakeDown()); FollowPathWithEvents command = new FollowPathWithEvents( getPathFollowingCommand(examplePath), examplePath.getMarkers(), eventMap ); ``` -------------------------------- ### Get Path Group and Starting Pose from PathPlanner Auto (C++) Source: https://github.com/mjansen4857/pathplanner/wiki/Cpp-Example:-Path-Groups This snippet demonstrates how to use the PathPlannerAuto class in C++ to extract a path group and the starting pose from an autonomous routine file created in PathPlanner. Ensure the auto file exists and contains the relevant data. This method is useful for custom auto routines not fully built by AutoBuilder. ```C++ #include using namespace pathplanner; // Use the PathPlannerAuto class to get a path group from an auto auto pathGroup = PathPlannerAuto::getPathGroupFromAutoFile("Example Auto"); // You can also get the starting pose from the auto. Only call this if the auto actually has a starting pose. frc::Pose2d startingPose = PathPlannerAuto::getStartingPoseFromAutoFile("Example Auto"); ``` -------------------------------- ### Warmup Commands Source: https://context7.com/mjansen4857/pathplanner/llms.txt Run warmup commands at startup to reduce first-run latency for path following and pathfinding. ```APIDOC ## Java Warmup Commands - Reduce First-Run Latency ### Description Run warmup commands at startup to prevent delays when running path following for the first time. ### Method ```java public void robotInit() { // All other robot initialization... // Warm up path following (run after AutoBuilder configured) FollowPathCommand.warmupCommand().schedule(); // Warm up pathfinding (run after pathfinder configured) PathfindingCommand.warmupCommand().schedule(); } ``` ``` -------------------------------- ### Initialize and Drive Swerve Subsystem with Pathplannerlib (Python) Source: https://github.com/mjansen4857/pathplanner/blob/main/Writerside/topics/pplib-Swerve-Setpoint-Generator.md Demonstrates how to initialize a SwerveSubsystem by loading robot configuration and setting up the SwerveSetpointGenerator. It also shows how to drive the robot relative to its own frame by taking ChassisSpeeds as input, generating a SwerveSetpoint, and updating the module states. Dependencies include pathplannerlib and wpimath. ```Python from pathplannerlib.config import RobotConfig from pathplannerlib.util import DriveFeedforwards from pathplannerlib.util.swerve import SwerveSetpoint, SwerveSetpointGenerator from wpimath.kinematics import ChassisSpeeds from wpimath.units import rotationsToRadians class SwerveSubsystem(Subsystem): def __init__(self): # All other subsystem initialization # ... # Load the RobotConfig from the GUI settings. You should probably # store this in your Constants file config = RobotConfig.fromGUISettings() self.setpointGenerator = SwerveSetpointGenerator( config, # The robot configuration. This is the same config used for generating trajectories and running path following commands. rotationsToRadians(10.0) # The max rotation velocity of a swerve module in radians per second. This should probably be stored in your Constants file ) # Initialize the previous setpoint to the robot's current speeds & module states currentSpeeds = self.getCurrentSpeeds() # Method to get current robot-relative chassis speeds currentStates = self.getCurrentModuleStates() # Method to get the current swerve module states self.previousSetpoint = SwerveSetpoint(currentSpeeds, currentStates, DriveFeedforwards.zeros(config.numModules)) def driveRobotRelative(self, speeds: ChassisSpeeds): """ This method will take in desired robot-relative chassis speeds, generate a swerve setpoint, then set the target state for each module :param speeds: The desired robot-relative speeds """ # Note: it is important to not discretize speeds before or after # using the setpoint generator, as it will discretize them for you self.previousSetpoint = self.setpointGenerator.generateSetpoint( self.previousSetpoint, # The previous setpoint speeds, # The desired target speeds 0.02, # The loop time of the robot code, in seconds ) self.setModuleStates(self.previousSetpoint.moduleStates) # Method that will drive the robot given target module states ``` -------------------------------- ### Create SendableChooser with Auto Filtering (C++) Source: https://github.com/mjansen4857/pathplanner/blob/main/Writerside/topics/pplib-Build-an-Auto.md Illustrates the creation of a SendableChooser for autonomous routines in C++ using PathPlannerLib. The buildAutoChooserFilter function is employed to filter autonomous commands. The example shows how to conditionally filter based on a 'isCompetition' boolean, only including autos whose names start with 'comp' when 'isCompetition' is true. It also includes commented-out examples for specifying a default auto by name and filtering by path. ```cpp #include #include #include #include #include using namespace pathplanner; RobotContainer::RobotContainer() { // ... // For convenience a programmer could change this when going to competition. bool isCompetition = true; // Build an auto chooser. This will use frc2::cmd::None() as the default option. // As an example, this will only show autos that start with "comp" while at // competition as defined by the programmer autoChooser = AutoBuilder::buildAutoChooserFilter( [&isCompetition](const PathPlannerAuto& autoCommand) { return isCompetition ? autoCommand.GetName().starts_with("comp") : true; } ); // Another option that allows you to specify the default auto by its name /* autoChooser = AutoBuilder::buildAutoChooserFilter( [&isCompetition](const PathPlannerAuto& autoCommand) { return isCompetition ? autoCommand.GetName().starts_with("comp") : true; }, "autoDefault", // If filled it will choosen always, regardless of filter ); */ // Another option allows you to filter out current directories relative to deploy/pathplanner/auto directory // Allows only autos in directory deploy/pathplanner/autos/comp /* autoChooser = AutoBuilder::buildAutoChooserFilterPathFilterPath( [&isCompetition](const PathPlannerAuto& autoCommand, std::filesystem::path autoPath) { return isCompetition ? autoPath.compare("comp") > 0 : true; } ); */ frc::SmartDashboard::PutData("Auto Chooser", &autoChooser); } frc2::Command* RobotContainer::getAutonomousCommand() { // Returns a frc2::Command* that is freed at program termination return autoChooser.GetSelected(); } ``` -------------------------------- ### Create PathPlannerPath On-the-fly Source: https://github.com/mjansen4857/pathplanner/blob/main/Writerside/topics/pplib-Create-a-Path-On-the-fly.md Demonstrates creating a PathPlannerPath from a list of poses. It includes setting path constraints and a goal end state. The `preventFlipping` option is shown to prevent unwanted path mirroring. ```Java List waypoints = PathPlannerPath.waypointsFromPoses( 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)) ); PathConstraints constraints = new PathConstraints(3.0, 3.0, 2 * Math.PI, 4 * Math.PI); // The constraints for this path. // PathConstraints constraints = PathConstraints.unlimitedConstraints(12.0); // You can also use unlimited constraints, only limited by motor torque and nominal battery voltage // Create the path using the waypoints created above PathPlannerPath path = new PathPlannerPath( waypoints, constraints, null, // The ideal starting state, this is only relevant for pre-planned paths, so can be null for on-the-fly paths. 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. ); // Prevent the path from being flipped if the coordinates are already correct path.preventFlipping = true; ``` ```C++ #include using namespace pathplanner; // Create a vector of waypoints from poses. Each pose represents one waypoint. // The rotation component of the pose should be the direction of travel. Do not use holonomic rotation. std::vector poses{ frc::Pose2d(1.0_m, 1.0_m, frc::Rotation2d(0_deg)), frc::Pose2d(3.0_m, 1.0_m, frc::Rotation2d(0_deg)), frc::Pose2d(5.0_m, 3.0_m, frc::Rotation2d(90_deg)) }; std::vector waypoints = PathPlannerPath::waypointsFromPoses(poses); PathConstraints constraints(3.0_mps, 3.0_mps_sq, 360_deg_per_s, 720_deg_per_s_sq); // The constraints for this path. // PathConstraints constraints = PathConstraints::unlimitedConstraints(12_V); // You can also use unlimited constraints, only limited by motor torque and nominal battery voltage // Create the path using the waypoints created above // We make a shared pointer here since the path following commands require a shared pointer auto path = std::make_shared( waypoints, constraints, std::nullopt, // The ideal starting state, this is only relevant for pre-planned paths, so can be nullopt for on-the-fly paths. GoalEndState(0.0_mps, frc::Rotation2d(-90_deg)) // Goal end state. You can set a holonomic rotation here. If using a differential drivetrain, the rotation will have no effect. ); // Prevent the path from being flipped if the coordinates are already correct path->preventFlipping = true; ``` ```Python from pathplannerlib.path import PathPlannerPath, PathConstraints, GoalEndState from wpimath.geometry import Pose2d, Rotation2d import math # Create a list of waypoints from poses. Each pose represents one waypoint. # The rotation component of the pose should be the direction of travel. Do not use holonomic rotation. waypoints = PathPlannerPath.waypointsFromPoses( Pose2d(1.0, 1.0, Rotation2d.fromDegrees(0)), Pose2d(3.0, 1.0, Rotation2d.fromDegrees(0)), Pose2d(5.0, 3.0, Rotation2d.fromDegrees(90)) ) constraints = PathConstraints(3.0, 3.0, 2 * math.pi, 4 * math.pi) # The constraints for this path. # constraints = PathConstraints.unlimitedConstraints(12.0) # You can also use unlimited constraints, only limited by motor torque and nominal battery voltage # Create the path using the waypoints created above path = new PathPlannerPath( waypoints, constraints, None, # The ideal starting state, this is only relevant for pre-planned paths, so can be None for on-the-fly paths. 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. ) # Prevent the path from being flipped if the coordinates are already correct path.preventFlipping = True; ``` -------------------------------- ### Create Manual FollowPathCommand Source: https://context7.com/mjansen4857/pathplanner/llms.txt Demonstrates how to instantiate a FollowPathCommand manually for custom path following logic without relying on AutoBuilder. ```java public Command followPathCommand(String pathName) { PathPlannerPath path = PathPlannerPath.fromPathFile(pathName); return new FollowPathCommand( path, this::getPose, // Pose supplier this::getRobotRelativeSpeeds, // Robot-relative ChassisSpeeds supplier this::driveWithFeedforwards, // Drive method (speeds + feedforwards) new PPHolonomicDriveController( new PIDConstants(5.0, 0.0, 0.0), // Translation PID new PIDConstants(5.0, 0.0, 0.0) // Rotation PID ), Constants.robotConfig, () -> DriverStation.getAlliance().orElse(Alliance.Blue) == Alliance.Red, this // Subsystem requirement ); } ``` -------------------------------- ### Pathfind Then Follow Path Source: https://github.com/mjansen4857/pathplanner/blob/main/Writerside/topics/pplib-Pathfinding.md This section demonstrates how to use AutoBuilder to create a command that first pathfinds a path and then follows it. ```APIDOC ## POST /api/pathfindThenFollowPath ### Description Creates a command to pathfind a specified path and then follow it. ### Method POST ### Endpoint /api/pathfindThenFollowPath ### Parameters #### Request Body - **path** (PathPlannerPath) - Required - The path to pathfind and follow. - **constraints** (PathConstraints) - Required - The constraints for pathfinding (max velocity, max acceleration). ### Request Example ```json { "path": { "name": "Example Human Player Pickup" }, "constraints": { "maxVelocity": 3.0, "maxAcceleration": 4.0, "maxAngularVelocity": "540deg/s", "maxAngularAcceleration": "720deg/s^2" } } ``` ### Response #### Success Response (200) - **command** (string) - A string representing the pathfinding and following command. #### Response Example ```json { "command": "pathfindingFollowCommand" } ``` ``` -------------------------------- ### AutoBuilder.pathfindThenFollowPath Source: https://context7.com/mjansen4857/pathplanner/llms.txt Pathfind to the start of a pre-planned path, then follow it for precise alignment. This combines dynamic pathfinding with the accuracy of pre-defined paths. ```APIDOC ## AutoBuilder.pathfindThenFollowPath - Pathfind to Pre-planned Path ### Description Pathfind to the start of a pre-planned path, then follow it for precise alignment. ### Method `public static Command pathfindThenFollowPath(PathPlannerPath path, PathConstraints constraints)` ### Endpoint N/A (Java method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java // Load the path for final approach (e.g., to human player station) PathPlannerPath approachPath = PathPlannerPath.fromPathFile("Human Player Pickup"); // Pathfinding constraints (path constraints used once following the pre-planned path) PathConstraints constraints = new PathConstraints( 3.0, 4.0, Units.degreesToRadians(540), Units.degreesToRadians(720) ); // Pathfind to the path start, then follow the pre-planned path Command command = AutoBuilder.pathfindThenFollowPath(approachPath, constraints); ``` ### Response N/A (Java method) #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Java Path Following Warmup Command Source: https://github.com/mjansen4857/pathplanner/blob/main/Writerside/topics/pplib-Follow-a-Single-Path.md This Java code snippet demonstrates how to schedule a warmup command during robot initialization. The warmup command runs a full path following cycle to pre-load necessary classes, reducing potential delays on the first actual path following command. This is particularly useful in Java environments. ```java public void robotInit() { // ... all other robot initialization FollowPathCommand.warmupCommand().schedule(); } ``` -------------------------------- ### Register Custom Pathfinder in Robot Initialization Source: https://github.com/mjansen4857/pathplanner/blob/main/Writerside/topics/pplib-Pathfinding.md Registers a custom pathfinder implementation with the PathPlannerLib library. This must be executed at the start of robot initialization before any pathfinding commands are generated. ```Java public void robotInit() { // DO THIS FIRST Pathfinding.setPathfinder(new MyPathfinder()); // ... remaining robot initialization } ``` ```C++ #include using namespace pathplanner; Robot::robotInit() { // DO THIS FIRST Pathfinding::setPathfinder(MyPathfinder()); // ... remaining robot initialization } ``` ```Python from pathplannerlib.pathfinding import Pathfinding def robotInit(): # DO THIS FIRST Pathfinding.setPathfinder(MyPathfinder()) # ... remaining robot initialization ``` -------------------------------- ### Using AutoBuilder Source: https://github.com/mjansen4857/pathplanner/wiki/Python-Example:-Follow-a-Single-Path This section demonstrates how to use AutoBuilder to create a command for following a single path. AutoBuilder simplifies the process and automatically handles event markers. ```APIDOC ## Using AutoBuilder ### Description This section demonstrates how to use AutoBuilder to create a command for following a single path. AutoBuilder simplifies the process and automatically handles event markers. ### Method `AutoBuilder.followPathWithEvents(path)` ### Endpoint N/A (This is a library function, not an API endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from pathplannerlib.path import PathPlannerPath from pathplannerlib.auto import AutoBuilder def getAutonomousCommand(): # Load the path you want to follow using its name in the GUI path = PathPlannerPath.fromPathFile('Example Path') # Create a path following command using AutoBuilder. This will also trigger event markers. return AutoBuilder.followPathWithEvents(path); ``` ### Response #### Success Response (200) N/A (This is a library function, not an API endpoint) #### Response Example N/A ``` -------------------------------- ### Configure Ramsete AutoBuilder Source: https://github.com/mjansen4857/pathplanner/wiki/Cpp-Example:-Build-an-Auto Configures the AutoBuilder for a Ramsete drive system. This setup uses default Ramsete parameters and requires pose/speed suppliers and drive control methods. ```C++ AutoBuilder::configureRamsete( [this](){ return getPose(); }, [this](frc::Pose2d pose){ resetPose(pose); }, [this](){ return getRobotRelativeSpeeds(); }, [this](frc::ChassisSpeeds speeds){ driveRobotRelative(speeds); }, ReplanningConfig(), this ); ``` -------------------------------- ### Configure AutoBuilder for Holonomic Drive Source: https://context7.com/mjansen4857/pathplanner/llms.txt Configures the AutoBuilder in the drive subsystem to handle path following. This setup requires pose suppliers, odometry reset methods, and PID constants for translation and rotation. ```java public class DriveSubsystem extends SubsystemBase { public DriveSubsystem() { RobotConfig config; try { config = RobotConfig.fromGUISettings(); } catch (Exception e) { e.printStackTrace(); } AutoBuilder.configure( this::getPose, this::resetPose, this::getRobotRelativeSpeeds, (speeds, feedforwards) -> driveRobotRelative(speeds), new PPHolonomicDriveController( new PIDConstants(5.0, 0.0, 0.0), new PIDConstants(5.0, 0.0, 0.0) ), config, () -> { var alliance = DriverStation.getAlliance(); if (alliance.isPresent()) { return alliance.get() == DriverStation.Alliance.Red; } return false; }, this ); } } ``` -------------------------------- ### Generate Autonomous Command with AutoBuilder in Java Source: https://github.com/mjansen4857/pathplanner/wiki/PathPlannerLib:-Java-Usage Illustrates using PathPlannerLib's AutoBuilder to create a complete autonomous command, incorporating path groups, event markers, and stop events. This example uses SwerveAutoBuilder. ```Java ArrayList pathGroup = PathPlanner.loadPathGroup("FullAuto", new PathConstraints(4, 3)); HashMap eventMap = new HashMap<>(); eventMap.put("marker1", new PrintCommand("Passed marker 1")); eventMap.put("intakeDown", new IntakeDown()); SwerveAutoBuilder autoBuilder = new SwerveAutoBuilder( driveSubsystem::getPose, // Pose2d supplier driveSubsystem::resetPose, // Pose2d consumer, used to reset odometry at the beginning of auto driveSubsystem.kinematics, // SwerveDriveKinematics new PIDConstants(5.0, 0.0, 0.0), // PID constants to correct for translation error new PIDConstants(0.5, 0.0, 0.0), // PID constants to correct for rotation error driveSubsystem::setModuleStates, // Module states consumer eventMap, true, // Should the path be automatically mirrored driveSubsystem // The drive subsystem ); Command fullAuto = autoBuilder.fullAuto(pathGroup); ``` -------------------------------- ### Follow Path with Events (C++) Source: https://github.com/mjansen4857/pathplanner/wiki/PathPlannerLib:-Cpp-Usage Demonstrates how to use the FollowPathWithEvents command to execute a path and trigger custom commands at named markers along the path. It loads a predefined path and maps string markers to shared pointer commands. ```C++ #include #include #include using namespace pathplanner; // This will load the file "Example Path.path" and generate it with a max velocity of 4 m/s and a max acceleration of 3 m/s^2 PathPlannerTrajectory examplePath = PathPlanner::loadPath("Example Path", PathConstrains(4, 3)); // This is just an example event map. It would be better to have a constant, global event map // in your code that will be used by all path following commands. std::unordered_map> eventMap; eventMap.emplace("marker1", std::make_shared("Passed marker 1")); eventMap.emplace("intakeDown", std::make_shared()); FollowPathWithEvents command( getPathFollowingCommand(examplePath), examplePath.getMarkers(), eventMap ); ``` -------------------------------- ### Get Path Group from Auto - PathPlannerAuto Source: https://github.com/mjansen4857/pathplanner/blob/main/Writerside/topics/pplib-Path-Groups.md Demonstrates how to retrieve a path group from a PathPlanner auto file using the PathPlannerAuto class. This method is useful for accessing the paths defined within an auto. Note that only paths are retrieved, not other commands. ```Java List pathGroup = PathPlannerAuto.getPathGroupFromAutoFile("Example Auto"); ``` ```C++ #include using namespace pathplanner; auto pathGroup = PathPlannerAuto::getPathGroupFromAutoFile("Example Auto"); ``` ```Python from pathplannerlib.auto import PathPlannerAuto pathGroup = PathPlannerAuto.getPathGroupFromAutoFile('Example Auto'); ``` -------------------------------- ### Pathfind to Pre-planned Path (Java) Source: https://context7.com/mjansen4857/pathplanner/llms.txt Combines automatic pathfinding with following a pre-planned path. The robot first pathfinds to the start of a defined path, then executes that path for precise alignment. This is ideal for complex maneuvers requiring both navigation and accurate endpoint positioning. ```java // Load the path for final approach (e.g., to human player station) PathPlannerPath approachPath = PathPlannerPath.fromPathFile("Human Player Pickup"); // Pathfinding constraints (path constraints used once following the pre-planned path) PathConstraints constraints = new PathConstraints( 3.0, 4.0, Units.degreesToRadians(540), Units.degreesToRadians(720) ); // Pathfind to the path start, then follow the pre-planned path Command command = AutoBuilder.pathfindThenFollowPath(approachPath, constraints); ``` -------------------------------- ### Set AdvantageKit Compatible Pathfinder Source: https://github.com/mjansen4857/pathplanner/blob/main/Writerside/topics/pplib-Pathfinding.md Initializes Pathfinding with an AdvantageKit-compatible pathfinder implementation for log replay compatibility. This should be done first during robot initialization. ```Java public void robotInit() { // DO THIS FIRST Pathfinding.setPathfinder(new LocalADStarAK()); // ... remaining robot initialization } ``` -------------------------------- ### Pathfind Then Follow Path using AutoBuilder Source: https://github.com/mjansen4857/pathplanner/blob/main/Writerside/topics/pplib-Pathfinding.md Creates a command that first pathfinds to a specified path and then follows it. This method leverages AutoBuilder for simplified command creation. It requires a PathPlannerPath object and PathConstraints. ```Java // Load the path we want to pathfind to and follow PathPlannerPath path = PathPlannerPath.fromPathFile("Example Human Player Pickup"); // Create the constraints to use while pathfinding. The constraints defined in the path will only be used for the path. PathConstraints constraints = new PathConstraints( 3.0, 4.0, Units.degreesToRadians(540), Units.degreesToRadians(720)); // Since AutoBuilder is configured, we can use it to build pathfinding commands Command pathfindingCommand = AutoBuilder.pathfindThenFollowPath( path, constraints); ``` ```C++ #include using namespace pathplanner; // Load the path we want to pathfind to and follow auto path = PathPlannerPath::fromPathFile("Example Human Player Pickup"); // Create the constraints to use while pathfinding. The constraints defined in the path will only be used for the path. PathConstraints constraints = PathConstraints( 3.0_mps, 4.0_mps_sq, 540_deg_per_s, 720_deg_per_s_sq); // Since AutoBuilder is configured, we can use it to build pathfinding commands frc2::CommandPtr pathfindingCommand = AutoBuilder::pathfindThenFollowPath( path, constraints, ); ``` ```Python from pathplannerlib.auto import AutoBuilder from pathplannerlib.path import PathPlannerPath PathConstraints from wpimath.units import degreesToRadians # Load the path we want to pathfind to and follow path = PathPlannerPath.fromPathFile('Example Human Player Pickup'); # Create the constraints to use while pathfinding. The constraints defined in the path will only be used for the path. constraints = PathConstraints( 3.0, 4.0, degreesToRadians(540), degreesToRadians(720) ) # Since AutoBuilder is configured, we can use it to build pathfinding commands pathfindingCommand = AutoBuilder.pathfindThenFollowPath( path, constraints, ) ```