blob: dae8374b4aa3e029871ce0dcbd43170fb4970726 [file] [log] [blame]
Ben Fredrickson6b5ba792015-01-25 17:14:40 -08001#include "frc971/control_loops/fridge/fridge.h"
2
Austin Schuh703b8d42015-02-01 14:56:34 -08003#include <cmath>
4
Ben Fredrickson6b5ba792015-01-25 17:14:40 -08005#include "aos/common/controls/control_loops.q.h"
6#include "aos/common/logging/logging.h"
7
8#include "frc971/control_loops/fridge/elevator_motor_plant.h"
9#include "frc971/control_loops/fridge/arm_motor_plant.h"
Austin Schuhb966c432015-02-16 15:47:18 -080010#include "frc971/control_loops/voltage_cap/voltage_cap.h"
Austin Schuh703b8d42015-02-01 14:56:34 -080011#include "frc971/zeroing/zeroing.h"
12
13#include "frc971/constants.h"
Ben Fredrickson6b5ba792015-01-25 17:14:40 -080014
15namespace frc971 {
16namespace control_loops {
17
Austin Schuh703b8d42015-02-01 14:56:34 -080018constexpr double Fridge::dt;
19
20namespace {
Austin Schuhb966c432015-02-16 15:47:18 -080021constexpr double kZeroingVoltage = 4.0;
22constexpr double kElevatorZeroingVelocity = 0.10;
23constexpr double kArmZeroingVelocity = 0.20;
Austin Schuh703b8d42015-02-01 14:56:34 -080024} // namespace
25
26
27void CappedStateFeedbackLoop::CapU() {
Austin Schuhb966c432015-02-16 15:47:18 -080028 VoltageCap(max_voltage_, U(0, 0), U(1, 0), &mutable_U(0, 0),
29 &mutable_U(1, 0));
Austin Schuh703b8d42015-02-01 14:56:34 -080030}
31
32Eigen::Matrix<double, 2, 1>
33CappedStateFeedbackLoop::UnsaturateOutputGoalChange() {
34 // Compute the K matrix used to compensate for position errors.
35 Eigen::Matrix<double, 2, 2> Kp;
36 Kp.setZero();
37 Kp.col(0) = K().col(0);
38 Kp.col(1) = K().col(2);
39
40 Eigen::Matrix<double, 2, 2> Kp_inv = Kp.inverse();
41
42 // Compute how much we need to change R in order to achieve the change in U
43 // that was observed.
44 Eigen::Matrix<double, 2, 1> deltaR = -Kp_inv * (U_uncapped() - U());
45 return deltaR;
46}
47
Ben Fredrickson6b5ba792015-01-25 17:14:40 -080048Fridge::Fridge(control_loops::FridgeQueue *fridge)
Brian Silverman089f5812015-02-15 01:58:19 -050049 : aos::controls::ControlLoop<control_loops::FridgeQueue>(fridge),
Austin Schuh703b8d42015-02-01 14:56:34 -080050 arm_loop_(new CappedStateFeedbackLoop(
51 StateFeedbackLoop<4, 2, 2>(MakeArmLoop()))),
52 elevator_loop_(new CappedStateFeedbackLoop(
53 StateFeedbackLoop<4, 2, 2>(MakeElevatorLoop()))),
Daniel Pettia7827412015-02-13 20:55:57 -080054 left_arm_estimator_(constants::GetValues().fridge.left_arm_zeroing),
55 right_arm_estimator_(constants::GetValues().fridge.right_arm_zeroing),
Austin Schuh482a4e12015-02-14 22:43:43 -080056 left_elevator_estimator_(constants::GetValues().fridge.left_elev_zeroing),
Austin Schuh703b8d42015-02-01 14:56:34 -080057 right_elevator_estimator_(
Daniel Pettia7827412015-02-13 20:55:57 -080058 constants::GetValues().fridge.right_elev_zeroing) {}
Ben Fredrickson6b5ba792015-01-25 17:14:40 -080059
Austin Schuh703b8d42015-02-01 14:56:34 -080060void Fridge::UpdateZeroingState() {
Austin Schuh47bf6902015-02-14 22:46:22 -080061 if (left_elevator_estimator_.offset_ratio_ready() < 1.0 ||
62 right_elevator_estimator_.offset_ratio_ready() < 1.0 ||
63 left_arm_estimator_.offset_ratio_ready() < 1.0 ||
64 right_arm_estimator_.offset_ratio_ready() < 1.0) {
Austin Schuh703b8d42015-02-01 14:56:34 -080065 state_ = INITIALIZING;
66 } else if (!left_elevator_estimator_.zeroed() ||
67 !right_elevator_estimator_.zeroed()) {
68 state_ = ZEROING_ELEVATOR;
69 } else if (!left_arm_estimator_.zeroed() ||
70 !right_arm_estimator_.zeroed()) {
71 state_ = ZEROING_ARM;
72 } else {
73 state_ = RUNNING;
74 }
75}
Ben Fredrickson6b5ba792015-01-25 17:14:40 -080076
Austin Schuh703b8d42015-02-01 14:56:34 -080077void Fridge::Correct() {
78 {
79 Eigen::Matrix<double, 2, 1> Y;
80 Y << left_elevator(), right_elevator();
81 elevator_loop_->Correct(Y);
82 }
83
84 {
85 Eigen::Matrix<double, 2, 1> Y;
86 Y << left_arm(), right_arm();
87 arm_loop_->Correct(Y);
88 }
89}
90
91void Fridge::SetElevatorOffset(double left_offset, double right_offset) {
Austin Schuhdbd6bfa2015-02-14 21:25:16 -080092 LOG(INFO, "Changing Elevator offset from %f, %f to %f, %f\n",
93 left_elevator_offset_, right_elevator_offset_, left_offset, right_offset);
Austin Schuh703b8d42015-02-01 14:56:34 -080094 double left_doffset = left_offset - left_elevator_offset_;
95 double right_doffset = right_offset - right_elevator_offset_;
96
97 // Adjust the average height and height difference between the two sides.
98 // The derivatives of both should not need to be updated since the speeds
99 // haven't changed.
100 // The height difference is calculated as left - right, not right - left.
101 elevator_loop_->mutable_X_hat(0, 0) += (left_doffset + right_doffset) / 2;
102 elevator_loop_->mutable_X_hat(2, 0) += (left_doffset - right_doffset) / 2;
103
104 // Modify the zeroing goal.
105 elevator_goal_ += (left_doffset + right_doffset) / 2;
106
107 // Update the cached offset values to the actual values.
108 left_elevator_offset_ = left_offset;
109 right_elevator_offset_ = right_offset;
110}
111
112void Fridge::SetArmOffset(double left_offset, double right_offset) {
Austin Schuhdbd6bfa2015-02-14 21:25:16 -0800113 LOG(INFO, "Changing Arm offset from %f, %f to %f, %f\n", left_arm_offset_,
114 right_arm_offset_, left_offset, right_offset);
Austin Schuh703b8d42015-02-01 14:56:34 -0800115 double left_doffset = left_offset - left_arm_offset_;
116 double right_doffset = right_offset - right_arm_offset_;
117
118 // Adjust the average angle and angle difference between the two sides.
119 // The derivatives of both should not need to be updated since the speeds
120 // haven't changed.
121 arm_loop_->mutable_X_hat(0, 0) += (left_doffset + right_doffset) / 2;
122 arm_loop_->mutable_X_hat(2, 0) += (left_doffset - right_doffset) / 2;
123
124 // Modify the zeroing goal.
125 arm_goal_ += (left_doffset + right_doffset) / 2;
126
127 // Update the cached offset values to the actual values.
128 left_arm_offset_ = left_offset;
129 right_arm_offset_ = right_offset;
130}
131
132double Fridge::estimated_left_elevator() {
133 return current_position_.elevator.left.encoder +
134 left_elevator_estimator_.offset();
135}
136double Fridge::estimated_right_elevator() {
137 return current_position_.elevator.right.encoder +
138 right_elevator_estimator_.offset();
139}
140
141double Fridge::estimated_elevator() {
142 return (estimated_left_elevator() + estimated_right_elevator()) / 2.0;
143}
144
145double Fridge::estimated_left_arm() {
146 return current_position_.elevator.left.encoder + left_arm_estimator_.offset();
147}
148double Fridge::estimated_right_arm() {
149 return current_position_.elevator.right.encoder +
150 right_arm_estimator_.offset();
151}
152double Fridge::estimated_arm() {
153 return (estimated_left_arm() + estimated_right_arm()) / 2.0;
154}
155
156double Fridge::left_elevator() {
157 return current_position_.elevator.left.encoder + left_elevator_offset_;
158}
159double Fridge::right_elevator() {
160 return current_position_.elevator.right.encoder + right_elevator_offset_;
161}
162
163double Fridge::elevator() { return (left_elevator() + right_elevator()) / 2.0; }
164
165double Fridge::left_arm() {
166 return current_position_.arm.left.encoder + left_arm_offset_;
167}
168double Fridge::right_arm() {
169 return current_position_.arm.right.encoder + right_arm_offset_;
170}
171double Fridge::arm() { return (left_arm() + right_arm()) / 2.0; }
172
173double Fridge::elevator_zeroing_velocity() {
174 double average_elevator =
175 (constants::GetValues().fridge.elevator.lower_limit +
176 constants::GetValues().fridge.elevator.upper_limit) /
177 2.0;
178
179 const double pulse_width = ::std::max(
Daniel Pettia7827412015-02-13 20:55:57 -0800180 constants::GetValues().fridge.left_elev_zeroing.index_difference,
181 constants::GetValues().fridge.right_elev_zeroing.index_difference);
Austin Schuh703b8d42015-02-01 14:56:34 -0800182
183 if (elevator_zeroing_velocity_ == 0) {
184 if (estimated_elevator() > average_elevator) {
185 elevator_zeroing_velocity_ = -kElevatorZeroingVelocity;
186 } else {
187 elevator_zeroing_velocity_ = kElevatorZeroingVelocity;
188 }
189 } else if (elevator_zeroing_velocity_ > 0 &&
Austin Schuh9e37c322015-02-16 15:47:49 -0800190 estimated_elevator() > average_elevator + 1.1 * pulse_width) {
Austin Schuh703b8d42015-02-01 14:56:34 -0800191 elevator_zeroing_velocity_ = -kElevatorZeroingVelocity;
192 } else if (elevator_zeroing_velocity_ < 0 &&
Austin Schuh9e37c322015-02-16 15:47:49 -0800193 estimated_elevator() < average_elevator - 1.1 * pulse_width) {
Austin Schuh703b8d42015-02-01 14:56:34 -0800194 elevator_zeroing_velocity_ = kElevatorZeroingVelocity;
195 }
196 return elevator_zeroing_velocity_;
197}
198
199double Fridge::arm_zeroing_velocity() {
200 const double average_arm = (constants::GetValues().fridge.arm.lower_limit +
201 constants::GetValues().fridge.arm.upper_limit) /
202 2.0;
203 const double pulse_width = ::std::max(
Daniel Pettia7827412015-02-13 20:55:57 -0800204 constants::GetValues().fridge.right_arm_zeroing.index_difference,
205 constants::GetValues().fridge.left_arm_zeroing.index_difference);
Austin Schuh703b8d42015-02-01 14:56:34 -0800206
207 if (arm_zeroing_velocity_ == 0) {
208 if (estimated_arm() > average_arm) {
209 arm_zeroing_velocity_ = -kArmZeroingVelocity;
210 } else {
211 arm_zeroing_velocity_ = kArmZeroingVelocity;
212 }
213 } else if (arm_zeroing_velocity_ > 0.0 &&
Austin Schuh9e37c322015-02-16 15:47:49 -0800214 estimated_arm() > average_arm + 1.1 * pulse_width) {
Austin Schuh703b8d42015-02-01 14:56:34 -0800215 arm_zeroing_velocity_ = -kArmZeroingVelocity;
216 } else if (arm_zeroing_velocity_ < 0.0 &&
Austin Schuh9e37c322015-02-16 15:47:49 -0800217 estimated_arm() < average_arm - 1.1 * pulse_width) {
Austin Schuh703b8d42015-02-01 14:56:34 -0800218 arm_zeroing_velocity_ = kArmZeroingVelocity;
219 }
220 return arm_zeroing_velocity_;
221}
222
Austin Schuh9e37c322015-02-16 15:47:49 -0800223namespace {
224void PopulateEstimatorState(const zeroing::ZeroingEstimator &estimator,
225 EstimatorState *state) {
226 state->error = estimator.error();
227 state->zeroed = estimator.zeroed();
228 state->position = estimator.position();
229}
230} // namespace
231
Austin Schuh482a4e12015-02-14 22:43:43 -0800232void Fridge::RunIteration(const control_loops::FridgeQueue::Goal *unsafe_goal,
Austin Schuh703b8d42015-02-01 14:56:34 -0800233 const control_loops::FridgeQueue::Position *position,
234 control_loops::FridgeQueue::Output *output,
235 control_loops::FridgeQueue::Status *status) {
Austin Schuhdbd6bfa2015-02-14 21:25:16 -0800236 if (WasReset()) {
237 LOG(ERROR, "WPILib reset, restarting\n");
238 left_elevator_estimator_.Reset();
239 right_elevator_estimator_.Reset();
240 left_arm_estimator_.Reset();
241 right_arm_estimator_.Reset();
242 state_ = UNINITIALIZED;
243 }
244
Austin Schuh703b8d42015-02-01 14:56:34 -0800245 // Get a reference to the constants struct since we use it so often in this
246 // code.
Philipp Schrader82c65072015-02-16 00:47:09 +0000247 const auto &values = constants::GetValues();
Austin Schuh703b8d42015-02-01 14:56:34 -0800248
249 // Bool to track if we should turn the motors on or not.
250 bool disable = output == nullptr;
251 double elevator_goal_velocity = 0.0;
252 double arm_goal_velocity = 0.0;
253
254 // Save the current position so it can be used easily in the class.
255 current_position_ = *position;
256
257 left_elevator_estimator_.UpdateEstimate(position->elevator.left);
258 right_elevator_estimator_.UpdateEstimate(position->elevator.right);
259 left_arm_estimator_.UpdateEstimate(position->arm.left);
260 right_arm_estimator_.UpdateEstimate(position->arm.right);
261
262 if (state_ != UNINITIALIZED) {
263 Correct();
264 }
265
266 // Zeroing will work as follows:
267 // At startup, record the offset of the two halves of the two subsystems.
268 // Then, start moving the elevator towards the center until both halves are
269 // zeroed.
270 // Then, start moving the claw towards the center until both halves are
271 // zeroed.
272 // Then, done!
273
274 // We'll then need code to do sanity checking on values.
275
276 // Now, we need to figure out which way to go.
277
278 switch (state_) {
279 case UNINITIALIZED:
280 LOG(DEBUG, "Uninitialized\n");
281 // Startup. Assume that we are at the origin everywhere.
282 // This records the encoder offset between the two sides of the elevator.
283 left_elevator_offset_ = -position->elevator.left.encoder;
284 right_elevator_offset_ = -position->elevator.right.encoder;
285 left_arm_offset_ = -position->arm.left.encoder;
286 right_arm_offset_ = -position->arm.right.encoder;
Austin Schuhaab01572015-02-15 00:12:35 -0800287 elevator_loop_->mutable_X_hat().setZero();
288 arm_loop_->mutable_X_hat().setZero();
Austin Schuhdbd6bfa2015-02-14 21:25:16 -0800289 LOG(INFO, "Initializing arm offsets to %f, %f\n", left_arm_offset_,
290 right_arm_offset_);
291 LOG(INFO, "Initializing elevator offsets to %f, %f\n",
292 left_elevator_offset_, right_elevator_offset_);
Austin Schuh703b8d42015-02-01 14:56:34 -0800293 Correct();
294 state_ = INITIALIZING;
295 disable = true;
296 break;
297
298 case INITIALIZING:
299 LOG(DEBUG, "Waiting for accurate initial position.\n");
300 disable = true;
301 // Update state_ to accurately represent the state of the zeroing
302 // estimators.
303 UpdateZeroingState();
304 if (state_ != INITIALIZING) {
305 // Set the goals to where we are now.
306 elevator_goal_ = elevator();
307 arm_goal_ = arm();
308 }
309 break;
310
311 case ZEROING_ELEVATOR:
312 LOG(DEBUG, "Zeroing elevator\n");
Austin Schuh703b8d42015-02-01 14:56:34 -0800313
314 // Update state_ to accurately represent the state of the zeroing
315 // estimators.
316 UpdateZeroingState();
317 if (left_elevator_estimator_.zeroed() &&
318 right_elevator_estimator_.zeroed()) {
319 SetElevatorOffset(left_elevator_estimator_.offset(),
320 right_elevator_estimator_.offset());
321 LOG(DEBUG, "Zeroed the elevator!\n");
Austin Schuhdbd6bfa2015-02-14 21:25:16 -0800322 } else if (!disable) {
323 elevator_goal_velocity = elevator_zeroing_velocity();
324 elevator_goal_ += elevator_goal_velocity * dt;
Austin Schuh703b8d42015-02-01 14:56:34 -0800325 }
326 break;
327
328 case ZEROING_ARM:
329 LOG(DEBUG, "Zeroing the arm\n");
Austin Schuh703b8d42015-02-01 14:56:34 -0800330
331 // Update state_ to accurately represent the state of the zeroing
332 // estimators.
333 UpdateZeroingState();
334 if (left_arm_estimator_.zeroed() && right_arm_estimator_.zeroed()) {
335 SetArmOffset(left_arm_estimator_.offset(),
336 right_arm_estimator_.offset());
337 LOG(DEBUG, "Zeroed the arm!\n");
Austin Schuhdbd6bfa2015-02-14 21:25:16 -0800338 } else if (!disable) {
339 arm_goal_velocity = arm_zeroing_velocity();
340 arm_goal_ += arm_goal_velocity * dt;
Austin Schuh703b8d42015-02-01 14:56:34 -0800341 }
342 break;
343
344 case RUNNING:
345 LOG(DEBUG, "Running!\n");
Austin Schuh482a4e12015-02-14 22:43:43 -0800346 if (unsafe_goal) {
347 arm_goal_velocity = unsafe_goal->angular_velocity;
348 elevator_goal_velocity = unsafe_goal->velocity;
349 }
Austin Schuh703b8d42015-02-01 14:56:34 -0800350
351 // Update state_ to accurately represent the state of the zeroing
352 // estimators.
353 UpdateZeroingState();
Austin Schuh482a4e12015-02-14 22:43:43 -0800354 if (unsafe_goal) {
355 arm_goal_ = unsafe_goal->angle;
356 elevator_goal_ = unsafe_goal->height;
357 }
Austin Schuh703b8d42015-02-01 14:56:34 -0800358
359 if (state_ != RUNNING && state_ != ESTOP) {
360 state_ = UNINITIALIZED;
361 }
362 break;
363
364 case ESTOP:
365 LOG(ERROR, "Estop\n");
366 disable = true;
367 break;
368 }
369
370 // Commence death if either left/right tracking error gets too big. This
371 // should run immediately after the SetArmOffset and SetElevatorOffset
372 // functions to double-check that the hardware is in a sane state.
373 if (::std::abs(left_arm() - right_arm()) >=
Austin Schuhdbd6bfa2015-02-14 21:25:16 -0800374 values.max_allowed_left_right_arm_difference) {
375 LOG(ERROR, "The arms are too far apart. |%f - %f| > %f\n", left_arm(),
376 right_arm(), values.max_allowed_left_right_arm_difference);
377
378 // Indicate an ESTOP condition and stop the motors.
379 state_ = ESTOP;
380 disable = true;
381 }
382
383 if (::std::abs(left_elevator() - right_elevator()) >=
384 values.max_allowed_left_right_elevator_difference) {
385 LOG(ERROR, "The elevators are too far apart. |%f - %f| > %f\n",
386 left_elevator(), right_elevator(),
387 values.max_allowed_left_right_elevator_difference);
Austin Schuh703b8d42015-02-01 14:56:34 -0800388
389 // Indicate an ESTOP condition and stop the motors.
390 state_ = ESTOP;
391 disable = true;
392 }
393
394 // Limit the goals so we can't exceed the hardware limits if we are RUNNING.
395 if (state_ == RUNNING) {
396 // Limit the arm goal to min/max allowable angles.
397 if (arm_goal_ >= values.fridge.arm.upper_limit) {
398 LOG(WARNING, "Arm goal above limit, %f > %f\n", arm_goal_,
399 values.fridge.arm.upper_limit);
400 arm_goal_ = values.fridge.arm.upper_limit;
401 }
402 if (arm_goal_ <= values.fridge.arm.lower_limit) {
403 LOG(WARNING, "Arm goal below limit, %f < %f\n", arm_goal_,
404 values.fridge.arm.lower_limit);
405 arm_goal_ = values.fridge.arm.lower_limit;
406 }
407
408 // Limit the elevator goal to min/max allowable heights.
409 if (elevator_goal_ >= values.fridge.elevator.upper_limit) {
410 LOG(WARNING, "Elevator goal above limit, %f > %f\n", elevator_goal_,
411 values.fridge.elevator.upper_limit);
412 elevator_goal_ = values.fridge.elevator.upper_limit;
413 }
414 if (elevator_goal_ <= values.fridge.elevator.lower_limit) {
415 LOG(WARNING, "Elevator goal below limit, %f < %f\n", elevator_goal_,
416 values.fridge.elevator.lower_limit);
417 elevator_goal_ = values.fridge.elevator.lower_limit;
418 }
419 }
420
421 // Check the lower level hardware limit as well.
422 if (state_ == RUNNING) {
423 if (left_arm() >= values.fridge.arm.upper_hard_limit ||
424 left_arm() <= values.fridge.arm.lower_hard_limit) {
425 LOG(ERROR, "Left arm at %f out of bounds [%f, %f], ESTOPing\n",
426 left_arm(), values.fridge.arm.lower_hard_limit,
427 values.fridge.arm.upper_hard_limit);
428 state_ = ESTOP;
429 }
430
431 if (right_arm() >= values.fridge.arm.upper_hard_limit ||
432 right_arm() <= values.fridge.arm.lower_hard_limit) {
433 LOG(ERROR, "Right arm at %f out of bounds [%f, %f], ESTOPing\n",
434 right_arm(), values.fridge.arm.lower_hard_limit,
435 values.fridge.arm.upper_hard_limit);
436 state_ = ESTOP;
437 }
438
439 if (left_elevator() >= values.fridge.elevator.upper_hard_limit ||
440 left_elevator() <= values.fridge.elevator.lower_hard_limit) {
441 LOG(ERROR, "Left elevator at %f out of bounds [%f, %f], ESTOPing\n",
442 left_elevator(), values.fridge.elevator.lower_hard_limit,
443 values.fridge.elevator.upper_hard_limit);
444 state_ = ESTOP;
445 }
446
447 if (right_elevator() >= values.fridge.elevator.upper_hard_limit ||
448 right_elevator() <= values.fridge.elevator.lower_hard_limit) {
449 LOG(ERROR, "Right elevator at %f out of bounds [%f, %f], ESTOPing\n",
450 right_elevator(), values.fridge.elevator.lower_hard_limit,
451 values.fridge.elevator.upper_hard_limit);
452 state_ = ESTOP;
453 }
454 }
455
456 // Set the goals.
457 arm_loop_->mutable_R() << arm_goal_, arm_goal_velocity, 0.0, 0.0;
458 elevator_loop_->mutable_R() << elevator_goal_, elevator_goal_velocity, 0.0,
459 0.0;
460
461 const double max_voltage = state_ == RUNNING ? 12.0 : kZeroingVoltage;
462 arm_loop_->set_max_voltage(max_voltage);
463 elevator_loop_->set_max_voltage(max_voltage);
464
465 if (state_ == ESTOP) {
466 disable = true;
467 }
468 arm_loop_->Update(disable);
469 elevator_loop_->Update(disable);
470
471 if (state_ == INITIALIZING || state_ == ZEROING_ELEVATOR ||
472 state_ == ZEROING_ARM) {
473 if (arm_loop_->U() != arm_loop_->U_uncapped()) {
474 Eigen::Matrix<double, 2, 1> deltaR =
475 arm_loop_->UnsaturateOutputGoalChange();
476
477 // Move the average arm goal by the amount observed.
478 LOG(WARNING, "Moving arm goal by %f to handle saturation\n",
479 deltaR(0, 0));
480 arm_goal_ += deltaR(0, 0);
481 }
482
483 if (elevator_loop_->U() != elevator_loop_->U_uncapped()) {
484 Eigen::Matrix<double, 2, 1> deltaR =
485 elevator_loop_->UnsaturateOutputGoalChange();
486
487 // Move the average elevator goal by the amount observed.
488 LOG(WARNING, "Moving elevator goal by %f to handle saturation\n",
489 deltaR(0, 0));
490 elevator_goal_ += deltaR(0, 0);
491 }
492 }
493
494 if (output) {
495 output->left_arm = arm_loop_->U(0, 0);
496 output->right_arm = arm_loop_->U(1, 0);
497 output->left_elevator = elevator_loop_->U(0, 0);
498 output->right_elevator = elevator_loop_->U(1, 0);
Austin Schuh482a4e12015-02-14 22:43:43 -0800499 if (unsafe_goal) {
500 output->grabbers = unsafe_goal->grabbers;
501 } else {
502 output->grabbers.top_front = false;
503 output->grabbers.top_back = false;
504 output->grabbers.bottom_front = false;
505 output->grabbers.bottom_back = false;
506 }
Austin Schuh703b8d42015-02-01 14:56:34 -0800507 }
508
509 // TODO(austin): Populate these fully.
Austin Schuh5ae4efd2015-02-15 23:34:22 -0800510 status->zeroed = state_ == RUNNING;
Austin Schuh703b8d42015-02-01 14:56:34 -0800511 status->angle = arm_loop_->X_hat(0, 0);
512 status->height = elevator_loop_->X_hat(0, 0);
Austin Schuh482a4e12015-02-14 22:43:43 -0800513 if (unsafe_goal) {
514 status->grabbers = unsafe_goal->grabbers;
515 } else {
516 status->grabbers.top_front = false;
517 status->grabbers.top_back = false;
518 status->grabbers.bottom_front = false;
519 status->grabbers.bottom_back = false;
520 }
Austin Schuh9e37c322015-02-16 15:47:49 -0800521 PopulateEstimatorState(left_arm_estimator_, &status->left_arm_state);
522 PopulateEstimatorState(right_arm_estimator_, &status->right_arm_state);
523 PopulateEstimatorState(left_elevator_estimator_,
524 &status->left_elevator_state);
525 PopulateEstimatorState(right_elevator_estimator_,
526 &status->right_elevator_state);
Austin Schuh703b8d42015-02-01 14:56:34 -0800527 status->estopped = (state_ == ESTOP);
Austin Schuh482a4e12015-02-14 22:43:43 -0800528 status->state = state_;
Austin Schuh703b8d42015-02-01 14:56:34 -0800529 last_state_ = state_;
Ben Fredrickson6b5ba792015-01-25 17:14:40 -0800530}
531
532} // namespace control_loops
533} // namespace frc971