mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpimath] Refactor TrapezoidProfile API (#5457)
This commit is contained in:
@@ -40,13 +40,17 @@ void RobotContainer::ConfigureButtonBindings() {
|
||||
frc2::TrapezoidProfileCommand<units::meters>(
|
||||
frc::TrapezoidProfile<units::meters>(
|
||||
// Limit the max acceleration and velocity
|
||||
{DriveConstants::kMaxSpeed, DriveConstants::kMaxAcceleration},
|
||||
// End at desired position in meters; implicitly starts at 0
|
||||
{3_m, 0_mps}),
|
||||
{DriveConstants::kMaxSpeed, DriveConstants::kMaxAcceleration}),
|
||||
// Pipe the profile state to the drive
|
||||
[this](auto setpointState) {
|
||||
m_drive.SetDriveStates(setpointState, setpointState);
|
||||
},
|
||||
// End at desired position in meters; implicitly starts at 0
|
||||
[] {
|
||||
return frc::TrapezoidProfile<units::meters>::State{3_m, 0_mps};
|
||||
},
|
||||
// Current position
|
||||
[] { return frc::TrapezoidProfile<units::meters>::State{}; },
|
||||
// Require the drive
|
||||
{&m_drive})
|
||||
// Convert to CommandPtr
|
||||
|
||||
@@ -13,13 +13,16 @@ DriveDistanceProfiled::DriveDistanceProfiled(units::meter_t distance,
|
||||
: CommandHelper{
|
||||
frc::TrapezoidProfile<units::meters>{
|
||||
// Limit the max acceleration and velocity
|
||||
{kMaxSpeed, kMaxAcceleration},
|
||||
// End at desired position in meters; implicitly starts at 0
|
||||
{distance, 0_mps}},
|
||||
{kMaxSpeed, kMaxAcceleration}},
|
||||
// Pipe the profile state to the drive
|
||||
[drive](auto setpointState) {
|
||||
drive->SetDriveStates(setpointState, setpointState);
|
||||
},
|
||||
// End at desired position in meters; implicitly starts at 0
|
||||
[distance] {
|
||||
return frc::TrapezoidProfile<units::meters>::State{distance, 0_mps};
|
||||
},
|
||||
[] { return frc::TrapezoidProfile<units::meters>::State{}; },
|
||||
// Require the drive
|
||||
{drive}} {
|
||||
// Reset drive encoders since we're starting at 0
|
||||
|
||||
Reference in New Issue
Block a user