blob: b9ec5c56742f2048d6eb292b4a35bbd86fa047b8 [file] [log] [blame]
Austin Schuh473a5652017-02-05 01:30:42 -08001#ifndef FRC971_CONTROL_LOOPS_PROFILED_SUBSYSTEM_H_
2#define FRC971_CONTROL_LOOPS_PROFILED_SUBSYSTEM_H_
3
4#include <array>
Austin Schuh3634ed32017-02-05 16:28:49 -08005#include <chrono>
Austin Schuh473a5652017-02-05 01:30:42 -08006#include <memory>
7#include <utility>
8
9#include "Eigen/Dense"
10
John Park33858a32018-09-28 23:05:48 -070011#include "aos/controls/control_loop.h"
12#include "aos/util/trapezoid_profile.h"
Tyler Chatowd3afdef2019-04-06 22:15:26 -070013#include "frc971/constants.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -070014#include "frc971/control_loops/control_loops_generated.h"
15#include "frc971/control_loops/profiled_subsystem_generated.h"
Austin Schuh473a5652017-02-05 01:30:42 -080016#include "frc971/control_loops/simple_capped_state_feedback_loop.h"
17#include "frc971/control_loops/state_feedback_loop.h"
18#include "frc971/zeroing/zeroing.h"
19
20namespace frc971 {
21namespace control_loops {
22
Brian Silvermanab0b6772017-02-05 16:16:21 -080023// TODO(Brian): Use a tuple instead of an array to support heterogeneous zeroing
24// styles.
25template <int number_of_states, int number_of_axes,
26 class ZeroingEstimator =
Austin Schuh08d9ecf2017-03-05 00:58:48 -080027 ::frc971::zeroing::PotAndIndexPulseZeroingEstimator,
28 int number_of_inputs = number_of_axes,
29 int number_of_outputs = number_of_axes>
Austin Schuh473a5652017-02-05 01:30:42 -080030class ProfiledSubsystem {
31 public:
32 ProfiledSubsystem(
33 ::std::unique_ptr<::frc971::control_loops::SimpleCappedStateFeedbackLoop<
Austin Schuh08d9ecf2017-03-05 00:58:48 -080034 number_of_states, number_of_inputs, number_of_outputs>>
35 loop,
Brian Silvermanab0b6772017-02-05 16:16:21 -080036 ::std::array<ZeroingEstimator, number_of_axes> &&estimators)
Austin Schuh473a5652017-02-05 01:30:42 -080037 : loop_(::std::move(loop)), estimators_(::std::move(estimators)) {
38 zeroed_.fill(false);
39 unprofiled_goal_.setZero();
40 }
41
42 // Returns whether an error has occured
43 bool error() const {
44 for (const auto &estimator : estimators_) {
45 if (estimator.error()) {
46 return true;
47 }
48 }
49 return false;
50 }
51
52 void Reset() {
53 zeroed_.fill(false);
Austin Schuh3a81d5c2017-02-05 23:13:47 -080054 initialized_ = false;
Austin Schuh473a5652017-02-05 01:30:42 -080055 for (auto &estimator : estimators_) {
56 estimator.Reset();
57 }
Austin Schuhd5ccb862017-03-11 22:06:36 -080058 should_reset_ = true;
Austin Schuh473a5652017-02-05 01:30:42 -080059 }
60
61 // Returns the controller.
Tyler Chatowd3afdef2019-04-06 22:15:26 -070062 const StateFeedbackLoop<number_of_states, number_of_inputs, number_of_outputs>
63 &controller() const {
Austin Schuh473a5652017-02-05 01:30:42 -080064 return *loop_;
65 }
66
Austin Schuhc5fceb82017-02-25 16:24:12 -080067 int controller_index() const { return loop_->index(); }
Austin Schuh473a5652017-02-05 01:30:42 -080068
Tyler Chatowd3afdef2019-04-06 22:15:26 -070069 void set_controller_index(int index) { loop_->set_index(index); }
70
Austin Schuh473a5652017-02-05 01:30:42 -080071 // Returns whether the estimators have been initialized and zeroed.
72 bool initialized() const { return initialized_; }
73
74 bool zeroed() const {
75 for (int i = 0; i < number_of_axes; ++i) {
76 if (!zeroed_[i]) {
77 return false;
78 }
79 }
80 return true;
81 }
82
83 bool zeroed(int index) const { return zeroed_[index]; };
84
85 // Returns the filtered goal.
86 const Eigen::Matrix<double, number_of_states, 1> &goal() const {
87 return loop_->R();
88 }
89 double goal(int row, int col) const { return loop_->R(row, col); }
90
91 // Returns the unprofiled goal.
92 const Eigen::Matrix<double, number_of_states, 1> &unprofiled_goal() const {
93 return unprofiled_goal_;
94 }
95 double unprofiled_goal(int row, int col) const {
96 return unprofiled_goal_(row, col);
97 }
98
99 // Returns the current state estimate.
100 const Eigen::Matrix<double, number_of_states, 1> &X_hat() const {
101 return loop_->X_hat();
102 }
103 double X_hat(int row, int col) const { return loop_->X_hat(row, col); }
Austin Schuhd5ccb862017-03-11 22:06:36 -0800104 double &mutable_X_hat(int row, int col) const {
105 return loop_->mutable_X_hat(row, col);
106 }
Austin Schuh473a5652017-02-05 01:30:42 -0800107
108 // Returns the current internal estimator state for logging.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700109 flatbuffers::Offset<typename ZeroingEstimator::State> EstimatorState(
110 flatbuffers::FlatBufferBuilder *fbb, int index) {
111 return estimators_[index].GetEstimatorState(fbb);
Austin Schuh473a5652017-02-05 01:30:42 -0800112 }
113
114 // Sets the maximum voltage that will be commanded by the loop.
Austin Schuh08d9ecf2017-03-05 00:58:48 -0800115 void set_max_voltage(::std::array<double, number_of_inputs> voltages) {
116 for (int i = 0; i < number_of_inputs; ++i) {
Austin Schuh473a5652017-02-05 01:30:42 -0800117 loop_->set_max_voltage(i, voltages[i]);
118 }
119 }
120
121 protected:
122 void set_zeroed(int index, bool val) { zeroed_[index] = val; }
123
Austin Schuh473a5652017-02-05 01:30:42 -0800124 ::std::unique_ptr<::frc971::control_loops::SimpleCappedStateFeedbackLoop<
Austin Schuh08d9ecf2017-03-05 00:58:48 -0800125 number_of_states, number_of_inputs, number_of_outputs>>
126 loop_;
Austin Schuh473a5652017-02-05 01:30:42 -0800127
128 // The goal that the profile tries to reach.
129 Eigen::Matrix<double, number_of_states, 1> unprofiled_goal_;
130
131 bool initialized_ = false;
132
Austin Schuhd5ccb862017-03-11 22:06:36 -0800133 // If true, the subclass should reset in Update. It should then clear this
134 // flag.
135 bool should_reset_ = true;
136
Brian Silvermanab0b6772017-02-05 16:16:21 -0800137 ::std::array<ZeroingEstimator, number_of_axes> estimators_;
Austin Schuh473a5652017-02-05 01:30:42 -0800138
139 private:
140 ::std::array<bool, number_of_axes> zeroed_;
141};
142
Adam Snaider79900c22017-02-08 20:23:15 -0800143template <typename ZeroingEstimator =
Brian Silvermanab0b6772017-02-05 16:16:21 -0800144 ::frc971::zeroing::PotAndIndexPulseZeroingEstimator>
Austin Schuh473a5652017-02-05 01:30:42 -0800145class SingleDOFProfiledSubsystem
Tyler Chatowd3afdef2019-04-06 22:15:26 -0700146 : public ::frc971::control_loops::ProfiledSubsystem<3, 1,
147 ZeroingEstimator> {
Austin Schuh473a5652017-02-05 01:30:42 -0800148 public:
149 SingleDOFProfiledSubsystem(
150 ::std::unique_ptr<SimpleCappedStateFeedbackLoop<3, 1, 1>> loop,
Brian Silvermanab0b6772017-02-05 16:16:21 -0800151 const typename ZeroingEstimator::ZeroingConstants &zeroing_constants,
Austin Schuh473a5652017-02-05 01:30:42 -0800152 const ::frc971::constants::Range &range, double default_angular_velocity,
153 double default_angular_acceleration);
154
155 // Updates our estimator with the latest position.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700156 void Correct(const typename ZeroingEstimator::Position &position);
Austin Schuh473a5652017-02-05 01:30:42 -0800157 // Runs the controller and profile generator for a cycle.
158 void Update(bool disabled);
159
Austin Schuh3634ed32017-02-05 16:28:49 -0800160 // Fills out the ProfiledJointStatus structure with the current state.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700161 template <class StatusTypeBuilder>
162 StatusTypeBuilder BuildStatus(
163 flatbuffers::FlatBufferBuilder *fbb);
Austin Schuh3634ed32017-02-05 16:28:49 -0800164
Austin Schuh473a5652017-02-05 01:30:42 -0800165 // Forces the current goal to the provided goal, bypassing the profiler.
166 void ForceGoal(double goal);
James Kuszmaul4fb29762020-02-20 19:37:41 -0800167 // Sets whether to use the trapezoidal profiler or whether to just bypass it
168 // and pass the unprofiled goal through directly.
169 void set_enable_profile(bool enable) { enable_profile_ = enable; }
Austin Schuh473a5652017-02-05 01:30:42 -0800170 // Sets the unprofiled goal. The profiler will generate a profile to go to
171 // this goal.
James Kuszmaul4fb29762020-02-20 19:37:41 -0800172 void set_unprofiled_goal(double unprofiled_goal,
173 double unprofiled_goal_velocity = 0.0);
Austin Schuh473a5652017-02-05 01:30:42 -0800174 // Limits our profiles to a max velocity and acceleration for proper motion.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700175 void AdjustProfile(const ::frc971::ProfileParameters *profile_parameters);
Austin Schuh473a5652017-02-05 01:30:42 -0800176 void AdjustProfile(double max_angular_velocity,
177 double max_angular_acceleration);
178
179 // Returns true if we have exceeded any hard limits.
180 bool CheckHardLimits();
181
Austin Schuh3634ed32017-02-05 16:28:49 -0800182 // Returns the requested voltage.
Adam Snaider79900c22017-02-08 20:23:15 -0800183 double voltage() const { return this->loop_->U(0, 0); }
Austin Schuh473a5652017-02-05 01:30:42 -0800184
185 // Returns the current position.
Adam Snaider79900c22017-02-08 20:23:15 -0800186 double position() const { return this->Y_(0, 0); }
Austin Schuh473a5652017-02-05 01:30:42 -0800187
188 // For testing:
189 // Triggers an estimator error.
Adam Snaider79900c22017-02-08 20:23:15 -0800190 void TriggerEstimatorError() { this->estimators_[0].TriggerError(); }
Austin Schuh473a5652017-02-05 01:30:42 -0800191
Austin Schuh00be3a82017-02-05 19:01:40 -0800192 const ::frc971::constants::Range &range() const { return range_; }
193
Austin Schuh6a90cd92017-02-19 20:55:33 -0800194 protected:
Austin Schuh473a5652017-02-05 01:30:42 -0800195 // Limits the provided goal to the soft limits. Prints "name" when it fails
196 // to aid debugging.
Austin Schuh6a90cd92017-02-19 20:55:33 -0800197 virtual void CapGoal(const char *name, Eigen::Matrix<double, 3, 1> *goal);
Austin Schuh473a5652017-02-05 01:30:42 -0800198
Austin Schuh6a90cd92017-02-19 20:55:33 -0800199 private:
Austin Schuh473a5652017-02-05 01:30:42 -0800200 void UpdateOffset(double offset);
201
202 aos::util::TrapezoidProfile profile_;
James Kuszmaul4fb29762020-02-20 19:37:41 -0800203 bool enable_profile_ = true;
Austin Schuh473a5652017-02-05 01:30:42 -0800204
205 // Current measurement.
206 Eigen::Matrix<double, 1, 1> Y_;
207 // Current offset. Y_ = offset_ + raw_sensor;
208 Eigen::Matrix<double, 1, 1> offset_;
209
210 const ::frc971::constants::Range range_;
211
212 const double default_velocity_;
213 const double default_acceleration_;
Austin Schuh3634ed32017-02-05 16:28:49 -0800214
215 double last_position_ = 0;
Austin Schuh473a5652017-02-05 01:30:42 -0800216};
217
Brian Silvermanab0b6772017-02-05 16:16:21 -0800218namespace internal {
219
220double UseUnlessZero(double target_value, double default_value);
221
222} // namespace internal
223
224template <class ZeroingEstimator>
225SingleDOFProfiledSubsystem<ZeroingEstimator>::SingleDOFProfiledSubsystem(
226 ::std::unique_ptr<SimpleCappedStateFeedbackLoop<3, 1, 1>> loop,
227 const typename ZeroingEstimator::ZeroingConstants &zeroing_constants,
228 const ::frc971::constants::Range &range, double default_velocity,
229 double default_acceleration)
Campbell Crowley36e93e92017-12-23 14:21:43 -0800230 : ProfiledSubsystem<3, 1, ZeroingEstimator>(
231 ::std::move(loop), {{ZeroingEstimator(zeroing_constants)}}),
Brian Silvermanab0b6772017-02-05 16:16:21 -0800232 profile_(::aos::controls::kLoopFrequency),
233 range_(range),
234 default_velocity_(default_velocity),
235 default_acceleration_(default_acceleration) {
236 Y_.setZero();
237 offset_.setZero();
238 AdjustProfile(0.0, 0.0);
239}
240
241template <class ZeroingEstimator>
242void SingleDOFProfiledSubsystem<ZeroingEstimator>::UpdateOffset(double offset) {
243 const double doffset = offset - offset_(0, 0);
Austin Schuhf257f3c2019-10-27 21:00:43 -0700244 AOS_LOG(INFO, "Adjusting offset from %f to %f\n", offset_(0, 0), offset);
Brian Silvermanab0b6772017-02-05 16:16:21 -0800245
Adam Snaider79900c22017-02-08 20:23:15 -0800246 this->loop_->mutable_X_hat()(0, 0) += doffset;
247 this->Y_(0, 0) += doffset;
Austin Schuh3634ed32017-02-05 16:28:49 -0800248 last_position_ += doffset;
Adam Snaider79900c22017-02-08 20:23:15 -0800249 this->loop_->mutable_R(0, 0) += doffset;
Brian Silvermanab0b6772017-02-05 16:16:21 -0800250
251 profile_.MoveGoal(doffset);
252 offset_(0, 0) = offset;
253
Adam Snaider79900c22017-02-08 20:23:15 -0800254 CapGoal("R", &this->loop_->mutable_R());
Brian Silvermanab0b6772017-02-05 16:16:21 -0800255}
256
257template <class ZeroingEstimator>
Alex Perrycb7da4b2019-08-28 19:35:56 -0700258template <class StatusTypeBuilder>
259StatusTypeBuilder SingleDOFProfiledSubsystem<ZeroingEstimator>::BuildStatus(
260 flatbuffers::FlatBufferBuilder *fbb) {
261 flatbuffers::Offset<typename ZeroingEstimator::State> estimator_state =
262 this->EstimatorState(fbb, 0);
263
264 StatusTypeBuilder builder(*fbb);
265
266 builder.add_zeroed(this->zeroed());
Austin Schuh3634ed32017-02-05 16:28:49 -0800267 // We don't know, so default to the bad case.
Austin Schuh3634ed32017-02-05 16:28:49 -0800268
Alex Perrycb7da4b2019-08-28 19:35:56 -0700269 builder.add_position(this->X_hat(0, 0));
270 builder.add_velocity(this->X_hat(1, 0));
271 builder.add_goal_position(this->goal(0, 0));
272 builder.add_goal_velocity(this->goal(1, 0));
273 builder.add_unprofiled_goal_position(this->unprofiled_goal(0, 0));
274 builder.add_unprofiled_goal_velocity(this->unprofiled_goal(1, 0));
275 builder.add_voltage_error(this->X_hat(2, 0));
276 builder.add_calculated_velocity(
Austin Schuh3634ed32017-02-05 16:28:49 -0800277 (position() - last_position_) /
Alex Perrycb7da4b2019-08-28 19:35:56 -0700278 ::aos::time::DurationInSeconds(::aos::controls::kLoopFrequency));
Austin Schuh3634ed32017-02-05 16:28:49 -0800279
Alex Perrycb7da4b2019-08-28 19:35:56 -0700280 builder.add_estimator_state(estimator_state);
Austin Schuh3634ed32017-02-05 16:28:49 -0800281
Adam Snaider79900c22017-02-08 20:23:15 -0800282 Eigen::Matrix<double, 3, 1> error = this->controller().error();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700283 builder.add_position_power(
284 this->controller().controller().K(0, 0) * error(0, 0));
285 builder.add_velocity_power(
286 this->controller().controller().K(0, 1) * error(1, 0));
287 return builder;
Austin Schuh3634ed32017-02-05 16:28:49 -0800288}
289
290template <class ZeroingEstimator>
Brian Silvermanab0b6772017-02-05 16:16:21 -0800291void SingleDOFProfiledSubsystem<ZeroingEstimator>::Correct(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700292 const typename ZeroingEstimator::Position &new_position) {
Adam Snaider79900c22017-02-08 20:23:15 -0800293 this->estimators_[0].UpdateEstimate(new_position);
Brian Silvermanab0b6772017-02-05 16:16:21 -0800294
Adam Snaider79900c22017-02-08 20:23:15 -0800295 if (this->estimators_[0].error()) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700296 AOS_LOG(ERROR, "zeroing error\n");
Brian Silvermanab0b6772017-02-05 16:16:21 -0800297 return;
298 }
299
Adam Snaider79900c22017-02-08 20:23:15 -0800300 if (!this->initialized_) {
301 if (this->estimators_[0].offset_ready()) {
302 UpdateOffset(this->estimators_[0].offset());
303 this->initialized_ = true;
Brian Silvermanab0b6772017-02-05 16:16:21 -0800304 }
305 }
306
Adam Snaider79900c22017-02-08 20:23:15 -0800307 if (!this->zeroed(0) && this->estimators_[0].zeroed()) {
308 UpdateOffset(this->estimators_[0].offset());
309 this->set_zeroed(0, true);
Brian Silvermanab0b6772017-02-05 16:16:21 -0800310 }
311
Austin Schuh3634ed32017-02-05 16:28:49 -0800312 last_position_ = position();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700313 this->Y_ << new_position.encoder();
Adam Snaider79900c22017-02-08 20:23:15 -0800314 this->Y_ += this->offset_;
315 this->loop_->Correct(Y_);
Brian Silvermanab0b6772017-02-05 16:16:21 -0800316}
317
318template <class ZeroingEstimator>
319void SingleDOFProfiledSubsystem<ZeroingEstimator>::CapGoal(
320 const char *name, Eigen::Matrix<double, 3, 1> *goal) {
Austin Schuh3634ed32017-02-05 16:28:49 -0800321 // Limit the goal to min/max allowable positions.
Brian Silvermanab0b6772017-02-05 16:16:21 -0800322 if ((*goal)(0, 0) > range_.upper) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700323 AOS_LOG(WARNING, "Goal %s above limit, %f > %f\n", name, (*goal)(0, 0),
324 range_.upper);
Brian Silvermanab0b6772017-02-05 16:16:21 -0800325 (*goal)(0, 0) = range_.upper;
326 }
327 if ((*goal)(0, 0) < range_.lower) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700328 AOS_LOG(WARNING, "Goal %s below limit, %f < %f\n", name, (*goal)(0, 0),
Brian Silvermanab0b6772017-02-05 16:16:21 -0800329 range_.lower);
330 (*goal)(0, 0) = range_.lower;
331 }
332}
333
334template <class ZeroingEstimator>
335void SingleDOFProfiledSubsystem<ZeroingEstimator>::ForceGoal(double goal) {
336 set_unprofiled_goal(goal);
Adam Snaider79900c22017-02-08 20:23:15 -0800337 this->loop_->mutable_R() = this->unprofiled_goal_;
338 this->loop_->mutable_next_R() = this->loop_->R();
Brian Silvermanab0b6772017-02-05 16:16:21 -0800339
Adam Snaider79900c22017-02-08 20:23:15 -0800340 const ::Eigen::Matrix<double, 3, 1> &R = this->loop_->R();
341 this->profile_.MoveCurrentState(R.block<2, 1>(0, 0));
Brian Silvermanab0b6772017-02-05 16:16:21 -0800342}
343
344template <class ZeroingEstimator>
345void SingleDOFProfiledSubsystem<ZeroingEstimator>::set_unprofiled_goal(
James Kuszmaul4fb29762020-02-20 19:37:41 -0800346 double unprofiled_goal, double unprofiled_goal_velocity) {
Adam Snaider79900c22017-02-08 20:23:15 -0800347 this->unprofiled_goal_(0, 0) = unprofiled_goal;
James Kuszmaul4fb29762020-02-20 19:37:41 -0800348 this->unprofiled_goal_(1, 0) = unprofiled_goal_velocity;
Adam Snaider79900c22017-02-08 20:23:15 -0800349 this->unprofiled_goal_(2, 0) = 0.0;
350 CapGoal("unprofiled R", &this->unprofiled_goal_);
Brian Silvermanab0b6772017-02-05 16:16:21 -0800351}
352
353template <class ZeroingEstimator>
354void SingleDOFProfiledSubsystem<ZeroingEstimator>::Update(bool disable) {
Austin Schuhd5ccb862017-03-11 22:06:36 -0800355 // TODO(austin): What do we want to do with the profile on reset? Also, we
356 // should probably reset R, the offset, the profile, etc.
357 if (this->should_reset_) {
358 this->loop_->mutable_X_hat(0, 0) = Y_(0, 0);
359 this->loop_->mutable_X_hat(1, 0) = 0.0;
360 this->loop_->mutable_X_hat(2, 0) = 0.0;
361 this->should_reset_ = false;
362 }
363
Brian Silvermanab0b6772017-02-05 16:16:21 -0800364 if (!disable) {
James Kuszmaul4fb29762020-02-20 19:37:41 -0800365 if (enable_profile_) {
366 ::Eigen::Matrix<double, 2, 1> goal_state = profile_.Update(
367 this->unprofiled_goal_(0, 0), this->unprofiled_goal_(1, 0));
Brian Silvermanab0b6772017-02-05 16:16:21 -0800368
James Kuszmaul4fb29762020-02-20 19:37:41 -0800369 this->loop_->mutable_next_R(0, 0) = goal_state(0, 0);
370 this->loop_->mutable_next_R(1, 0) = goal_state(1, 0);
371 this->loop_->mutable_next_R(2, 0) = 0.0;
372 } else {
373 this->loop_->mutable_R() = this->unprofiled_goal_;
374 this->loop_->mutable_next_R() = this->unprofiled_goal_;
375 this->loop_->mutable_next_R(0, 0) +=
376 this->unprofiled_goal_(1) *
377 aos::time::DurationInSeconds(this->loop_->plant().coefficients().dt);
378 CapGoal("R", &this->loop_->mutable_R());
379 }
Adam Snaider79900c22017-02-08 20:23:15 -0800380 CapGoal("next R", &this->loop_->mutable_next_R());
Brian Silvermanab0b6772017-02-05 16:16:21 -0800381 }
382
Adam Snaider79900c22017-02-08 20:23:15 -0800383 this->loop_->Update(disable);
Brian Silvermanab0b6772017-02-05 16:16:21 -0800384
Adam Snaider79900c22017-02-08 20:23:15 -0800385 if (!disable && this->loop_->U(0, 0) != this->loop_->U_uncapped(0, 0)) {
386 const ::Eigen::Matrix<double, 3, 1> &R = this->loop_->R();
387 profile_.MoveCurrentState(R.block<2, 1>(0, 0));
Brian Silvermanab0b6772017-02-05 16:16:21 -0800388 }
389}
390
391template <class ZeroingEstimator>
392bool SingleDOFProfiledSubsystem<ZeroingEstimator>::CheckHardLimits() {
393 // Returns whether hard limits have been exceeded.
394
Austin Schuh3634ed32017-02-05 16:28:49 -0800395 if (position() > range_.upper_hard || position() < range_.lower_hard) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700396 AOS_LOG(
397 ERROR,
Brian Silvermanab0b6772017-02-05 16:16:21 -0800398 "SingleDOFProfiledSubsystem at %f out of bounds [%f, %f], ESTOPing\n",
Austin Schuh3634ed32017-02-05 16:28:49 -0800399 position(), range_.lower_hard, range_.upper_hard);
Brian Silvermanab0b6772017-02-05 16:16:21 -0800400 return true;
401 }
402
403 return false;
404}
405
406template <class ZeroingEstimator>
407void SingleDOFProfiledSubsystem<ZeroingEstimator>::AdjustProfile(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700408 const ::frc971::ProfileParameters *profile_parameters) {
409 AdjustProfile(
410 profile_parameters != nullptr ? profile_parameters->max_velocity() : 0.0,
411 profile_parameters != nullptr ? profile_parameters->max_acceleration()
412 : 0.0);
Austin Schuh3634ed32017-02-05 16:28:49 -0800413}
414
415template <class ZeroingEstimator>
416void SingleDOFProfiledSubsystem<ZeroingEstimator>::AdjustProfile(
Brian Silvermanab0b6772017-02-05 16:16:21 -0800417 double max_angular_velocity, double max_angular_acceleration) {
418 profile_.set_maximum_velocity(
419 internal::UseUnlessZero(max_angular_velocity, default_velocity_));
420 profile_.set_maximum_acceleration(
421 internal::UseUnlessZero(max_angular_acceleration, default_acceleration_));
422}
423
Austin Schuh473a5652017-02-05 01:30:42 -0800424} // namespace control_loops
425} // namespace frc971
426
427#endif // FRC971_CONTROL_LOOPS_PROFILED_SUBSYSTEM_H_