[examples] Update ElevatorTrapezoidProfile example (#5466)

This commit is contained in:
Gold856
2023-07-24 00:36:47 -04:00
committed by GitHub
parent 99b88be4f3
commit 873c2a6c10
2 changed files with 9 additions and 14 deletions

View File

@@ -32,13 +32,9 @@ class Robot : public frc::TimedRobot {
m_goal = {0_m, 0_mps};
}
// Create a motion profile with the given maximum velocity and maximum
// acceleration constraints for the next setpoint.
frc::TrapezoidProfile<units::meters> profile{m_constraints};
// Retrieve the profiled setpoint for the next timestep. This setpoint moves
// toward the goal while obeying the constraints.
m_setpoint = profile.Calculate(kDt, m_goal, m_setpoint);
m_setpoint = m_profile.Calculate(kDt, m_goal, m_setpoint);
// Send setpoint to offboard controller PID
m_motor.SetSetpoint(ExampleSmartMotorController::PIDMode::kPosition,
@@ -53,8 +49,9 @@ class Robot : public frc::TimedRobot {
// Note: These gains are fake, and will have to be tuned for your robot.
1_V, 1.5_V * 1_s / 1_m};
frc::TrapezoidProfile<units::meters>::Constraints m_constraints{1.75_mps,
0.75_mps_sq};
// Create a motion profile with the given maximum velocity and maximum
// acceleration constraints for the next setpoint.
frc::TrapezoidProfile<units::meters> m_profile{{1.75_mps, 0.75_mps_sq}};
frc::TrapezoidProfile<units::meters>::State m_goal;
frc::TrapezoidProfile<units::meters>::State m_setpoint;
};