Improve various subsystem APIs (#2130)

Improves the APIs for various prebuilt subsystems (PIDSubsystem, TrapezoidProfileSubsystem, ProfiledPIDSubsystem). Addresses #2128, and also changes the rather cumbersome getSetpoint API to a more intuitive setSetpoint one. Updates examples to match.
This commit is contained in:
Oblarg
2019-11-26 00:46:47 -05:00
committed by Peter Johnson
parent ce3973435e
commit 6dcd2b0e2c
19 changed files with 184 additions and 204 deletions

View File

@@ -41,22 +41,29 @@ class TrapezoidProfileSubsystem : public SubsystemBase {
units::second_t period = 20_ms)
: m_constraints(constraints),
m_state{position, Velocity_t(0)},
m_goal{position, Velocity_t{0}},
m_period(period) {}
void Periodic() override {
auto profile =
frc::TrapezoidProfile<Distance>(m_constraints, GetGoal(), m_state);
frc::TrapezoidProfile<Distance>(m_constraints, m_goal, m_state);
m_state = profile.Calculate(m_period);
UseState(m_state);
}
/**
* Users should override this to return the goal state for the subsystem's
* motion profile.
* Sets the goal state for the subsystem.
*
* @return The goal state for the subsystem's motion profile.
* @param goal The goal state for the subsystem's motion profile.
*/
virtual State GetGoal() = 0;
void SetGoal(State goal) { m_goal = goal; }
/**
* Sets the goal state for the subsystem. Goal velocity assumed to be zero.
*
* @param goal The goal position for the subsystem's motion profile.
*/
void SetGoal(Distance_t goal) { m_goal = State{goal, Velocity_t(0)}; }
protected:
/**
@@ -70,6 +77,7 @@ class TrapezoidProfileSubsystem : public SubsystemBase {
private:
Constraints m_constraints;
State m_state;
State m_goal;
units::second_t m_period;
};
} // namespace frc2