Ben Fredrickson | 6b5ba79 | 2015-01-25 17:14:40 -0800 | [diff] [blame] | 1 | #include "frc971/control_loops/fridge/fridge.h" |
| 2 | |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 3 | #include <cmath> |
| 4 | |
Ben Fredrickson | 6b5ba79 | 2015-01-25 17:14:40 -0800 | [diff] [blame] | 5 | #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" |
Austin Schuh | 8de10c7 | 2015-02-27 23:33:40 -0800 | [diff] [blame] | 9 | #include "frc971/control_loops/fridge/integral_arm_plant.h" |
Austin Schuh | b966c43 | 2015-02-16 15:47:18 -0800 | [diff] [blame] | 10 | #include "frc971/control_loops/voltage_cap/voltage_cap.h" |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 11 | #include "frc971/zeroing/zeroing.h" |
| 12 | |
| 13 | #include "frc971/constants.h" |
Ben Fredrickson | 6b5ba79 | 2015-01-25 17:14:40 -0800 | [diff] [blame] | 14 | |
| 15 | namespace frc971 { |
| 16 | namespace control_loops { |
| 17 | |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 18 | namespace { |
Austin Schuh | b966c43 | 2015-02-16 15:47:18 -0800 | [diff] [blame] | 19 | constexpr double kZeroingVoltage = 4.0; |
| 20 | constexpr double kElevatorZeroingVelocity = 0.10; |
Daniel Petti | e1bb13e | 2015-02-17 13:59:15 -0800 | [diff] [blame] | 21 | // What speed we move to our safe height at. |
| 22 | constexpr double kElevatorSafeHeightVelocity = 0.2; |
Austin Schuh | b966c43 | 2015-02-16 15:47:18 -0800 | [diff] [blame] | 23 | constexpr double kArmZeroingVelocity = 0.20; |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 24 | } // namespace |
| 25 | |
Austin Schuh | 8de10c7 | 2015-02-27 23:33:40 -0800 | [diff] [blame] | 26 | template <int S> |
| 27 | void CappedStateFeedbackLoop<S>::CapU() { |
| 28 | VoltageCap(max_voltage_, this->U(0, 0), this->U(1, 0), &this->mutable_U(0, 0), |
| 29 | &this->mutable_U(1, 0)); |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 30 | } |
| 31 | |
Austin Schuh | 8de10c7 | 2015-02-27 23:33:40 -0800 | [diff] [blame] | 32 | template <int S> |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 33 | Eigen::Matrix<double, 2, 1> |
Austin Schuh | 8de10c7 | 2015-02-27 23:33:40 -0800 | [diff] [blame] | 34 | CappedStateFeedbackLoop<S>::UnsaturateOutputGoalChange() { |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 35 | // Compute the K matrix used to compensate for position errors. |
| 36 | Eigen::Matrix<double, 2, 2> Kp; |
| 37 | Kp.setZero(); |
Austin Schuh | 8de10c7 | 2015-02-27 23:33:40 -0800 | [diff] [blame] | 38 | Kp.col(0) = this->K().col(0); |
| 39 | Kp.col(1) = this->K().col(2); |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 40 | |
| 41 | Eigen::Matrix<double, 2, 2> Kp_inv = Kp.inverse(); |
| 42 | |
| 43 | // Compute how much we need to change R in order to achieve the change in U |
| 44 | // that was observed. |
Austin Schuh | 8de10c7 | 2015-02-27 23:33:40 -0800 | [diff] [blame] | 45 | Eigen::Matrix<double, 2, 1> deltaR = |
| 46 | -Kp_inv * (this->U_uncapped() - this->U()); |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 47 | return deltaR; |
| 48 | } |
| 49 | |
Ben Fredrickson | 6b5ba79 | 2015-01-25 17:14:40 -0800 | [diff] [blame] | 50 | Fridge::Fridge(control_loops::FridgeQueue *fridge) |
Brian Silverman | 089f581 | 2015-02-15 01:58:19 -0500 | [diff] [blame] | 51 | : aos::controls::ControlLoop<control_loops::FridgeQueue>(fridge), |
Austin Schuh | 8de10c7 | 2015-02-27 23:33:40 -0800 | [diff] [blame] | 52 | arm_loop_(new CappedStateFeedbackLoop<5>( |
| 53 | StateFeedbackLoop<5, 2, 2>(MakeIntegralArmLoop()))), |
| 54 | elevator_loop_(new CappedStateFeedbackLoop<4>( |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 55 | StateFeedbackLoop<4, 2, 2>(MakeElevatorLoop()))), |
Daniel Petti | a782741 | 2015-02-13 20:55:57 -0800 | [diff] [blame] | 56 | left_arm_estimator_(constants::GetValues().fridge.left_arm_zeroing), |
| 57 | right_arm_estimator_(constants::GetValues().fridge.right_arm_zeroing), |
Austin Schuh | 482a4e1 | 2015-02-14 22:43:43 -0800 | [diff] [blame] | 58 | left_elevator_estimator_(constants::GetValues().fridge.left_elev_zeroing), |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 59 | right_elevator_estimator_( |
Philipp Schrader | 3e28141 | 2015-03-01 23:48:23 +0000 | [diff] [blame] | 60 | constants::GetValues().fridge.right_elev_zeroing), |
Philipp Schrader | 085bf01 | 2015-03-15 01:43:11 +0000 | [diff] [blame^] | 61 | last_profiling_type_(ProfilingType::ANGLE_HEIGHT_PROFILING), |
| 62 | kinematics_(constants::GetValues().fridge.arm_length, |
| 63 | constants::GetValues().fridge.elevator.upper_limit, |
| 64 | constants::GetValues().fridge.elevator.lower_limit, |
| 65 | constants::GetValues().fridge.arm.upper_limit, |
| 66 | constants::GetValues().fridge.arm.lower_limit), |
Philipp Schrader | 3e28141 | 2015-03-01 23:48:23 +0000 | [diff] [blame] | 67 | arm_profile_(::aos::controls::kLoopFrequency), |
Philipp Schrader | 085bf01 | 2015-03-15 01:43:11 +0000 | [diff] [blame^] | 68 | elevator_profile_(::aos::controls::kLoopFrequency), |
| 69 | x_profile_(::aos::controls::kLoopFrequency), |
| 70 | y_profile_(::aos::controls::kLoopFrequency) {} |
Ben Fredrickson | 6b5ba79 | 2015-01-25 17:14:40 -0800 | [diff] [blame] | 71 | |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 72 | void Fridge::UpdateZeroingState() { |
Austin Schuh | 47bf690 | 2015-02-14 22:46:22 -0800 | [diff] [blame] | 73 | if (left_elevator_estimator_.offset_ratio_ready() < 1.0 || |
| 74 | right_elevator_estimator_.offset_ratio_ready() < 1.0 || |
| 75 | left_arm_estimator_.offset_ratio_ready() < 1.0 || |
| 76 | right_arm_estimator_.offset_ratio_ready() < 1.0) { |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 77 | state_ = INITIALIZING; |
| 78 | } else if (!left_elevator_estimator_.zeroed() || |
Adam Snaider | 3cd11c5 | 2015-02-16 02:16:09 +0000 | [diff] [blame] | 79 | !right_elevator_estimator_.zeroed()) { |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 80 | state_ = ZEROING_ELEVATOR; |
Adam Snaider | 3cd11c5 | 2015-02-16 02:16:09 +0000 | [diff] [blame] | 81 | } else if (!left_arm_estimator_.zeroed() || !right_arm_estimator_.zeroed()) { |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 82 | state_ = ZEROING_ARM; |
| 83 | } else { |
| 84 | state_ = RUNNING; |
| 85 | } |
| 86 | } |
Ben Fredrickson | 6b5ba79 | 2015-01-25 17:14:40 -0800 | [diff] [blame] | 87 | |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 88 | void Fridge::Correct() { |
| 89 | { |
| 90 | Eigen::Matrix<double, 2, 1> Y; |
| 91 | Y << left_elevator(), right_elevator(); |
| 92 | elevator_loop_->Correct(Y); |
| 93 | } |
| 94 | |
| 95 | { |
| 96 | Eigen::Matrix<double, 2, 1> Y; |
| 97 | Y << left_arm(), right_arm(); |
| 98 | arm_loop_->Correct(Y); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | void Fridge::SetElevatorOffset(double left_offset, double right_offset) { |
Austin Schuh | dbd6bfa | 2015-02-14 21:25:16 -0800 | [diff] [blame] | 103 | LOG(INFO, "Changing Elevator offset from %f, %f to %f, %f\n", |
| 104 | left_elevator_offset_, right_elevator_offset_, left_offset, right_offset); |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 105 | double left_doffset = left_offset - left_elevator_offset_; |
| 106 | double right_doffset = right_offset - right_elevator_offset_; |
| 107 | |
| 108 | // Adjust the average height and height difference between the two sides. |
| 109 | // The derivatives of both should not need to be updated since the speeds |
| 110 | // haven't changed. |
| 111 | // The height difference is calculated as left - right, not right - left. |
| 112 | elevator_loop_->mutable_X_hat(0, 0) += (left_doffset + right_doffset) / 2; |
| 113 | elevator_loop_->mutable_X_hat(2, 0) += (left_doffset - right_doffset) / 2; |
| 114 | |
| 115 | // Modify the zeroing goal. |
| 116 | elevator_goal_ += (left_doffset + right_doffset) / 2; |
| 117 | |
| 118 | // Update the cached offset values to the actual values. |
| 119 | left_elevator_offset_ = left_offset; |
| 120 | right_elevator_offset_ = right_offset; |
| 121 | } |
| 122 | |
| 123 | void Fridge::SetArmOffset(double left_offset, double right_offset) { |
Austin Schuh | dbd6bfa | 2015-02-14 21:25:16 -0800 | [diff] [blame] | 124 | LOG(INFO, "Changing Arm offset from %f, %f to %f, %f\n", left_arm_offset_, |
| 125 | right_arm_offset_, left_offset, right_offset); |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 126 | double left_doffset = left_offset - left_arm_offset_; |
| 127 | double right_doffset = right_offset - right_arm_offset_; |
| 128 | |
| 129 | // Adjust the average angle and angle difference between the two sides. |
| 130 | // The derivatives of both should not need to be updated since the speeds |
| 131 | // haven't changed. |
| 132 | arm_loop_->mutable_X_hat(0, 0) += (left_doffset + right_doffset) / 2; |
| 133 | arm_loop_->mutable_X_hat(2, 0) += (left_doffset - right_doffset) / 2; |
| 134 | |
| 135 | // Modify the zeroing goal. |
| 136 | arm_goal_ += (left_doffset + right_doffset) / 2; |
| 137 | |
| 138 | // Update the cached offset values to the actual values. |
| 139 | left_arm_offset_ = left_offset; |
| 140 | right_arm_offset_ = right_offset; |
| 141 | } |
| 142 | |
| 143 | double Fridge::estimated_left_elevator() { |
| 144 | return current_position_.elevator.left.encoder + |
| 145 | left_elevator_estimator_.offset(); |
| 146 | } |
| 147 | double Fridge::estimated_right_elevator() { |
| 148 | return current_position_.elevator.right.encoder + |
| 149 | right_elevator_estimator_.offset(); |
| 150 | } |
| 151 | |
| 152 | double Fridge::estimated_elevator() { |
| 153 | return (estimated_left_elevator() + estimated_right_elevator()) / 2.0; |
| 154 | } |
| 155 | |
| 156 | double Fridge::estimated_left_arm() { |
| 157 | return current_position_.elevator.left.encoder + left_arm_estimator_.offset(); |
| 158 | } |
| 159 | double Fridge::estimated_right_arm() { |
| 160 | return current_position_.elevator.right.encoder + |
| 161 | right_arm_estimator_.offset(); |
| 162 | } |
| 163 | double Fridge::estimated_arm() { |
| 164 | return (estimated_left_arm() + estimated_right_arm()) / 2.0; |
| 165 | } |
| 166 | |
| 167 | double Fridge::left_elevator() { |
| 168 | return current_position_.elevator.left.encoder + left_elevator_offset_; |
| 169 | } |
| 170 | double Fridge::right_elevator() { |
| 171 | return current_position_.elevator.right.encoder + right_elevator_offset_; |
| 172 | } |
| 173 | |
| 174 | double Fridge::elevator() { return (left_elevator() + right_elevator()) / 2.0; } |
| 175 | |
| 176 | double Fridge::left_arm() { |
| 177 | return current_position_.arm.left.encoder + left_arm_offset_; |
| 178 | } |
| 179 | double Fridge::right_arm() { |
| 180 | return current_position_.arm.right.encoder + right_arm_offset_; |
| 181 | } |
| 182 | double Fridge::arm() { return (left_arm() + right_arm()) / 2.0; } |
| 183 | |
| 184 | double Fridge::elevator_zeroing_velocity() { |
| 185 | double average_elevator = |
| 186 | (constants::GetValues().fridge.elevator.lower_limit + |
| 187 | constants::GetValues().fridge.elevator.upper_limit) / |
| 188 | 2.0; |
| 189 | |
| 190 | const double pulse_width = ::std::max( |
Daniel Petti | a782741 | 2015-02-13 20:55:57 -0800 | [diff] [blame] | 191 | constants::GetValues().fridge.left_elev_zeroing.index_difference, |
| 192 | constants::GetValues().fridge.right_elev_zeroing.index_difference); |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 193 | |
| 194 | if (elevator_zeroing_velocity_ == 0) { |
| 195 | if (estimated_elevator() > average_elevator) { |
| 196 | elevator_zeroing_velocity_ = -kElevatorZeroingVelocity; |
| 197 | } else { |
| 198 | elevator_zeroing_velocity_ = kElevatorZeroingVelocity; |
| 199 | } |
| 200 | } else if (elevator_zeroing_velocity_ > 0 && |
Austin Schuh | 9e37c32 | 2015-02-16 15:47:49 -0800 | [diff] [blame] | 201 | estimated_elevator() > average_elevator + 1.1 * pulse_width) { |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 202 | elevator_zeroing_velocity_ = -kElevatorZeroingVelocity; |
| 203 | } else if (elevator_zeroing_velocity_ < 0 && |
Austin Schuh | 9e37c32 | 2015-02-16 15:47:49 -0800 | [diff] [blame] | 204 | estimated_elevator() < average_elevator - 1.1 * pulse_width) { |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 205 | elevator_zeroing_velocity_ = kElevatorZeroingVelocity; |
| 206 | } |
| 207 | return elevator_zeroing_velocity_; |
| 208 | } |
| 209 | |
Philipp Schrader | 3e28141 | 2015-03-01 23:48:23 +0000 | [diff] [blame] | 210 | double Fridge::UseUnlessZero(double target_value, double default_value) { |
| 211 | if (target_value != 0.0) { |
| 212 | return target_value; |
| 213 | } else { |
| 214 | return default_value; |
| 215 | } |
| 216 | } |
| 217 | |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 218 | double Fridge::arm_zeroing_velocity() { |
| 219 | const double average_arm = (constants::GetValues().fridge.arm.lower_limit + |
| 220 | constants::GetValues().fridge.arm.upper_limit) / |
| 221 | 2.0; |
| 222 | const double pulse_width = ::std::max( |
Daniel Petti | a782741 | 2015-02-13 20:55:57 -0800 | [diff] [blame] | 223 | constants::GetValues().fridge.right_arm_zeroing.index_difference, |
| 224 | constants::GetValues().fridge.left_arm_zeroing.index_difference); |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 225 | |
| 226 | if (arm_zeroing_velocity_ == 0) { |
| 227 | if (estimated_arm() > average_arm) { |
| 228 | arm_zeroing_velocity_ = -kArmZeroingVelocity; |
| 229 | } else { |
| 230 | arm_zeroing_velocity_ = kArmZeroingVelocity; |
| 231 | } |
| 232 | } else if (arm_zeroing_velocity_ > 0.0 && |
Austin Schuh | 9e37c32 | 2015-02-16 15:47:49 -0800 | [diff] [blame] | 233 | estimated_arm() > average_arm + 1.1 * pulse_width) { |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 234 | arm_zeroing_velocity_ = -kArmZeroingVelocity; |
| 235 | } else if (arm_zeroing_velocity_ < 0.0 && |
Austin Schuh | 9e37c32 | 2015-02-16 15:47:49 -0800 | [diff] [blame] | 236 | estimated_arm() < average_arm - 1.1 * pulse_width) { |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 237 | arm_zeroing_velocity_ = kArmZeroingVelocity; |
| 238 | } |
| 239 | return arm_zeroing_velocity_; |
| 240 | } |
| 241 | |
Austin Schuh | 482a4e1 | 2015-02-14 22:43:43 -0800 | [diff] [blame] | 242 | void Fridge::RunIteration(const control_loops::FridgeQueue::Goal *unsafe_goal, |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 243 | const control_loops::FridgeQueue::Position *position, |
| 244 | control_loops::FridgeQueue::Output *output, |
| 245 | control_loops::FridgeQueue::Status *status) { |
Austin Schuh | dbd6bfa | 2015-02-14 21:25:16 -0800 | [diff] [blame] | 246 | if (WasReset()) { |
| 247 | LOG(ERROR, "WPILib reset, restarting\n"); |
| 248 | left_elevator_estimator_.Reset(); |
| 249 | right_elevator_estimator_.Reset(); |
| 250 | left_arm_estimator_.Reset(); |
| 251 | right_arm_estimator_.Reset(); |
| 252 | state_ = UNINITIALIZED; |
| 253 | } |
| 254 | |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 255 | // Get a reference to the constants struct since we use it so often in this |
| 256 | // code. |
Philipp Schrader | 82c6507 | 2015-02-16 00:47:09 +0000 | [diff] [blame] | 257 | const auto &values = constants::GetValues(); |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 258 | |
| 259 | // Bool to track if we should turn the motors on or not. |
| 260 | bool disable = output == nullptr; |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 261 | |
| 262 | // Save the current position so it can be used easily in the class. |
| 263 | current_position_ = *position; |
| 264 | |
| 265 | left_elevator_estimator_.UpdateEstimate(position->elevator.left); |
| 266 | right_elevator_estimator_.UpdateEstimate(position->elevator.right); |
| 267 | left_arm_estimator_.UpdateEstimate(position->arm.left); |
| 268 | right_arm_estimator_.UpdateEstimate(position->arm.right); |
| 269 | |
| 270 | if (state_ != UNINITIALIZED) { |
| 271 | Correct(); |
| 272 | } |
| 273 | |
| 274 | // Zeroing will work as follows: |
| 275 | // At startup, record the offset of the two halves of the two subsystems. |
| 276 | // Then, start moving the elevator towards the center until both halves are |
| 277 | // zeroed. |
| 278 | // Then, start moving the claw towards the center until both halves are |
| 279 | // zeroed. |
| 280 | // Then, done! |
| 281 | |
| 282 | // We'll then need code to do sanity checking on values. |
| 283 | |
| 284 | // Now, we need to figure out which way to go. |
| 285 | |
| 286 | switch (state_) { |
| 287 | case UNINITIALIZED: |
| 288 | LOG(DEBUG, "Uninitialized\n"); |
| 289 | // Startup. Assume that we are at the origin everywhere. |
| 290 | // This records the encoder offset between the two sides of the elevator. |
| 291 | left_elevator_offset_ = -position->elevator.left.encoder; |
| 292 | right_elevator_offset_ = -position->elevator.right.encoder; |
| 293 | left_arm_offset_ = -position->arm.left.encoder; |
| 294 | right_arm_offset_ = -position->arm.right.encoder; |
Austin Schuh | aab0157 | 2015-02-15 00:12:35 -0800 | [diff] [blame] | 295 | elevator_loop_->mutable_X_hat().setZero(); |
| 296 | arm_loop_->mutable_X_hat().setZero(); |
Austin Schuh | dbd6bfa | 2015-02-14 21:25:16 -0800 | [diff] [blame] | 297 | LOG(INFO, "Initializing arm offsets to %f, %f\n", left_arm_offset_, |
| 298 | right_arm_offset_); |
| 299 | LOG(INFO, "Initializing elevator offsets to %f, %f\n", |
| 300 | left_elevator_offset_, right_elevator_offset_); |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 301 | Correct(); |
| 302 | state_ = INITIALIZING; |
| 303 | disable = true; |
| 304 | break; |
| 305 | |
| 306 | case INITIALIZING: |
| 307 | LOG(DEBUG, "Waiting for accurate initial position.\n"); |
| 308 | disable = true; |
| 309 | // Update state_ to accurately represent the state of the zeroing |
| 310 | // estimators. |
| 311 | UpdateZeroingState(); |
| 312 | if (state_ != INITIALIZING) { |
| 313 | // Set the goals to where we are now. |
| 314 | elevator_goal_ = elevator(); |
| 315 | arm_goal_ = arm(); |
| 316 | } |
| 317 | break; |
| 318 | |
| 319 | case ZEROING_ELEVATOR: |
| 320 | LOG(DEBUG, "Zeroing elevator\n"); |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 321 | |
| 322 | // Update state_ to accurately represent the state of the zeroing |
| 323 | // estimators. |
| 324 | UpdateZeroingState(); |
| 325 | if (left_elevator_estimator_.zeroed() && |
| 326 | right_elevator_estimator_.zeroed()) { |
| 327 | SetElevatorOffset(left_elevator_estimator_.offset(), |
| 328 | right_elevator_estimator_.offset()); |
| 329 | LOG(DEBUG, "Zeroed the elevator!\n"); |
Daniel Petti | e1bb13e | 2015-02-17 13:59:15 -0800 | [diff] [blame] | 330 | |
Austin Schuh | 5e872c8 | 2015-02-17 22:59:08 -0800 | [diff] [blame] | 331 | if (elevator() < values.fridge.arm_zeroing_height && |
Daniel Petti | e1bb13e | 2015-02-17 13:59:15 -0800 | [diff] [blame] | 332 | state_ != INITIALIZING) { |
| 333 | // Move the elevator to a safe height before we start zeroing the arm, |
| 334 | // so that we don't crash anything. |
| 335 | LOG(DEBUG, "Moving elevator to safe height.\n"); |
| 336 | elevator_goal_ += kElevatorSafeHeightVelocity * |
| 337 | ::aos::controls::kLoopFrequency.ToSeconds(); |
Philipp Schrader | 085bf01 | 2015-03-15 01:43:11 +0000 | [diff] [blame^] | 338 | elevator_goal_velocity_ = kElevatorSafeHeightVelocity; |
Daniel Petti | e1bb13e | 2015-02-17 13:59:15 -0800 | [diff] [blame] | 339 | |
| 340 | state_ = ZEROING_ELEVATOR; |
| 341 | break; |
| 342 | } |
| 343 | |
Austin Schuh | dbd6bfa | 2015-02-14 21:25:16 -0800 | [diff] [blame] | 344 | } else if (!disable) { |
Philipp Schrader | 085bf01 | 2015-03-15 01:43:11 +0000 | [diff] [blame^] | 345 | elevator_goal_velocity_ = elevator_zeroing_velocity(); |
| 346 | elevator_goal_ += elevator_goal_velocity_ * |
Adam Snaider | 3cd11c5 | 2015-02-16 02:16:09 +0000 | [diff] [blame] | 347 | ::aos::controls::kLoopFrequency.ToSeconds(); |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 348 | } |
Philipp Schrader | 3e28141 | 2015-03-01 23:48:23 +0000 | [diff] [blame] | 349 | |
| 350 | // Bypass motion profiles while we are zeroing. |
| 351 | // This is also an important step right after the elevator is zeroed and |
| 352 | // we reach into the elevator's state matrix and change it based on the |
| 353 | // newly-obtained offset. |
| 354 | { |
| 355 | Eigen::Matrix<double, 2, 1> current; |
| 356 | current.setZero(); |
Philipp Schrader | 085bf01 | 2015-03-15 01:43:11 +0000 | [diff] [blame^] | 357 | current << elevator_goal_, elevator_goal_velocity_; |
Philipp Schrader | 3e28141 | 2015-03-01 23:48:23 +0000 | [diff] [blame] | 358 | elevator_profile_.MoveCurrentState(current); |
| 359 | } |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 360 | break; |
| 361 | |
| 362 | case ZEROING_ARM: |
| 363 | LOG(DEBUG, "Zeroing the arm\n"); |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 364 | |
| 365 | // Update state_ to accurately represent the state of the zeroing |
| 366 | // estimators. |
| 367 | UpdateZeroingState(); |
| 368 | if (left_arm_estimator_.zeroed() && right_arm_estimator_.zeroed()) { |
| 369 | SetArmOffset(left_arm_estimator_.offset(), |
| 370 | right_arm_estimator_.offset()); |
| 371 | LOG(DEBUG, "Zeroed the arm!\n"); |
Austin Schuh | dbd6bfa | 2015-02-14 21:25:16 -0800 | [diff] [blame] | 372 | } else if (!disable) { |
Philipp Schrader | 085bf01 | 2015-03-15 01:43:11 +0000 | [diff] [blame^] | 373 | arm_goal_velocity_ = arm_zeroing_velocity(); |
Adam Snaider | 3cd11c5 | 2015-02-16 02:16:09 +0000 | [diff] [blame] | 374 | arm_goal_ += |
Philipp Schrader | 085bf01 | 2015-03-15 01:43:11 +0000 | [diff] [blame^] | 375 | arm_goal_velocity_ * ::aos::controls::kLoopFrequency.ToSeconds(); |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 376 | } |
Philipp Schrader | 3e28141 | 2015-03-01 23:48:23 +0000 | [diff] [blame] | 377 | |
| 378 | // Bypass motion profiles while we are zeroing. |
| 379 | // This is also an important step right after the arm is zeroed and |
| 380 | // we reach into the arm's state matrix and change it based on the |
| 381 | // newly-obtained offset. |
| 382 | { |
| 383 | Eigen::Matrix<double, 2, 1> current; |
| 384 | current.setZero(); |
Philipp Schrader | 085bf01 | 2015-03-15 01:43:11 +0000 | [diff] [blame^] | 385 | current << arm_goal_, arm_goal_velocity_; |
Philipp Schrader | 3e28141 | 2015-03-01 23:48:23 +0000 | [diff] [blame] | 386 | arm_profile_.MoveCurrentState(current); |
| 387 | } |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 388 | break; |
| 389 | |
| 390 | case RUNNING: |
| 391 | LOG(DEBUG, "Running!\n"); |
Austin Schuh | 482a4e1 | 2015-02-14 22:43:43 -0800 | [diff] [blame] | 392 | if (unsafe_goal) { |
Philipp Schrader | 085bf01 | 2015-03-15 01:43:11 +0000 | [diff] [blame^] | 393 | // Handle the case where we switch between the types of profiling. |
| 394 | ProfilingType new_profiling_type = |
| 395 | static_cast<ProfilingType>(unsafe_goal->profiling_type); |
Philipp Schrader | 3e28141 | 2015-03-01 23:48:23 +0000 | [diff] [blame] | 396 | |
Philipp Schrader | 085bf01 | 2015-03-15 01:43:11 +0000 | [diff] [blame^] | 397 | if (last_profiling_type_ != new_profiling_type) { |
| 398 | // Reset the height/angle profiles. |
| 399 | Eigen::Matrix<double, 2, 1> current; |
| 400 | current.setZero(); |
| 401 | current << arm_goal_, arm_goal_velocity_; |
| 402 | arm_profile_.MoveCurrentState(current); |
| 403 | current << elevator_goal_, elevator_goal_velocity_; |
| 404 | elevator_profile_.MoveCurrentState(current); |
Philipp Schrader | 3e28141 | 2015-03-01 23:48:23 +0000 | [diff] [blame] | 405 | |
Philipp Schrader | 085bf01 | 2015-03-15 01:43:11 +0000 | [diff] [blame^] | 406 | // Reset the x/y profiles. |
| 407 | aos::util::ElevatorArmKinematics::KinematicResult x_y_result; |
| 408 | kinematics_.ForwardKinematic(elevator_goal_, arm_goal_, |
| 409 | elevator_goal_velocity_, |
| 410 | arm_goal_velocity_, &x_y_result); |
| 411 | current << x_y_result.fridge_x, x_y_result.fridge_x_velocity; |
| 412 | x_profile_.MoveCurrentState(current); |
| 413 | current << x_y_result.fridge_h, x_y_result.fridge_h_velocity; |
| 414 | y_profile_.MoveCurrentState(current); |
| 415 | |
| 416 | last_profiling_type_ = new_profiling_type; |
| 417 | } |
| 418 | |
| 419 | if (new_profiling_type == ProfilingType::ANGLE_HEIGHT_PROFILING) { |
| 420 | // Pick a set of sane arm defaults if none are specified. |
| 421 | arm_profile_.set_maximum_velocity( |
| 422 | UseUnlessZero(unsafe_goal->max_angular_velocity, 1.0)); |
| 423 | arm_profile_.set_maximum_acceleration( |
| 424 | UseUnlessZero(unsafe_goal->max_angular_acceleration, 3.0)); |
| 425 | elevator_profile_.set_maximum_velocity( |
| 426 | UseUnlessZero(unsafe_goal->max_velocity, 0.50)); |
| 427 | elevator_profile_.set_maximum_acceleration( |
| 428 | UseUnlessZero(unsafe_goal->max_acceleration, 2.0)); |
| 429 | |
| 430 | // Use the profiles to limit the arm's movements. |
| 431 | const double unfiltered_arm_goal = ::std::max( |
| 432 | ::std::min(unsafe_goal->angle, values.fridge.arm.upper_limit), |
| 433 | values.fridge.arm.lower_limit); |
| 434 | ::Eigen::Matrix<double, 2, 1> arm_goal_state = arm_profile_.Update( |
| 435 | unfiltered_arm_goal, unsafe_goal->angular_velocity); |
| 436 | arm_goal_ = arm_goal_state(0, 0); |
| 437 | arm_goal_velocity_ = arm_goal_state(1, 0); |
| 438 | |
| 439 | // Use the profiles to limit the elevator's movements. |
| 440 | const double unfiltered_elevator_goal = |
| 441 | ::std::max(::std::min(unsafe_goal->height, |
| 442 | values.fridge.elevator.upper_limit), |
| 443 | values.fridge.elevator.lower_limit); |
| 444 | ::Eigen::Matrix<double, 2, 1> elevator_goal_state = |
| 445 | elevator_profile_.Update(unfiltered_elevator_goal, |
| 446 | unsafe_goal->velocity); |
| 447 | elevator_goal_ = elevator_goal_state(0, 0); |
| 448 | elevator_goal_velocity_ = elevator_goal_state(1, 0); |
| 449 | } else if (new_profiling_type == ProfilingType::X_Y_PROFILING) { |
| 450 | // Use x/y profiling |
| 451 | aos::util::ElevatorArmKinematics::KinematicResult kinematic_result; |
| 452 | |
| 453 | x_profile_.set_maximum_velocity( |
| 454 | UseUnlessZero(unsafe_goal->max_x_velocity, 0.5)); |
| 455 | x_profile_.set_maximum_acceleration( |
| 456 | UseUnlessZero(unsafe_goal->max_x_acceleration, 2.0)); |
| 457 | y_profile_.set_maximum_velocity( |
| 458 | UseUnlessZero(unsafe_goal->max_y_velocity, 0.50)); |
| 459 | y_profile_.set_maximum_acceleration( |
| 460 | UseUnlessZero(unsafe_goal->max_y_acceleration, 2.0)); |
| 461 | |
| 462 | // Limit the goals before we update the profiles. |
| 463 | kinematics_.InverseKinematic( |
| 464 | unsafe_goal->x, unsafe_goal->y, unsafe_goal->x_velocity, |
| 465 | unsafe_goal->y_velocity, &kinematic_result); |
| 466 | |
| 467 | // Use the profiles to limit the x movements. |
| 468 | ::Eigen::Matrix<double, 2, 1> x_goal_state = x_profile_.Update( |
| 469 | kinematic_result.fridge_x, kinematic_result.fridge_x_velocity); |
| 470 | |
| 471 | // Use the profiles to limit the y movements. |
| 472 | ::Eigen::Matrix<double, 2, 1> y_goal_state = y_profile_.Update( |
| 473 | kinematic_result.fridge_h, kinematic_result.fridge_h_velocity); |
| 474 | |
| 475 | // Convert x/y goal states into arm/elevator goals. |
| 476 | // The inverse kinematics functions automatically perform range |
| 477 | // checking and adjust the results so that they're always valid. |
| 478 | kinematics_.InverseKinematic(x_goal_state(0, 0), y_goal_state(0, 0), |
| 479 | x_goal_state(1, 0), y_goal_state(1, 0), |
| 480 | &kinematic_result); |
| 481 | |
| 482 | // Store the appropriate inverse kinematic results in the |
| 483 | // arm/elevator goals. |
| 484 | arm_goal_ = kinematic_result.arm_angle; |
| 485 | arm_goal_velocity_ = kinematic_result.arm_velocity; |
| 486 | |
| 487 | elevator_goal_ = kinematic_result.elevator_height; |
| 488 | elevator_goal_velocity_ = kinematic_result.arm_velocity; |
| 489 | } else { |
| 490 | LOG(ERROR, "Unknown profiling_type: %d\n", |
| 491 | unsafe_goal->profiling_type); |
| 492 | } |
Austin Schuh | 482a4e1 | 2015-02-14 22:43:43 -0800 | [diff] [blame] | 493 | } |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 494 | |
| 495 | // Update state_ to accurately represent the state of the zeroing |
| 496 | // estimators. |
| 497 | UpdateZeroingState(); |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 498 | |
| 499 | if (state_ != RUNNING && state_ != ESTOP) { |
| 500 | state_ = UNINITIALIZED; |
| 501 | } |
| 502 | break; |
| 503 | |
| 504 | case ESTOP: |
| 505 | LOG(ERROR, "Estop\n"); |
| 506 | disable = true; |
| 507 | break; |
| 508 | } |
| 509 | |
| 510 | // Commence death if either left/right tracking error gets too big. This |
| 511 | // should run immediately after the SetArmOffset and SetElevatorOffset |
| 512 | // functions to double-check that the hardware is in a sane state. |
| 513 | if (::std::abs(left_arm() - right_arm()) >= |
Austin Schuh | dbd6bfa | 2015-02-14 21:25:16 -0800 | [diff] [blame] | 514 | values.max_allowed_left_right_arm_difference) { |
| 515 | LOG(ERROR, "The arms are too far apart. |%f - %f| > %f\n", left_arm(), |
| 516 | right_arm(), values.max_allowed_left_right_arm_difference); |
| 517 | |
| 518 | // Indicate an ESTOP condition and stop the motors. |
| 519 | state_ = ESTOP; |
| 520 | disable = true; |
| 521 | } |
| 522 | |
| 523 | if (::std::abs(left_elevator() - right_elevator()) >= |
| 524 | values.max_allowed_left_right_elevator_difference) { |
| 525 | LOG(ERROR, "The elevators are too far apart. |%f - %f| > %f\n", |
| 526 | left_elevator(), right_elevator(), |
| 527 | values.max_allowed_left_right_elevator_difference); |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 528 | |
| 529 | // Indicate an ESTOP condition and stop the motors. |
| 530 | state_ = ESTOP; |
| 531 | disable = true; |
| 532 | } |
| 533 | |
| 534 | // Limit the goals so we can't exceed the hardware limits if we are RUNNING. |
| 535 | if (state_ == RUNNING) { |
| 536 | // Limit the arm goal to min/max allowable angles. |
| 537 | if (arm_goal_ >= values.fridge.arm.upper_limit) { |
| 538 | LOG(WARNING, "Arm goal above limit, %f > %f\n", arm_goal_, |
| 539 | values.fridge.arm.upper_limit); |
| 540 | arm_goal_ = values.fridge.arm.upper_limit; |
| 541 | } |
| 542 | if (arm_goal_ <= values.fridge.arm.lower_limit) { |
| 543 | LOG(WARNING, "Arm goal below limit, %f < %f\n", arm_goal_, |
| 544 | values.fridge.arm.lower_limit); |
| 545 | arm_goal_ = values.fridge.arm.lower_limit; |
| 546 | } |
| 547 | |
| 548 | // Limit the elevator goal to min/max allowable heights. |
| 549 | if (elevator_goal_ >= values.fridge.elevator.upper_limit) { |
| 550 | LOG(WARNING, "Elevator goal above limit, %f > %f\n", elevator_goal_, |
| 551 | values.fridge.elevator.upper_limit); |
| 552 | elevator_goal_ = values.fridge.elevator.upper_limit; |
| 553 | } |
| 554 | if (elevator_goal_ <= values.fridge.elevator.lower_limit) { |
| 555 | LOG(WARNING, "Elevator goal below limit, %f < %f\n", elevator_goal_, |
| 556 | values.fridge.elevator.lower_limit); |
| 557 | elevator_goal_ = values.fridge.elevator.lower_limit; |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | // Check the lower level hardware limit as well. |
| 562 | if (state_ == RUNNING) { |
| 563 | if (left_arm() >= values.fridge.arm.upper_hard_limit || |
| 564 | left_arm() <= values.fridge.arm.lower_hard_limit) { |
| 565 | LOG(ERROR, "Left arm at %f out of bounds [%f, %f], ESTOPing\n", |
| 566 | left_arm(), values.fridge.arm.lower_hard_limit, |
| 567 | values.fridge.arm.upper_hard_limit); |
| 568 | state_ = ESTOP; |
| 569 | } |
| 570 | |
| 571 | if (right_arm() >= values.fridge.arm.upper_hard_limit || |
| 572 | right_arm() <= values.fridge.arm.lower_hard_limit) { |
| 573 | LOG(ERROR, "Right arm at %f out of bounds [%f, %f], ESTOPing\n", |
| 574 | right_arm(), values.fridge.arm.lower_hard_limit, |
| 575 | values.fridge.arm.upper_hard_limit); |
| 576 | state_ = ESTOP; |
| 577 | } |
| 578 | |
| 579 | if (left_elevator() >= values.fridge.elevator.upper_hard_limit || |
| 580 | left_elevator() <= values.fridge.elevator.lower_hard_limit) { |
| 581 | LOG(ERROR, "Left elevator at %f out of bounds [%f, %f], ESTOPing\n", |
| 582 | left_elevator(), values.fridge.elevator.lower_hard_limit, |
| 583 | values.fridge.elevator.upper_hard_limit); |
| 584 | state_ = ESTOP; |
| 585 | } |
| 586 | |
| 587 | if (right_elevator() >= values.fridge.elevator.upper_hard_limit || |
| 588 | right_elevator() <= values.fridge.elevator.lower_hard_limit) { |
| 589 | LOG(ERROR, "Right elevator at %f out of bounds [%f, %f], ESTOPing\n", |
| 590 | right_elevator(), values.fridge.elevator.lower_hard_limit, |
| 591 | values.fridge.elevator.upper_hard_limit); |
| 592 | state_ = ESTOP; |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | // Set the goals. |
Philipp Schrader | 085bf01 | 2015-03-15 01:43:11 +0000 | [diff] [blame^] | 597 | arm_loop_->mutable_R() << arm_goal_, arm_goal_velocity_, 0.0, 0.0, 0.0; |
| 598 | elevator_loop_->mutable_R() << elevator_goal_, elevator_goal_velocity_, 0.0, |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 599 | 0.0; |
| 600 | |
| 601 | const double max_voltage = state_ == RUNNING ? 12.0 : kZeroingVoltage; |
| 602 | arm_loop_->set_max_voltage(max_voltage); |
| 603 | elevator_loop_->set_max_voltage(max_voltage); |
| 604 | |
| 605 | if (state_ == ESTOP) { |
| 606 | disable = true; |
| 607 | } |
| 608 | arm_loop_->Update(disable); |
| 609 | elevator_loop_->Update(disable); |
| 610 | |
| 611 | if (state_ == INITIALIZING || state_ == ZEROING_ELEVATOR || |
| 612 | state_ == ZEROING_ARM) { |
| 613 | if (arm_loop_->U() != arm_loop_->U_uncapped()) { |
| 614 | Eigen::Matrix<double, 2, 1> deltaR = |
| 615 | arm_loop_->UnsaturateOutputGoalChange(); |
| 616 | |
| 617 | // Move the average arm goal by the amount observed. |
| 618 | LOG(WARNING, "Moving arm goal by %f to handle saturation\n", |
| 619 | deltaR(0, 0)); |
| 620 | arm_goal_ += deltaR(0, 0); |
| 621 | } |
| 622 | |
| 623 | if (elevator_loop_->U() != elevator_loop_->U_uncapped()) { |
| 624 | Eigen::Matrix<double, 2, 1> deltaR = |
| 625 | elevator_loop_->UnsaturateOutputGoalChange(); |
| 626 | |
| 627 | // Move the average elevator goal by the amount observed. |
| 628 | LOG(WARNING, "Moving elevator goal by %f to handle saturation\n", |
| 629 | deltaR(0, 0)); |
| 630 | elevator_goal_ += deltaR(0, 0); |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | if (output) { |
| 635 | output->left_arm = arm_loop_->U(0, 0); |
| 636 | output->right_arm = arm_loop_->U(1, 0); |
| 637 | output->left_elevator = elevator_loop_->U(0, 0); |
| 638 | output->right_elevator = elevator_loop_->U(1, 0); |
Austin Schuh | 482a4e1 | 2015-02-14 22:43:43 -0800 | [diff] [blame] | 639 | if (unsafe_goal) { |
| 640 | output->grabbers = unsafe_goal->grabbers; |
| 641 | } else { |
| 642 | output->grabbers.top_front = false; |
| 643 | output->grabbers.top_back = false; |
| 644 | output->grabbers.bottom_front = false; |
| 645 | output->grabbers.bottom_back = false; |
| 646 | } |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | // TODO(austin): Populate these fully. |
Austin Schuh | 5ae4efd | 2015-02-15 23:34:22 -0800 | [diff] [blame] | 650 | status->zeroed = state_ == RUNNING; |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 651 | status->angle = arm_loop_->X_hat(0, 0); |
Philipp Schrader | 3e28141 | 2015-03-01 23:48:23 +0000 | [diff] [blame] | 652 | status->angular_velocity = arm_loop_->X_hat(1, 0); |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 653 | status->height = elevator_loop_->X_hat(0, 0); |
Philipp Schrader | 3e28141 | 2015-03-01 23:48:23 +0000 | [diff] [blame] | 654 | status->velocity = elevator_loop_->X_hat(1, 0); |
Austin Schuh | 5e872c8 | 2015-02-17 22:59:08 -0800 | [diff] [blame] | 655 | status->goal_angle = arm_goal_; |
Philipp Schrader | 085bf01 | 2015-03-15 01:43:11 +0000 | [diff] [blame^] | 656 | status->goal_angular_velocity = arm_goal_velocity_; |
Austin Schuh | 5e872c8 | 2015-02-17 22:59:08 -0800 | [diff] [blame] | 657 | status->goal_height = elevator_goal_; |
Philipp Schrader | 085bf01 | 2015-03-15 01:43:11 +0000 | [diff] [blame^] | 658 | status->goal_velocity = elevator_goal_velocity_; |
Austin Schuh | 482a4e1 | 2015-02-14 22:43:43 -0800 | [diff] [blame] | 659 | if (unsafe_goal) { |
| 660 | status->grabbers = unsafe_goal->grabbers; |
| 661 | } else { |
| 662 | status->grabbers.top_front = false; |
| 663 | status->grabbers.top_back = false; |
| 664 | status->grabbers.bottom_front = false; |
| 665 | status->grabbers.bottom_back = false; |
| 666 | } |
Adam Snaider | 3cd11c5 | 2015-02-16 02:16:09 +0000 | [diff] [blame] | 667 | zeroing::PopulateEstimatorState(left_arm_estimator_, &status->left_arm_state); |
Daniel Petti | ab27423 | 2015-02-16 19:15:34 -0800 | [diff] [blame] | 668 | zeroing::PopulateEstimatorState(right_arm_estimator_, |
| 669 | &status->right_arm_state); |
| 670 | zeroing::PopulateEstimatorState(left_elevator_estimator_, |
Adam Snaider | 3cd11c5 | 2015-02-16 02:16:09 +0000 | [diff] [blame] | 671 | &status->left_elevator_state); |
Daniel Petti | ab27423 | 2015-02-16 19:15:34 -0800 | [diff] [blame] | 672 | zeroing::PopulateEstimatorState(right_elevator_estimator_, |
Adam Snaider | 3cd11c5 | 2015-02-16 02:16:09 +0000 | [diff] [blame] | 673 | &status->right_elevator_state); |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 674 | status->estopped = (state_ == ESTOP); |
Austin Schuh | 482a4e1 | 2015-02-14 22:43:43 -0800 | [diff] [blame] | 675 | status->state = state_; |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 676 | last_state_ = state_; |
Ben Fredrickson | 6b5ba79 | 2015-01-25 17:14:40 -0800 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | } // namespace control_loops |
| 680 | } // namespace frc971 |