[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

@@ -17,8 +17,10 @@ public class Robot extends TimedRobot {
// Note: These gains are fake, and will have to be tuned for your robot.
private final SimpleMotorFeedforward m_feedforward = new SimpleMotorFeedforward(1, 1.5);
private final TrapezoidProfile.Constraints m_constraints =
new TrapezoidProfile.Constraints(1.75, 0.75);
// Create a motion profile with the given maximum velocity and maximum
// acceleration constraints for the next setpoint.
private final TrapezoidProfile m_profile =
new TrapezoidProfile(new TrapezoidProfile.Constraints(1.75, 0.75));
private TrapezoidProfile.State m_goal = new TrapezoidProfile.State();
private TrapezoidProfile.State m_setpoint = new TrapezoidProfile.State();
@@ -36,13 +38,9 @@ public class Robot extends TimedRobot {
m_goal = new TrapezoidProfile.State();
}
// Create a motion profile with the given maximum velocity and maximum
// acceleration constraints for the next setpoint.
var profile = new TrapezoidProfile(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(