57 void Reset(wpi::units::radian_t angle, wpi::units::radians_per_second_t velocity);
65 void Reset(wpi::units::meter_t distance, wpi::units::meters_per_second_t velocity);
75 wpi::units::volt_t
Calculate(wpi::units::radian_t measured, wpi::units::radian_t position,
76 wpi::units::radians_per_second_t velocity);
86 wpi::units::volt_t
Calculate(wpi::units::meter_t measured, wpi::units::meter_t position,
87 wpi::units::meters_per_second_t velocity);
96 wpi::units::volt_t
Calculate(wpi::units::radians_per_second_t measured,
97 wpi::units::radians_per_second_t velocity);
106 wpi::units::volt_t
Calculate(wpi::units::meters_per_second_t measured,
107 wpi::units::meters_per_second_t velocity);
126 struct FlywheelBundle {
127 wpi::math::LinearQuadraticRegulator<1, 1> controller;
128 wpi::math::KalmanFilter<1, 1, 1> observer;
131 FlywheelBundle(wpi::math::LinearSystem<1, 1, 1> plant,
132 wpi::math::LinearQuadraticRegulator<1, 1> ctrl,
133 wpi::math::KalmanFilter<1, 1, 1> obs, wpi::units::volt_t maxV,
134 wpi::units::second_t dt)
135 : controller{std::move(ctrl)},
136 observer{std::move(obs)},
137 loop{plant, controller, observer, maxV, dt} {}
139 FlywheelBundle(
const FlywheelBundle&) =
delete;
140 FlywheelBundle& operator=(
const FlywheelBundle&) =
delete;
141 FlywheelBundle(FlywheelBundle&&) =
delete;
142 FlywheelBundle& operator=(FlywheelBundle&&) =
delete;
145 struct ArmElevatorBundle {
146 wpi::math::LinearQuadraticRegulator<2, 1> controller;
147 wpi::math::KalmanFilter<2, 1, 1> observer;
150 ArmElevatorBundle(wpi::math::LinearSystem<2, 1, 1> plant,
151 wpi::math::LinearQuadraticRegulator<2, 1> ctrl,
152 wpi::math::KalmanFilter<2, 1, 1> obs, wpi::units::volt_t maxV,
153 wpi::units::second_t dt)
154 : controller{std::move(ctrl)},
155 observer{std::move(obs)},
156 loop{plant, controller, observer, maxV, dt} {}
158 ArmElevatorBundle(
const ArmElevatorBundle&) =
delete;
159 ArmElevatorBundle& operator=(
const ArmElevatorBundle&) =
delete;
160 ArmElevatorBundle(ArmElevatorBundle&&) =
delete;
161 ArmElevatorBundle& operator=(ArmElevatorBundle&&) =
delete;
164 static std::unique_ptr<FlywheelBundle> BuildFlywheel(
const LQRConfig& cfg);
165 static std::unique_ptr<ArmElevatorBundle> BuildArmElevator(
const LQRConfig& cfg);
167 std::optional<LQRConfig> m_config;
169 std::variant<std::unique_ptr<FlywheelBundle>, std::unique_ptr<ArmElevatorBundle>> m_bundle;
170 wpi::units::second_t m_period;