diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/cpp/Robot.cpp index b1b1389074..fb3a70dc8c 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/cpp/Robot.cpp @@ -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 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::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 m_profile{{1.75_mps, 0.75_mps_sq}}; frc::TrapezoidProfile::State m_goal; frc::TrapezoidProfile::State m_setpoint; }; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatortrapezoidprofile/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatortrapezoidprofile/Robot.java index d6c25d6396..2acb5bcd39 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatortrapezoidprofile/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatortrapezoidprofile/Robot.java @@ -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(