public class DriveSubsystem extends SubsystemBase {
public DriveSubsystem() {
// All other subsystem initialization
// ...
// Load the RobotConfig from the GUI settings. You should probably
// store this in your Constants file
RobotConfig config;
try{
config = RobotConfig.fromGUISettings();
} catch (Exception e) {
// Handle exception as needed
e.printStackTrace();
}
// Configure AutoBuilder last
AutoBuilder.configure(
this::getPose, // Robot pose supplier
this::resetPose, // Method to reset odometry (will be called if your auto has a starting pose)
this::getRobotRelativeSpeeds, // ChassisSpeeds supplier. MUST BE ROBOT RELATIVE
(speeds, feedforwards) -> driveRobotRelative(speeds), // Method that will drive the robot given ROBOT RELATIVE ChassisSpeeds. Also optionally outputs individual module feedforwards
new PPHolonomicDriveController( // PPHolonomicController is the built in path following controller for holonomic drive trains
new PIDConstants(5.0, 0.0, 0.0), // Translation PID constants
new PIDConstants(5.0, 0.0, 0.0) // Rotation PID constants
),
config, // The robot configuration
() -> {
// Boolean supplier that controls when the path will be mirrored for the red alliance
// This will flip the path being followed to the red side of the field.
// THE ORIGIN WILL REMAIN ON THE BLUE SIDE
var alliance = DriverStation.getAlliance();
if (alliance.isPresent()) {
return alliance.get() == DriverStation.Alliance.Red;
}
return false;
},
this // Reference to this subsystem to set requirements
);
}
}
#include <pathplanner/lib/auto/AutoBuilder.h>
#include <pathplanner/lib/config/RobotConfig.h>
#include <pathplanner/lib/controllers/PPHolonomicDriveController.h>
#include <frc/geometry/Pose2d.h>
#include <frc/kinematics/ChassisSpeeds.h>
#include <frc/DriverStation.h>
using namespace pathplanner;
SwerveSubsystem::SwerveSubsystem(){
// Do all subsystem initialization here
// ...
// Load the RobotConfig from the GUI settings. You should probably
// store this in your Constants file
RobotConfig config = RobotConfig::fromGUISettings();
// Configure the AutoBuilder last
AutoBuilder::configure(
[this](){ return getPose(); }, // Robot pose supplier
[this](frc::Pose2d pose){ resetPose(pose); }, // Method to reset odometry (will be called if your auto has a starting pose)
[this](){ return getRobotRelativeSpeeds(); }, // ChassisSpeeds supplier. MUST BE ROBOT RELATIVE
[this](auto speeds, auto feedforwards){ driveRobotRelative(speeds); }, // Method that will drive the robot given ROBOT RELATIVE ChassisSpeeds. Also optionally outputs individual module feedforwards
std::make_shared<PPHolonomicDriveController>( // PPHolonomicController is the built in path following controller for holonomic drive trains
PIDConstants(5.0, 0.0, 0.0), // Translation PID constants
PIDConstants(5.0, 0.0, 0.0) // Rotation PID constants
),
config, // The robot configuration
[]() {
// Boolean supplier that controls when the path will be mirrored for the red alliance
// This will flip the path being followed to the red side of the field.
// THE ORIGIN WILL REMAIN ON THE BLUE SIDE
auto alliance = DriverStation::GetAlliance();
if (alliance) {
return alliance.value() == DriverStation::Alliance::kRed;
}
return false;
},
this // Reference to this subsystem to set requirements
);
}
from pathplannerlib.auto import AutoBuilder
from pathplannerlib.controller import PPHolonomicDriveController
from pathplannerlib.config import RobotConfig, PIDConstants
from wpilib import DriverStation
class SwerveSubsystem(Subsystem):
def __init__(self):
# Do all subsystem initialization here
# ...
# Load the RobotConfig from the GUI settings. You should probably
# store this in your Constants file
config = RobotConfig.fromGUISettings()
# Configure the AutoBuilder last
AutoBuilder.configureHolonomic(
self.getPose, # Robot pose supplier
self.resetPose, # Method to reset odometry (will be called if your auto has a starting pose)
self.getRobotRelativeSpeeds, # ChassisSpeeds supplier. MUST BE ROBOT RELATIVE
lambda speeds, feedforwards: self.driveRobotRelative(speeds), # Method that will drive the robot given ROBOT RELATIVE ChassisSpeeds. Also outputs individual module feedforwards
PPHolonomicDriveController( # PPHolonomicController is the built in path following controller for holonomic drive trains
PIDConstants(5.0, 0.0, 0.0), # Translation PID constants
PIDConstants(5.0, 0.0, 0.0) # Rotation PID constants
),
config, # The robot configuration
self.shouldFlipPath, # Supplier to control path flipping based on alliance color
self # Reference to this subsystem to set requirements
)
def shouldFlipPath():
# Boolean supplier that controls when the path will be mirrored for the red alliance
# This will flip the path being followed to the red side of the field.
# THE ORIGIN WILL REMAIN ON THE BLUE SIDE
return DriverStation.getAlliance() == DriverStation.Alliance.kRed