blob: a76f06a910cbbc8095324e0b8ed8719402715574 [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 &&
190 estimated_elevator() > average_elevator + 2 * pulse_width) {
191 elevator_zeroing_velocity_ = -kElevatorZeroingVelocity;
192 } else if (elevator_zeroing_velocity_ < 0 &&
193 estimated_elevator() < average_elevator - 2 * pulse_width) {
194 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 &&
214 estimated_arm() > average_arm + 2.0 * pulse_width) {
215 arm_zeroing_velocity_ = -kArmZeroingVelocity;
216 } else if (arm_zeroing_velocity_ < 0.0 &&
217 estimated_arm() < average_arm - 2.0 * pulse_width) {
218 arm_zeroing_velocity_ = kArmZeroingVelocity;
219 }
220 return arm_zeroing_velocity_;
221}
222
Austin Schuh482a4e12015-02-14 22:43:43 -0800223void Fridge::RunIteration(const control_loops::FridgeQueue::Goal *unsafe_goal,
Austin Schuh703b8d42015-02-01 14:56:34 -0800224 const control_loops::FridgeQueue::Position *position,
225 control_loops::FridgeQueue::Output *output,
226 control_loops::FridgeQueue::Status *status) {
Austin Schuhdbd6bfa2015-02-14 21:25:16 -0800227 if (WasReset()) {
228 LOG(ERROR, "WPILib reset, restarting\n");
229 left_elevator_estimator_.Reset();
230 right_elevator_estimator_.Reset();
231 left_arm_estimator_.Reset();
232 right_arm_estimator_.Reset();
233 state_ = UNINITIALIZED;
234 }
235
Austin Schuh703b8d42015-02-01 14:56:34 -0800236 // Get a reference to the constants struct since we use it so often in this
237 // code.
Philipp Schrader82c65072015-02-16 00:47:09 +0000238 const auto &values = constants::GetValues();
Austin Schuh703b8d42015-02-01 14:56:34 -0800239
240 // Bool to track if we should turn the motors on or not.
241 bool disable = output == nullptr;
242 double elevator_goal_velocity = 0.0;
243 double arm_goal_velocity = 0.0;
244
245 // Save the current position so it can be used easily in the class.
246 current_position_ = *position;
247
248 left_elevator_estimator_.UpdateEstimate(position->elevator.left);
249 right_elevator_estimator_.UpdateEstimate(position->elevator.right);
250 left_arm_estimator_.UpdateEstimate(position->arm.left);
251 right_arm_estimator_.UpdateEstimate(position->arm.right);
252
253 if (state_ != UNINITIALIZED) {
254 Correct();
255 }
256
257 // Zeroing will work as follows:
258 // At startup, record the offset of the two halves of the two subsystems.
259 // Then, start moving the elevator towards the center until both halves are
260 // zeroed.
261 // Then, start moving the claw towards the center until both halves are
262 // zeroed.
263 // Then, done!
264
265 // We'll then need code to do sanity checking on values.
266
267 // Now, we need to figure out which way to go.
268
269 switch (state_) {
270 case UNINITIALIZED:
271 LOG(DEBUG, "Uninitialized\n");
272 // Startup. Assume that we are at the origin everywhere.
273 // This records the encoder offset between the two sides of the elevator.
274 left_elevator_offset_ = -position->elevator.left.encoder;
275 right_elevator_offset_ = -position->elevator.right.encoder;
276 left_arm_offset_ = -position->arm.left.encoder;
277 right_arm_offset_ = -position->arm.right.encoder;
Austin Schuhaab01572015-02-15 00:12:35 -0800278 elevator_loop_->mutable_X_hat().setZero();
279 arm_loop_->mutable_X_hat().setZero();
Austin Schuhdbd6bfa2015-02-14 21:25:16 -0800280 LOG(INFO, "Initializing arm offsets to %f, %f\n", left_arm_offset_,
281 right_arm_offset_);
282 LOG(INFO, "Initializing elevator offsets to %f, %f\n",
283 left_elevator_offset_, right_elevator_offset_);
Austin Schuh703b8d42015-02-01 14:56:34 -0800284 Correct();
285 state_ = INITIALIZING;
286 disable = true;
287 break;
288
289 case INITIALIZING:
290 LOG(DEBUG, "Waiting for accurate initial position.\n");
291 disable = true;
292 // Update state_ to accurately represent the state of the zeroing
293 // estimators.
294 UpdateZeroingState();
295 if (state_ != INITIALIZING) {
296 // Set the goals to where we are now.
297 elevator_goal_ = elevator();
298 arm_goal_ = arm();
299 }
300 break;
301
302 case ZEROING_ELEVATOR:
303 LOG(DEBUG, "Zeroing elevator\n");
Austin Schuh703b8d42015-02-01 14:56:34 -0800304
305 // Update state_ to accurately represent the state of the zeroing
306 // estimators.
307 UpdateZeroingState();
308 if (left_elevator_estimator_.zeroed() &&
309 right_elevator_estimator_.zeroed()) {
310 SetElevatorOffset(left_elevator_estimator_.offset(),
311 right_elevator_estimator_.offset());
312 LOG(DEBUG, "Zeroed the elevator!\n");
Austin Schuhdbd6bfa2015-02-14 21:25:16 -0800313 } else if (!disable) {
314 elevator_goal_velocity = elevator_zeroing_velocity();
315 elevator_goal_ += elevator_goal_velocity * dt;
Austin Schuh703b8d42015-02-01 14:56:34 -0800316 }
317 break;
318
319 case ZEROING_ARM:
320 LOG(DEBUG, "Zeroing the arm\n");
Austin Schuh703b8d42015-02-01 14:56:34 -0800321
322 // Update state_ to accurately represent the state of the zeroing
323 // estimators.
324 UpdateZeroingState();
325 if (left_arm_estimator_.zeroed() && right_arm_estimator_.zeroed()) {
326 SetArmOffset(left_arm_estimator_.offset(),
327 right_arm_estimator_.offset());
328 LOG(DEBUG, "Zeroed the arm!\n");
Austin Schuhdbd6bfa2015-02-14 21:25:16 -0800329 } else if (!disable) {
330 arm_goal_velocity = arm_zeroing_velocity();
331 arm_goal_ += arm_goal_velocity * dt;
Austin Schuh703b8d42015-02-01 14:56:34 -0800332 }
333 break;
334
335 case RUNNING:
336 LOG(DEBUG, "Running!\n");
Austin Schuh482a4e12015-02-14 22:43:43 -0800337 if (unsafe_goal) {
338 arm_goal_velocity = unsafe_goal->angular_velocity;
339 elevator_goal_velocity = unsafe_goal->velocity;
340 }
Austin Schuh703b8d42015-02-01 14:56:34 -0800341
342 // Update state_ to accurately represent the state of the zeroing
343 // estimators.
344 UpdateZeroingState();
Austin Schuh482a4e12015-02-14 22:43:43 -0800345 if (unsafe_goal) {
346 arm_goal_ = unsafe_goal->angle;
347 elevator_goal_ = unsafe_goal->height;
348 }
Austin Schuh703b8d42015-02-01 14:56:34 -0800349
350 if (state_ != RUNNING && state_ != ESTOP) {
351 state_ = UNINITIALIZED;
352 }
353 break;
354
355 case ESTOP:
356 LOG(ERROR, "Estop\n");
357 disable = true;
358 break;
359 }
360
361 // Commence death if either left/right tracking error gets too big. This
362 // should run immediately after the SetArmOffset and SetElevatorOffset
363 // functions to double-check that the hardware is in a sane state.
364 if (::std::abs(left_arm() - right_arm()) >=
Austin Schuhdbd6bfa2015-02-14 21:25:16 -0800365 values.max_allowed_left_right_arm_difference) {
366 LOG(ERROR, "The arms are too far apart. |%f - %f| > %f\n", left_arm(),
367 right_arm(), values.max_allowed_left_right_arm_difference);
368
369 // Indicate an ESTOP condition and stop the motors.
370 state_ = ESTOP;
371 disable = true;
372 }
373
374 if (::std::abs(left_elevator() - right_elevator()) >=
375 values.max_allowed_left_right_elevator_difference) {
376 LOG(ERROR, "The elevators are too far apart. |%f - %f| > %f\n",
377 left_elevator(), right_elevator(),
378 values.max_allowed_left_right_elevator_difference);
Austin Schuh703b8d42015-02-01 14:56:34 -0800379
380 // Indicate an ESTOP condition and stop the motors.
381 state_ = ESTOP;
382 disable = true;
383 }
384
385 // Limit the goals so we can't exceed the hardware limits if we are RUNNING.
386 if (state_ == RUNNING) {
387 // Limit the arm goal to min/max allowable angles.
388 if (arm_goal_ >= values.fridge.arm.upper_limit) {
389 LOG(WARNING, "Arm goal above limit, %f > %f\n", arm_goal_,
390 values.fridge.arm.upper_limit);
391 arm_goal_ = values.fridge.arm.upper_limit;
392 }
393 if (arm_goal_ <= values.fridge.arm.lower_limit) {
394 LOG(WARNING, "Arm goal below limit, %f < %f\n", arm_goal_,
395 values.fridge.arm.lower_limit);
396 arm_goal_ = values.fridge.arm.lower_limit;
397 }
398
399 // Limit the elevator goal to min/max allowable heights.
400 if (elevator_goal_ >= values.fridge.elevator.upper_limit) {
401 LOG(WARNING, "Elevator goal above limit, %f > %f\n", elevator_goal_,
402 values.fridge.elevator.upper_limit);
403 elevator_goal_ = values.fridge.elevator.upper_limit;
404 }
405 if (elevator_goal_ <= values.fridge.elevator.lower_limit) {
406 LOG(WARNING, "Elevator goal below limit, %f < %f\n", elevator_goal_,
407 values.fridge.elevator.lower_limit);
408 elevator_goal_ = values.fridge.elevator.lower_limit;
409 }
410 }
411
412 // Check the lower level hardware limit as well.
413 if (state_ == RUNNING) {
414 if (left_arm() >= values.fridge.arm.upper_hard_limit ||
415 left_arm() <= values.fridge.arm.lower_hard_limit) {
416 LOG(ERROR, "Left arm at %f out of bounds [%f, %f], ESTOPing\n",
417 left_arm(), values.fridge.arm.lower_hard_limit,
418 values.fridge.arm.upper_hard_limit);
419 state_ = ESTOP;
420 }
421
422 if (right_arm() >= values.fridge.arm.upper_hard_limit ||
423 right_arm() <= values.fridge.arm.lower_hard_limit) {
424 LOG(ERROR, "Right arm at %f out of bounds [%f, %f], ESTOPing\n",
425 right_arm(), values.fridge.arm.lower_hard_limit,
426 values.fridge.arm.upper_hard_limit);
427 state_ = ESTOP;
428 }
429
430 if (left_elevator() >= values.fridge.elevator.upper_hard_limit ||
431 left_elevator() <= values.fridge.elevator.lower_hard_limit) {
432 LOG(ERROR, "Left elevator at %f out of bounds [%f, %f], ESTOPing\n",
433 left_elevator(), values.fridge.elevator.lower_hard_limit,
434 values.fridge.elevator.upper_hard_limit);
435 state_ = ESTOP;
436 }
437
438 if (right_elevator() >= values.fridge.elevator.upper_hard_limit ||
439 right_elevator() <= values.fridge.elevator.lower_hard_limit) {
440 LOG(ERROR, "Right elevator at %f out of bounds [%f, %f], ESTOPing\n",
441 right_elevator(), values.fridge.elevator.lower_hard_limit,
442 values.fridge.elevator.upper_hard_limit);
443 state_ = ESTOP;
444 }
445 }
446
447 // Set the goals.
448 arm_loop_->mutable_R() << arm_goal_, arm_goal_velocity, 0.0, 0.0;
449 elevator_loop_->mutable_R() << elevator_goal_, elevator_goal_velocity, 0.0,
450 0.0;
451
452 const double max_voltage = state_ == RUNNING ? 12.0 : kZeroingVoltage;
453 arm_loop_->set_max_voltage(max_voltage);
454 elevator_loop_->set_max_voltage(max_voltage);
455
456 if (state_ == ESTOP) {
457 disable = true;
458 }
459 arm_loop_->Update(disable);
460 elevator_loop_->Update(disable);
461
462 if (state_ == INITIALIZING || state_ == ZEROING_ELEVATOR ||
463 state_ == ZEROING_ARM) {
464 if (arm_loop_->U() != arm_loop_->U_uncapped()) {
465 Eigen::Matrix<double, 2, 1> deltaR =
466 arm_loop_->UnsaturateOutputGoalChange();
467
468 // Move the average arm goal by the amount observed.
469 LOG(WARNING, "Moving arm goal by %f to handle saturation\n",
470 deltaR(0, 0));
471 arm_goal_ += deltaR(0, 0);
472 }
473
474 if (elevator_loop_->U() != elevator_loop_->U_uncapped()) {
475 Eigen::Matrix<double, 2, 1> deltaR =
476 elevator_loop_->UnsaturateOutputGoalChange();
477
478 // Move the average elevator goal by the amount observed.
479 LOG(WARNING, "Moving elevator goal by %f to handle saturation\n",
480 deltaR(0, 0));
481 elevator_goal_ += deltaR(0, 0);
482 }
483 }
484
485 if (output) {
486 output->left_arm = arm_loop_->U(0, 0);
487 output->right_arm = arm_loop_->U(1, 0);
488 output->left_elevator = elevator_loop_->U(0, 0);
489 output->right_elevator = elevator_loop_->U(1, 0);
Austin Schuh482a4e12015-02-14 22:43:43 -0800490 if (unsafe_goal) {
491 output->grabbers = unsafe_goal->grabbers;
492 } else {
493 output->grabbers.top_front = false;
494 output->grabbers.top_back = false;
495 output->grabbers.bottom_front = false;
496 output->grabbers.bottom_back = false;
497 }
Austin Schuh703b8d42015-02-01 14:56:34 -0800498 }
499
500 // TODO(austin): Populate these fully.
Austin Schuh5ae4efd2015-02-15 23:34:22 -0800501 status->zeroed = state_ == RUNNING;
Austin Schuh703b8d42015-02-01 14:56:34 -0800502 status->angle = arm_loop_->X_hat(0, 0);
503 status->height = elevator_loop_->X_hat(0, 0);
Austin Schuh482a4e12015-02-14 22:43:43 -0800504 if (unsafe_goal) {
505 status->grabbers = unsafe_goal->grabbers;
506 } else {
507 status->grabbers.top_front = false;
508 status->grabbers.top_back = false;
509 status->grabbers.bottom_front = false;
510 status->grabbers.bottom_back = false;
511 }
Austin Schuh703b8d42015-02-01 14:56:34 -0800512 status->estopped = (state_ == ESTOP);
Austin Schuh482a4e12015-02-14 22:43:43 -0800513 status->state = state_;
Austin Schuh703b8d42015-02-01 14:56:34 -0800514 last_state_ = state_;
Ben Fredrickson6b5ba792015-01-25 17:14:40 -0800515}
516
517} // namespace control_loops
518} // namespace frc971