mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
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:
@@ -18,10 +18,10 @@ ArmSubsystem::ArmSubsystem()
|
||||
kP, 0, 0, {kMaxVelocity, kMaxAcceleration})),
|
||||
m_motor(kMotorPort),
|
||||
m_encoder(kEncoderPorts[0], kEncoderPorts[1]),
|
||||
m_feedforward(kS, kCos, kV, kA),
|
||||
// Start arm at rest in neutral position
|
||||
m_goal{kArmOffset, 0_rad_per_s} {
|
||||
m_feedforward(kS, kCos, kV, kA) {
|
||||
m_encoder.SetDistancePerPulse(kEncoderDistancePerPulse.to<double>());
|
||||
// Start arm in neutral position
|
||||
SetGoal(State{kArmOffset, 0_rad_per_s});
|
||||
}
|
||||
|
||||
void ArmSubsystem::UseOutput(double output, State setpoint) {
|
||||
@@ -32,12 +32,6 @@ void ArmSubsystem::UseOutput(double output, State setpoint) {
|
||||
m_motor.SetVoltage(units::volt_t(output) + feedforward);
|
||||
}
|
||||
|
||||
void ArmSubsystem::SetGoal(units::radian_t goal) {
|
||||
m_goal = State{goal, 0_rad_per_s};
|
||||
}
|
||||
|
||||
State ArmSubsystem::GetGoal() { return m_goal; }
|
||||
|
||||
units::radian_t ArmSubsystem::GetMeasurement() {
|
||||
return units::radian_t(m_encoder.GetDistance()) + kArmOffset;
|
||||
}
|
||||
|
||||
@@ -24,16 +24,10 @@ class ArmSubsystem : public frc2::ProfiledPIDSubsystem<units::radians> {
|
||||
|
||||
void UseOutput(double output, State setpoint) override;
|
||||
|
||||
void SetGoal(units::radian_t goal);
|
||||
|
||||
State GetGoal() override;
|
||||
|
||||
units::radian_t GetMeasurement() override;
|
||||
|
||||
private:
|
||||
frc::PWMVictorSPX m_motor;
|
||||
frc::Encoder m_encoder;
|
||||
frc::ArmFeedforward m_feedforward;
|
||||
|
||||
State m_goal;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user