Austin Schuh | 3bb9a44 | 2014-02-02 16:01:45 -0800 | [diff] [blame] | 1 | #include "frc971/control_loops/claw/claw.h" |
| 2 | |
Austin Schuh | 3bb9a44 | 2014-02-02 16:01:45 -0800 | [diff] [blame] | 3 | #include <algorithm> |
| 4 | |
| 5 | #include "aos/common/control_loop/control_loops.q.h" |
| 6 | #include "aos/common/logging/logging.h" |
Brian Silverman | f48fab3 | 2014-03-09 14:32:24 -0700 | [diff] [blame] | 7 | #include "aos/common/logging/queue_logging.h" |
Austin Schuh | 3bb9a44 | 2014-02-02 16:01:45 -0800 | [diff] [blame] | 8 | |
| 9 | #include "frc971/constants.h" |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 10 | #include "frc971/control_loops/claw/claw_motor_plant.h" |
| 11 | |
Austin Schuh | 3bb9a44 | 2014-02-02 16:01:45 -0800 | [diff] [blame] | 12 | // Zeroing plan. |
| 13 | // There are 2 types of zeros. Enabled and disabled ones. |
| 14 | // Disabled ones are only valid during auto mode, and can be used to speed up |
| 15 | // the enabled zero process. We need to re-zero during teleop in case the auto |
| 16 | // zero was poor and causes us to miss all our shots. |
| 17 | // |
| 18 | // We need to be able to zero manually while disabled by moving the joint over |
| 19 | // the zeros. |
| 20 | // Zero on the down edge when disabled (gravity in the direction of motion) |
| 21 | // |
| 22 | // When enabled, zero on the up edge (gravity opposing the direction of motion) |
| 23 | // The enabled sequence needs to work as follows. We can crash the claw if we |
| 24 | // bring them too close to each other or too far from each other. The only safe |
| 25 | // thing to do is to move them in unison. |
| 26 | // |
| 27 | // Start by moving them both towards the front of the bot to either find either |
| 28 | // the middle hall effect on either jaw, or the front hall effect on the bottom |
| 29 | // jaw. Any edge that isn't the desired edge will provide an approximate edge |
| 30 | // location that can be used for the fine tuning step. |
| 31 | // Once an edge is found on the front claw, move back the other way with both |
| 32 | // claws until an edge is found for the other claw. |
| 33 | // Now that we have an approximate zero, we can robustify the limits to keep |
| 34 | // both claws safe. Then, we can move both claws to a position that is the |
| 35 | // correct side of the zero and go zero. |
| 36 | |
| 37 | // Valid region plan. |
Ben Fredrickson | 81ba2d5 | 2014-03-02 08:21:46 +0000 | [diff] [blame] | 38 | // Difference between the arms has a range, and the values of each arm has a |
| 39 | // range. |
Austin Schuh | 3bb9a44 | 2014-02-02 16:01:45 -0800 | [diff] [blame] | 40 | // If a claw runs up against a static limit, don't let the goal change outside |
| 41 | // the limit. |
| 42 | // If a claw runs up against a movable limit, move both claws outwards to get |
| 43 | // out of the condition. |
| 44 | |
| 45 | namespace frc971 { |
| 46 | namespace control_loops { |
| 47 | |
Austin Schuh | 01c652b | 2014-02-21 23:13:42 -0800 | [diff] [blame] | 48 | static const double kZeroingVoltage = 4.0; |
| 49 | static const double kMaxVoltage = 12.0; |
Austin Schuh | f84a130 | 2014-02-19 00:23:30 -0800 | [diff] [blame] | 50 | |
Austin Schuh | 27b8fb1 | 2014-02-22 15:10:05 -0800 | [diff] [blame] | 51 | ClawLimitedLoop::ClawLimitedLoop(StateFeedbackLoop<4, 2, 2> loop) |
| 52 | : StateFeedbackLoop<4, 2, 2>(loop), |
| 53 | uncapped_average_voltage_(0.0), |
James Kuszmaul | f63b0ae | 2014-03-25 16:52:11 -0700 | [diff] [blame] | 54 | is_zeroing_(true), |
| 55 | U_Poly_((Eigen::Matrix<double, 4, 2>() << 1, 0, |
| 56 | -1, 0, |
| 57 | 0, 1, |
| 58 | 0, -1).finished(), |
| 59 | (Eigen::Matrix<double, 4, 1>() << kMaxVoltage, kMaxVoltage, |
| 60 | kMaxVoltage, kMaxVoltage).finished()) { |
| 61 | ::aos::controls::HPolytope<0>::Init(); |
| 62 | } |
Austin Schuh | 27b8fb1 | 2014-02-22 15:10:05 -0800 | [diff] [blame] | 63 | |
James Kuszmaul | f63b0ae | 2014-03-25 16:52:11 -0700 | [diff] [blame] | 64 | // Caps the voltage prioritizing reducing velocity error over reducing |
| 65 | // positional error. |
| 66 | // Uses the polytope libararies which we used to just use for the drivetrain. |
| 67 | // Uses a region representing the maximum voltage and then transforms it such |
| 68 | // that the points represent different amounts of positional error and |
| 69 | // constrains the region such that, if at all possible, it will maintain its |
| 70 | // current efforts to reduce velocity error. |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 71 | void ClawLimitedLoop::CapU() { |
James Kuszmaul | f63b0ae | 2014-03-25 16:52:11 -0700 | [diff] [blame] | 72 | Eigen::Matrix<double, 4, 1> error = R - X_hat; |
Austin Schuh | 4cb047f | 2014-02-16 21:10:19 -0800 | [diff] [blame] | 73 | |
James Kuszmaul | d536a40 | 2014-02-18 22:32:12 -0800 | [diff] [blame] | 74 | double u_top = U(1, 0); |
| 75 | double u_bottom = U(0, 0); |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 76 | |
James Kuszmaul | f63b0ae | 2014-03-25 16:52:11 -0700 | [diff] [blame] | 77 | uncapped_average_voltage_ = (u_top + u_bottom) / 2; |
| 78 | |
| 79 | double max_voltage = is_zeroing_ ? kZeroingVoltage : kMaxVoltage; |
| 80 | |
| 81 | if (::std::abs(u_bottom) > max_voltage or ::std::abs(u_top) > max_voltage) { |
| 82 | // H * U <= k |
| 83 | // U = UPos + UVel |
| 84 | // H * (UPos + UVel) <= k |
| 85 | // H * UPos <= k - H * UVel |
| 86 | |
| 87 | // Now, we can do a coordinate transformation and say the following. |
| 88 | |
| 89 | // UPos = position_K * position_error |
| 90 | // (H * position_K) * position_error <= k - H * UVel |
| 91 | |
| 92 | Eigen::Matrix<double, 2, 2> position_K; |
| 93 | position_K << K(0, 0), K(0, 1), |
| 94 | K(1, 0), K(1, 1); |
| 95 | Eigen::Matrix<double, 2, 2> velocity_K; |
| 96 | velocity_K << K(0, 2), K(0, 3), |
| 97 | K(1, 2), K(1, 3); |
| 98 | |
| 99 | Eigen::Matrix<double, 2, 1> position_error; |
| 100 | position_error << error(0, 0), error(1, 0); |
| 101 | Eigen::Matrix<double, 2, 1> velocity_error; |
| 102 | velocity_error << error(2, 0), error(3, 0); |
| 103 | |
| 104 | Eigen::Matrix<double, 4, 1> pos_poly_k = |
| 105 | U_Poly_.k() - U_Poly_.H() * velocity_K * velocity_error; |
| 106 | Eigen::Matrix<double, 4, 2> pos_poly_H = U_Poly_.H() * position_K; |
| 107 | ::aos::controls::HPolytope<2> pos_poly(pos_poly_H, pos_poly_k); |
| 108 | |
| 109 | |
| 110 | Eigen::Matrix<double, 2, 1> adjusted_pos_error = CoerceGoal( |
| 111 | pos_poly, (Eigen::Matrix<double, 1, 2>() << position_error(1, 0), |
| 112 | -position_error(0, 0)).finished(), |
| 113 | 0.0, position_error); |
| 114 | |
| 115 | LOG(DEBUG, "Capping U is now %f %f\n", U(0, 0), U(1, 0)); |
| 116 | U = velocity_K * velocity_error + position_K * adjusted_pos_error; |
James Kuszmaul | d536a40 | 2014-02-18 22:32:12 -0800 | [diff] [blame] | 117 | } |
| 118 | |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 119 | } |
| 120 | |
Austin Schuh | 27b8fb1 | 2014-02-22 15:10:05 -0800 | [diff] [blame] | 121 | ZeroedStateFeedbackLoop::ZeroedStateFeedbackLoop(const char *name, |
| 122 | ClawMotor *motor) |
| 123 | : offset_(0.0), |
| 124 | name_(name), |
| 125 | motor_(motor), |
| 126 | zeroing_state_(UNKNOWN_POSITION), |
| 127 | posedge_value_(0.0), |
| 128 | negedge_value_(0.0), |
| 129 | encoder_(0.0), |
| 130 | last_encoder_(0.0) {} |
| 131 | |
| 132 | void ZeroedStateFeedbackLoop::SetPositionValues(const HalfClawPosition &claw) { |
| 133 | front_.Update(claw.front); |
| 134 | calibration_.Update(claw.calibration); |
| 135 | back_.Update(claw.back); |
| 136 | |
| 137 | bool any_sensor_triggered = any_triggered(); |
| 138 | if (any_sensor_triggered && any_triggered_last_) { |
| 139 | // We are still on the hall effect and nothing has changed. |
| 140 | min_hall_effect_on_angle_ = |
| 141 | ::std::min(min_hall_effect_on_angle_, claw.position); |
| 142 | max_hall_effect_on_angle_ = |
| 143 | ::std::max(max_hall_effect_on_angle_, claw.position); |
| 144 | } else if (!any_sensor_triggered && !any_triggered_last_) { |
| 145 | // We are still off the hall effect and nothing has changed. |
| 146 | min_hall_effect_off_angle_ = |
| 147 | ::std::min(min_hall_effect_off_angle_, claw.position); |
| 148 | max_hall_effect_off_angle_ = |
| 149 | ::std::max(max_hall_effect_off_angle_, claw.position); |
| 150 | } else if (any_sensor_triggered && !any_triggered_last_) { |
| 151 | // Saw a posedge on the hall effect. Reset the limits. |
| 152 | min_hall_effect_on_angle_ = ::std::min(claw.posedge_value, claw.position); |
| 153 | max_hall_effect_on_angle_ = ::std::max(claw.posedge_value, claw.position); |
| 154 | } else if (!any_sensor_triggered && any_triggered_last_) { |
| 155 | // Saw a negedge on the hall effect. Reset the limits. |
| 156 | min_hall_effect_off_angle_ = ::std::min(claw.negedge_value, claw.position); |
| 157 | max_hall_effect_off_angle_ = ::std::max(claw.negedge_value, claw.position); |
| 158 | } |
| 159 | |
| 160 | posedge_value_ = claw.posedge_value; |
| 161 | negedge_value_ = claw.negedge_value; |
| 162 | last_encoder_ = encoder_; |
| 163 | if (front().value() || calibration().value() || back().value()) { |
| 164 | last_on_encoder_ = encoder_; |
| 165 | } else { |
| 166 | last_off_encoder_ = encoder_; |
| 167 | } |
| 168 | encoder_ = claw.position; |
| 169 | any_triggered_last_ = any_sensor_triggered; |
| 170 | } |
| 171 | |
| 172 | void ZeroedStateFeedbackLoop::Reset(const HalfClawPosition &claw) { |
| 173 | set_zeroing_state(ZeroedStateFeedbackLoop::UNKNOWN_POSITION); |
| 174 | |
Ben Fredrickson | eaecbbb | 2014-02-23 12:12:03 +0000 | [diff] [blame] | 175 | front_.Reset(claw.front); |
| 176 | calibration_.Reset(claw.calibration); |
| 177 | back_.Reset(claw.back); |
Austin Schuh | 27b8fb1 | 2014-02-22 15:10:05 -0800 | [diff] [blame] | 178 | // close up the min and max edge positions as they are no longer valid and |
| 179 | // will be expanded in future iterations |
| 180 | min_hall_effect_on_angle_ = claw.position; |
| 181 | max_hall_effect_on_angle_ = claw.position; |
| 182 | min_hall_effect_off_angle_ = claw.position; |
| 183 | max_hall_effect_off_angle_ = claw.position; |
| 184 | any_triggered_last_ = any_triggered(); |
| 185 | } |
| 186 | |
| 187 | bool TopZeroedStateFeedbackLoop::SetCalibrationOnEdge( |
| 188 | const constants::Values::Claws::Claw &claw_values, |
| 189 | JointZeroingState zeroing_state) { |
| 190 | double edge_encoder; |
| 191 | double edge_angle; |
| 192 | if (GetPositionOfEdge(claw_values, &edge_encoder, &edge_angle)) { |
| 193 | LOG(INFO, "Calibration edge edge should be %f.\n", edge_angle); |
| 194 | SetCalibration(edge_encoder, edge_angle); |
| 195 | set_zeroing_state(zeroing_state); |
| 196 | return true; |
| 197 | } |
| 198 | return false; |
| 199 | } |
| 200 | |
| 201 | bool BottomZeroedStateFeedbackLoop::SetCalibrationOnEdge( |
| 202 | const constants::Values::Claws::Claw &claw_values, |
| 203 | JointZeroingState zeroing_state) { |
| 204 | double edge_encoder; |
| 205 | double edge_angle; |
| 206 | if (GetPositionOfEdge(claw_values, &edge_encoder, &edge_angle)) { |
| 207 | LOG(INFO, "Calibration edge.\n"); |
| 208 | SetCalibration(edge_encoder, edge_angle); |
| 209 | set_zeroing_state(zeroing_state); |
| 210 | return true; |
| 211 | } |
| 212 | return false; |
| 213 | } |
| 214 | |
Austin Schuh | cc0bf31 | 2014-02-09 00:39:29 -0800 | [diff] [blame] | 215 | ClawMotor::ClawMotor(control_loops::ClawGroup *my_claw) |
Brian Silverman | 71fbee0 | 2014-03-13 17:24:54 -0700 | [diff] [blame] | 216 | : aos::control_loops::ControlLoop<control_loops::ClawGroup, true, true, |
| 217 | false>(my_claw), |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 218 | has_top_claw_goal_(false), |
| 219 | top_claw_goal_(0.0), |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 220 | top_claw_(this), |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 221 | has_bottom_claw_goal_(false), |
| 222 | bottom_claw_goal_(0.0), |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 223 | bottom_claw_(this), |
| 224 | claw_(MakeClawLoop()), |
Ben Fredrickson | 9b38842 | 2014-02-13 06:15:31 +0000 | [diff] [blame] | 225 | was_enabled_(false), |
Austin Schuh | 4cb047f | 2014-02-16 21:10:19 -0800 | [diff] [blame] | 226 | doing_calibration_fine_tune_(false), |
Austin Schuh | e7f90d1 | 2014-02-17 00:48:25 -0800 | [diff] [blame] | 227 | capped_goal_(false), |
| 228 | mode_(UNKNOWN_LOCATION) {} |
Austin Schuh | 3bb9a44 | 2014-02-02 16:01:45 -0800 | [diff] [blame] | 229 | |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 230 | const int ZeroedStateFeedbackLoop::kZeroingMaxVoltage; |
Austin Schuh | 3bb9a44 | 2014-02-02 16:01:45 -0800 | [diff] [blame] | 231 | |
Ben Fredrickson | eaecbbb | 2014-02-23 12:12:03 +0000 | [diff] [blame] | 232 | bool ZeroedStateFeedbackLoop::SawFilteredPosedge( |
| 233 | const HallEffectTracker &this_sensor, const HallEffectTracker &sensorA, |
| 234 | const HallEffectTracker &sensorB) { |
| 235 | if (posedge_filter_ == nullptr && this_sensor.posedge_count_changed() && |
| 236 | !sensorA.posedge_count_changed() && !sensorB.posedge_count_changed() && |
| 237 | this_sensor.value() && !this_sensor.last_value()) { |
Ben Fredrickson | 81ba2d5 | 2014-03-02 08:21:46 +0000 | [diff] [blame] | 238 | posedge_filter_ = &this_sensor; |
Ben Fredrickson | eaecbbb | 2014-02-23 12:12:03 +0000 | [diff] [blame] | 239 | } else if (posedge_filter_ == &this_sensor && |
| 240 | !this_sensor.posedge_count_changed() && |
| 241 | !sensorA.posedge_count_changed() && |
| 242 | !sensorB.posedge_count_changed() && this_sensor.value()) { |
| 243 | posedge_filter_ = nullptr; |
Ben Fredrickson | 81ba2d5 | 2014-03-02 08:21:46 +0000 | [diff] [blame] | 244 | return true; |
Ben Fredrickson | eaecbbb | 2014-02-23 12:12:03 +0000 | [diff] [blame] | 245 | } else if (posedge_filter_ == &this_sensor) { |
| 246 | posedge_filter_ = nullptr; |
| 247 | } |
| 248 | return false; |
| 249 | } |
| 250 | |
| 251 | bool ZeroedStateFeedbackLoop::SawFilteredNegedge( |
| 252 | const HallEffectTracker &this_sensor, const HallEffectTracker &sensorA, |
| 253 | const HallEffectTracker &sensorB) { |
| 254 | if (negedge_filter_ == nullptr && this_sensor.negedge_count_changed() && |
| 255 | !sensorA.negedge_count_changed() && !sensorB.negedge_count_changed() && |
| 256 | !this_sensor.value() && this_sensor.last_value()) { |
| 257 | negedge_filter_ = &this_sensor; |
| 258 | } else if (negedge_filter_ == &this_sensor && |
| 259 | !this_sensor.negedge_count_changed() && |
| 260 | !sensorA.negedge_count_changed() && |
| 261 | !sensorB.negedge_count_changed() && !this_sensor.value()) { |
| 262 | negedge_filter_ = nullptr; |
Ben Fredrickson | 81ba2d5 | 2014-03-02 08:21:46 +0000 | [diff] [blame] | 263 | return true; |
Ben Fredrickson | eaecbbb | 2014-02-23 12:12:03 +0000 | [diff] [blame] | 264 | } else if (negedge_filter_ == &this_sensor) { |
| 265 | negedge_filter_ = nullptr; |
| 266 | } |
| 267 | return false; |
| 268 | } |
| 269 | |
Brian Silverman | e0a9546 | 2014-02-17 00:41:09 -0800 | [diff] [blame] | 270 | bool ZeroedStateFeedbackLoop::DoGetPositionOfEdge( |
| 271 | const constants::Values::Claws::AnglePair &angles, double *edge_encoder, |
Ben Fredrickson | eaecbbb | 2014-02-23 12:12:03 +0000 | [diff] [blame] | 272 | double *edge_angle, const HallEffectTracker &this_sensor, |
| 273 | const HallEffectTracker &sensorA, const HallEffectTracker &sensorB, |
Brian Silverman | e0a9546 | 2014-02-17 00:41:09 -0800 | [diff] [blame] | 274 | const char *hall_effect_name) { |
Austin Schuh | f84a130 | 2014-02-19 00:23:30 -0800 | [diff] [blame] | 275 | bool found_edge = false; |
Austin Schuh | 27b8fb1 | 2014-02-22 15:10:05 -0800 | [diff] [blame] | 276 | |
Ben Fredrickson | eaecbbb | 2014-02-23 12:12:03 +0000 | [diff] [blame] | 277 | if (SawFilteredPosedge(this_sensor, sensorA, sensorB)) { |
Austin Schuh | 27b8fb1 | 2014-02-22 15:10:05 -0800 | [diff] [blame] | 278 | if (min_hall_effect_off_angle_ == max_hall_effect_off_angle_) { |
Brian Silverman | f48fab3 | 2014-03-09 14:32:24 -0700 | [diff] [blame] | 279 | LOG(WARNING, "%s: Uncertain which side, rejecting posedge\n", name_); |
Brian Silverman | e0a9546 | 2014-02-17 00:41:09 -0800 | [diff] [blame] | 280 | } else { |
Austin Schuh | 27b8fb1 | 2014-02-22 15:10:05 -0800 | [diff] [blame] | 281 | const double average_last_encoder = |
| 282 | (min_hall_effect_off_angle_ + max_hall_effect_off_angle_) / 2.0; |
| 283 | if (posedge_value_ < average_last_encoder) { |
| 284 | *edge_angle = angles.upper_decreasing_angle; |
| 285 | LOG(INFO, "%s Posedge upper of %s -> %f posedge: %f avg_encoder: %f\n", |
| 286 | name_, hall_effect_name, *edge_angle, posedge_value_, |
| 287 | average_last_encoder); |
| 288 | } else { |
| 289 | *edge_angle = angles.lower_angle; |
| 290 | LOG(INFO, "%s Posedge lower of %s -> %f posedge: %f avg_encoder: %f\n", |
| 291 | name_, hall_effect_name, *edge_angle, posedge_value_, |
| 292 | average_last_encoder); |
| 293 | } |
Ben Fredrickson | eaecbbb | 2014-02-23 12:12:03 +0000 | [diff] [blame] | 294 | *edge_encoder = posedge_value_; |
Austin Schuh | 27b8fb1 | 2014-02-22 15:10:05 -0800 | [diff] [blame] | 295 | found_edge = true; |
Ben Fredrickson | eaecbbb | 2014-02-23 12:12:03 +0000 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | |
| 299 | if (SawFilteredNegedge(this_sensor, sensorA, sensorB)) { |
| 300 | if (min_hall_effect_on_angle_ == max_hall_effect_on_angle_) { |
Brian Silverman | f48fab3 | 2014-03-09 14:32:24 -0700 | [diff] [blame] | 301 | LOG(WARNING, "%s: Uncertain which side, rejecting negedge\n", name_); |
Brian Silverman | e0a9546 | 2014-02-17 00:41:09 -0800 | [diff] [blame] | 302 | } else { |
Austin Schuh | 27b8fb1 | 2014-02-22 15:10:05 -0800 | [diff] [blame] | 303 | const double average_last_encoder = |
| 304 | (min_hall_effect_on_angle_ + max_hall_effect_on_angle_) / 2.0; |
| 305 | if (negedge_value_ > average_last_encoder) { |
| 306 | *edge_angle = angles.upper_angle; |
| 307 | LOG(INFO, "%s Negedge upper of %s -> %f negedge: %f avg_encoder: %f\n", |
| 308 | name_, hall_effect_name, *edge_angle, negedge_value_, |
| 309 | average_last_encoder); |
| 310 | } else { |
| 311 | *edge_angle = angles.lower_decreasing_angle; |
| 312 | LOG(INFO, "%s Negedge lower of %s -> %f negedge: %f avg_encoder: %f\n", |
| 313 | name_, hall_effect_name, *edge_angle, negedge_value_, |
| 314 | average_last_encoder); |
| 315 | } |
| 316 | *edge_encoder = negedge_value_; |
Ben Fredrickson | eaecbbb | 2014-02-23 12:12:03 +0000 | [diff] [blame] | 317 | found_edge = true; |
Brian Silverman | e0a9546 | 2014-02-17 00:41:09 -0800 | [diff] [blame] | 318 | } |
Austin Schuh | 27b8fb1 | 2014-02-22 15:10:05 -0800 | [diff] [blame] | 319 | } |
| 320 | |
Austin Schuh | f84a130 | 2014-02-19 00:23:30 -0800 | [diff] [blame] | 321 | return found_edge; |
Brian Silverman | e0a9546 | 2014-02-17 00:41:09 -0800 | [diff] [blame] | 322 | } |
| 323 | |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 324 | bool ZeroedStateFeedbackLoop::GetPositionOfEdge( |
Austin Schuh | d27931c | 2014-02-16 19:18:20 -0800 | [diff] [blame] | 325 | const constants::Values::Claws::Claw &claw_values, double *edge_encoder, |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 326 | double *edge_angle) { |
Ben Fredrickson | 81ba2d5 | 2014-03-02 08:21:46 +0000 | [diff] [blame] | 327 | if (DoGetPositionOfEdge(claw_values.front, edge_encoder, edge_angle, front_, |
| 328 | calibration_, back_, "front")) { |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 329 | return true; |
| 330 | } |
Brian Silverman | e0a9546 | 2014-02-17 00:41:09 -0800 | [diff] [blame] | 331 | if (DoGetPositionOfEdge(claw_values.calibration, edge_encoder, edge_angle, |
Ben Fredrickson | eaecbbb | 2014-02-23 12:12:03 +0000 | [diff] [blame] | 332 | calibration_, front_, back_, "calibration")) { |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 333 | return true; |
| 334 | } |
Ben Fredrickson | 81ba2d5 | 2014-03-02 08:21:46 +0000 | [diff] [blame] | 335 | if (DoGetPositionOfEdge(claw_values.back, edge_encoder, edge_angle, back_, |
| 336 | calibration_, front_, "back")) { |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 337 | return true; |
| 338 | } |
| 339 | return false; |
| 340 | } |
| 341 | |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 342 | void TopZeroedStateFeedbackLoop::SetCalibration(double edge_encoder, |
| 343 | double edge_angle) { |
| 344 | double old_offset = offset_; |
| 345 | offset_ = edge_angle - edge_encoder; |
| 346 | const double doffset = offset_ - old_offset; |
| 347 | motor_->ChangeTopOffset(doffset); |
| 348 | } |
| 349 | |
| 350 | void BottomZeroedStateFeedbackLoop::SetCalibration(double edge_encoder, |
| 351 | double edge_angle) { |
| 352 | double old_offset = offset_; |
| 353 | offset_ = edge_angle - edge_encoder; |
| 354 | const double doffset = offset_ - old_offset; |
| 355 | motor_->ChangeBottomOffset(doffset); |
| 356 | } |
| 357 | |
| 358 | void ClawMotor::ChangeTopOffset(double doffset) { |
| 359 | claw_.ChangeTopOffset(doffset); |
| 360 | if (has_top_claw_goal_) { |
| 361 | top_claw_goal_ += doffset; |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | void ClawMotor::ChangeBottomOffset(double doffset) { |
| 366 | claw_.ChangeBottomOffset(doffset); |
| 367 | if (has_bottom_claw_goal_) { |
| 368 | bottom_claw_goal_ += doffset; |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | void ClawLimitedLoop::ChangeTopOffset(double doffset) { |
| 373 | Y_(1, 0) += doffset; |
| 374 | X_hat(1, 0) += doffset; |
| 375 | LOG(INFO, "Changing top offset by %f\n", doffset); |
| 376 | } |
| 377 | void ClawLimitedLoop::ChangeBottomOffset(double doffset) { |
| 378 | Y_(0, 0) += doffset; |
| 379 | X_hat(0, 0) += doffset; |
| 380 | X_hat(1, 0) -= doffset; |
| 381 | LOG(INFO, "Changing bottom offset by %f\n", doffset); |
| 382 | } |
joe | 7376ff5 | 2014-02-16 18:28:42 -0800 | [diff] [blame] | 383 | |
Austin Schuh | 069143b | 2014-02-17 02:46:26 -0800 | [diff] [blame] | 384 | void LimitClawGoal(double *bottom_goal, double *top_goal, |
| 385 | const frc971::constants::Values &values) { |
| 386 | // first update position based on angle limit |
| 387 | |
| 388 | const double separation = *top_goal - *bottom_goal; |
| 389 | if (separation > values.claw.claw_max_separation) { |
Austin Schuh | 069143b | 2014-02-17 02:46:26 -0800 | [diff] [blame] | 390 | const double dsep = (separation - values.claw.claw_max_separation) / 2.0; |
| 391 | *bottom_goal += dsep; |
| 392 | *top_goal -= dsep; |
| 393 | LOG(DEBUG, "Goals now bottom: %f, top: %f\n", *bottom_goal, *top_goal); |
| 394 | } |
| 395 | if (separation < values.claw.claw_min_separation) { |
Austin Schuh | 069143b | 2014-02-17 02:46:26 -0800 | [diff] [blame] | 396 | const double dsep = (separation - values.claw.claw_min_separation) / 2.0; |
| 397 | *bottom_goal += dsep; |
| 398 | *top_goal -= dsep; |
| 399 | LOG(DEBUG, "Goals now bottom: %f, top: %f\n", *bottom_goal, *top_goal); |
| 400 | } |
| 401 | |
| 402 | // now move both goals in unison |
| 403 | if (*bottom_goal < values.claw.lower_claw.lower_limit) { |
| 404 | *top_goal += values.claw.lower_claw.lower_limit - *bottom_goal; |
| 405 | *bottom_goal = values.claw.lower_claw.lower_limit; |
| 406 | } |
| 407 | if (*bottom_goal > values.claw.lower_claw.upper_limit) { |
| 408 | *top_goal -= *bottom_goal - values.claw.lower_claw.upper_limit; |
| 409 | *bottom_goal = values.claw.lower_claw.upper_limit; |
| 410 | } |
| 411 | |
| 412 | if (*top_goal < values.claw.upper_claw.lower_limit) { |
| 413 | *bottom_goal += values.claw.upper_claw.lower_limit - *top_goal; |
| 414 | *top_goal = values.claw.upper_claw.lower_limit; |
| 415 | } |
| 416 | if (*top_goal > values.claw.upper_claw.upper_limit) { |
| 417 | *bottom_goal -= *top_goal - values.claw.upper_claw.upper_limit; |
| 418 | *top_goal = values.claw.upper_claw.upper_limit; |
| 419 | } |
| 420 | } |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 421 | |
Austin Schuh | e7f90d1 | 2014-02-17 00:48:25 -0800 | [diff] [blame] | 422 | bool ClawMotor::is_ready() const { |
| 423 | return ( |
| 424 | (top_claw_.zeroing_state() == ZeroedStateFeedbackLoop::CALIBRATED && |
| 425 | bottom_claw_.zeroing_state() == ZeroedStateFeedbackLoop::CALIBRATED) || |
Brian Silverman | 71fbee0 | 2014-03-13 17:24:54 -0700 | [diff] [blame] | 426 | (((::aos::robot_state.get() == NULL) ? true |
| 427 | : ::aos::robot_state->autonomous) && |
Austin Schuh | e7f90d1 | 2014-02-17 00:48:25 -0800 | [diff] [blame] | 428 | ((top_claw_.zeroing_state() == ZeroedStateFeedbackLoop::CALIBRATED || |
| 429 | top_claw_.zeroing_state() == |
| 430 | ZeroedStateFeedbackLoop::DISABLED_CALIBRATION) && |
| 431 | (bottom_claw_.zeroing_state() == ZeroedStateFeedbackLoop::CALIBRATED || |
| 432 | bottom_claw_.zeroing_state() == |
| 433 | ZeroedStateFeedbackLoop::DISABLED_CALIBRATION)))); |
| 434 | } |
| 435 | |
| 436 | bool ClawMotor::is_zeroing() const { return !is_ready(); } |
| 437 | |
Austin Schuh | 3bb9a44 | 2014-02-02 16:01:45 -0800 | [diff] [blame] | 438 | // Positive angle is up, and positive power is up. |
Austin Schuh | cc0bf31 | 2014-02-09 00:39:29 -0800 | [diff] [blame] | 439 | void ClawMotor::RunIteration(const control_loops::ClawGroup::Goal *goal, |
| 440 | const control_loops::ClawGroup::Position *position, |
| 441 | control_loops::ClawGroup::Output *output, |
James Kuszmaul | 9ead1de | 2014-02-28 21:24:39 -0800 | [diff] [blame] | 442 | control_loops::ClawGroup::Status *status) { |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 443 | constexpr double dt = 0.01; |
Austin Schuh | 3bb9a44 | 2014-02-02 16:01:45 -0800 | [diff] [blame] | 444 | |
| 445 | // Disable the motors now so that all early returns will return with the |
| 446 | // motors disabled. |
| 447 | if (output) { |
| 448 | output->top_claw_voltage = 0; |
| 449 | output->bottom_claw_voltage = 0; |
| 450 | output->intake_voltage = 0; |
Ben Fredrickson | 61893d5 | 2014-03-02 09:43:23 +0000 | [diff] [blame] | 451 | output->tusk_voltage = 0; |
| 452 | } |
| 453 | |
Brian Silverman | 71fbee0 | 2014-03-13 17:24:54 -0700 | [diff] [blame] | 454 | if (goal) { |
| 455 | if (::std::isnan(goal->bottom_angle) || |
| 456 | ::std::isnan(goal->separation_angle) || ::std::isnan(goal->intake) || |
| 457 | ::std::isnan(goal->centering)) { |
| 458 | return; |
| 459 | } |
Austin Schuh | 3bb9a44 | 2014-02-02 16:01:45 -0800 | [diff] [blame] | 460 | } |
| 461 | |
Austin Schuh | 1a49994 | 2014-02-17 01:51:58 -0800 | [diff] [blame] | 462 | if (reset()) { |
Austin Schuh | 27b8fb1 | 2014-02-22 15:10:05 -0800 | [diff] [blame] | 463 | top_claw_.Reset(position->top); |
| 464 | bottom_claw_.Reset(position->bottom); |
Austin Schuh | 1a49994 | 2014-02-17 01:51:58 -0800 | [diff] [blame] | 465 | } |
| 466 | |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 467 | const frc971::constants::Values &values = constants::GetValues(); |
| 468 | |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 469 | if (position) { |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 470 | Eigen::Matrix<double, 2, 1> Y; |
| 471 | Y << position->bottom.position + bottom_claw_.offset(), |
| 472 | position->top.position + top_claw_.offset(); |
| 473 | claw_.Correct(Y); |
| 474 | |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 475 | top_claw_.SetPositionValues(position->top); |
| 476 | bottom_claw_.SetPositionValues(position->bottom); |
| 477 | |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 478 | if (!has_top_claw_goal_) { |
| 479 | has_top_claw_goal_ = true; |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 480 | top_claw_goal_ = top_claw_.absolute_position(); |
Austin Schuh | e7f90d1 | 2014-02-17 00:48:25 -0800 | [diff] [blame] | 481 | initial_separation_ = |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 482 | top_claw_.absolute_position() - bottom_claw_.absolute_position(); |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 483 | } |
| 484 | if (!has_bottom_claw_goal_) { |
| 485 | has_bottom_claw_goal_ = true; |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 486 | bottom_claw_goal_ = bottom_claw_.absolute_position(); |
Austin Schuh | e7f90d1 | 2014-02-17 00:48:25 -0800 | [diff] [blame] | 487 | initial_separation_ = |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 488 | top_claw_.absolute_position() - bottom_claw_.absolute_position(); |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 489 | } |
Brian Silverman | f48fab3 | 2014-03-09 14:32:24 -0700 | [diff] [blame] | 490 | LOG_STRUCT(DEBUG, "absolute position", |
| 491 | ClawPositionToLog(top_claw_.absolute_position(), |
| 492 | bottom_claw_.absolute_position())); |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 493 | } |
| 494 | |
Brian Silverman | 71fbee0 | 2014-03-13 17:24:54 -0700 | [diff] [blame] | 495 | bool autonomous, enabled; |
| 496 | if (::aos::robot_state.get() == nullptr) { |
| 497 | autonomous = true; |
| 498 | enabled = false; |
| 499 | } else { |
| 500 | autonomous = ::aos::robot_state->autonomous; |
| 501 | enabled = ::aos::robot_state->enabled; |
| 502 | } |
Austin Schuh | 069143b | 2014-02-17 02:46:26 -0800 | [diff] [blame] | 503 | |
| 504 | double bottom_claw_velocity_ = 0.0; |
| 505 | double top_claw_velocity_ = 0.0; |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 506 | |
Brian Silverman | 71fbee0 | 2014-03-13 17:24:54 -0700 | [diff] [blame] | 507 | if (goal != NULL && |
| 508 | ((top_claw_.zeroing_state() == ZeroedStateFeedbackLoop::CALIBRATED && |
| 509 | bottom_claw_.zeroing_state() == ZeroedStateFeedbackLoop::CALIBRATED) || |
| 510 | (autonomous && |
| 511 | ((top_claw_.zeroing_state() == ZeroedStateFeedbackLoop::CALIBRATED || |
| 512 | top_claw_.zeroing_state() == |
| 513 | ZeroedStateFeedbackLoop::DISABLED_CALIBRATION) && |
| 514 | (bottom_claw_.zeroing_state() == ZeroedStateFeedbackLoop::CALIBRATED || |
| 515 | bottom_claw_.zeroing_state() == |
| 516 | ZeroedStateFeedbackLoop::DISABLED_CALIBRATION))))) { |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 517 | // Ready to use the claw. |
| 518 | // Limit the goals here. |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 519 | bottom_claw_goal_ = goal->bottom_angle; |
Brian Silverman | 7c021c4 | 2014-02-17 15:15:56 -0800 | [diff] [blame] | 520 | top_claw_goal_ = goal->bottom_angle + goal->separation_angle; |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 521 | has_bottom_claw_goal_ = true; |
| 522 | has_top_claw_goal_ = true; |
| 523 | doing_calibration_fine_tune_ = false; |
| 524 | |
Austin Schuh | e7f90d1 | 2014-02-17 00:48:25 -0800 | [diff] [blame] | 525 | mode_ = READY; |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 526 | } else if (top_claw_.zeroing_state() != |
Ben Fredrickson | 81ba2d5 | 2014-03-02 08:21:46 +0000 | [diff] [blame] | 527 | ZeroedStateFeedbackLoop::UNKNOWN_POSITION && |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 528 | bottom_claw_.zeroing_state() != |
Ben Fredrickson | 81ba2d5 | 2014-03-02 08:21:46 +0000 | [diff] [blame] | 529 | ZeroedStateFeedbackLoop::UNKNOWN_POSITION) { |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 530 | // Time to fine tune the zero. |
| 531 | // Limit the goals here. |
Austin Schuh | 0c73342 | 2014-02-17 01:17:12 -0800 | [diff] [blame] | 532 | if (!enabled) { |
| 533 | // If we are disabled, start the fine tune process over again. |
| 534 | doing_calibration_fine_tune_ = false; |
| 535 | } |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 536 | if (bottom_claw_.zeroing_state() != ZeroedStateFeedbackLoop::CALIBRATED) { |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 537 | // always get the bottom claw to calibrated first |
| 538 | LOG(DEBUG, "Calibrating the bottom of the claw\n"); |
| 539 | if (!doing_calibration_fine_tune_) { |
| 540 | if (::std::abs(bottom_absolute_position() - |
Austin Schuh | d27931c | 2014-02-16 19:18:20 -0800 | [diff] [blame] | 541 | values.claw.start_fine_tune_pos) < |
| 542 | values.claw.claw_unimportant_epsilon) { |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 543 | doing_calibration_fine_tune_ = true; |
Austin Schuh | d27931c | 2014-02-16 19:18:20 -0800 | [diff] [blame] | 544 | bottom_claw_goal_ += values.claw.claw_zeroing_speed * dt; |
Austin Schuh | 069143b | 2014-02-17 02:46:26 -0800 | [diff] [blame] | 545 | top_claw_velocity_ = bottom_claw_velocity_ = |
| 546 | values.claw.claw_zeroing_speed; |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 547 | LOG(DEBUG, "Ready to fine tune the bottom\n"); |
Austin Schuh | e7f90d1 | 2014-02-17 00:48:25 -0800 | [diff] [blame] | 548 | mode_ = FINE_TUNE_BOTTOM; |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 549 | } else { |
| 550 | // send bottom to zeroing start |
Austin Schuh | d27931c | 2014-02-16 19:18:20 -0800 | [diff] [blame] | 551 | bottom_claw_goal_ = values.claw.start_fine_tune_pos; |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 552 | LOG(DEBUG, "Going to the start position for the bottom\n"); |
Austin Schuh | e7f90d1 | 2014-02-17 00:48:25 -0800 | [diff] [blame] | 553 | mode_ = PREP_FINE_TUNE_BOTTOM; |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 554 | } |
| 555 | } else { |
Austin Schuh | e7f90d1 | 2014-02-17 00:48:25 -0800 | [diff] [blame] | 556 | mode_ = FINE_TUNE_BOTTOM; |
Austin Schuh | d27931c | 2014-02-16 19:18:20 -0800 | [diff] [blame] | 557 | bottom_claw_goal_ += values.claw.claw_zeroing_speed * dt; |
Austin Schuh | 069143b | 2014-02-17 02:46:26 -0800 | [diff] [blame] | 558 | top_claw_velocity_ = bottom_claw_velocity_ = |
| 559 | values.claw.claw_zeroing_speed; |
Brian Silverman | e0a9546 | 2014-02-17 00:41:09 -0800 | [diff] [blame] | 560 | if (top_claw_.front_or_back_triggered() || |
| 561 | bottom_claw_.front_or_back_triggered()) { |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 562 | // We shouldn't hit a limit, but if we do, go back to the zeroing |
| 563 | // point and try again. |
| 564 | doing_calibration_fine_tune_ = false; |
Austin Schuh | d27931c | 2014-02-16 19:18:20 -0800 | [diff] [blame] | 565 | bottom_claw_goal_ = values.claw.start_fine_tune_pos; |
Austin Schuh | 069143b | 2014-02-17 02:46:26 -0800 | [diff] [blame] | 566 | top_claw_velocity_ = bottom_claw_velocity_ = 0.0; |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 567 | LOG(DEBUG, "Found a limit, starting over.\n"); |
Austin Schuh | e7f90d1 | 2014-02-17 00:48:25 -0800 | [diff] [blame] | 568 | mode_ = PREP_FINE_TUNE_BOTTOM; |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 569 | } |
Austin Schuh | 288c8c3 | 2014-02-16 17:20:17 -0800 | [diff] [blame] | 570 | |
Ben Fredrickson | 81ba2d5 | 2014-03-02 08:21:46 +0000 | [diff] [blame] | 571 | if (position && bottom_claw_.SawFilteredPosedge( |
| 572 | bottom_claw_.calibration(), bottom_claw_.front(), |
| 573 | bottom_claw_.back())) { |
Ben Fredrickson | eaecbbb | 2014-02-23 12:12:03 +0000 | [diff] [blame] | 574 | // do calibration |
| 575 | bottom_claw_.SetCalibration( |
| 576 | position->bottom.posedge_value, |
| 577 | values.claw.lower_claw.calibration.lower_angle); |
| 578 | bottom_claw_.set_zeroing_state(ZeroedStateFeedbackLoop::CALIBRATED); |
| 579 | // calibrated so we are done fine tuning bottom |
| 580 | doing_calibration_fine_tune_ = false; |
| 581 | LOG(DEBUG, "Calibrated the bottom correctly!\n"); |
| 582 | } else if (bottom_claw_.calibration().last_value()) { |
| 583 | doing_calibration_fine_tune_ = false; |
| 584 | bottom_claw_goal_ = values.claw.start_fine_tune_pos; |
| 585 | top_claw_velocity_ = bottom_claw_velocity_ = 0.0; |
| 586 | mode_ = PREP_FINE_TUNE_BOTTOM; |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 587 | } else { |
| 588 | LOG(DEBUG, "Fine tuning\n"); |
| 589 | } |
| 590 | } |
| 591 | // now set the top claw to track |
| 592 | |
Austin Schuh | d27931c | 2014-02-16 19:18:20 -0800 | [diff] [blame] | 593 | top_claw_goal_ = bottom_claw_goal_ + values.claw.claw_zeroing_separation; |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 594 | } else { |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 595 | // bottom claw must be calibrated, start on the top |
| 596 | if (!doing_calibration_fine_tune_) { |
Austin Schuh | d27931c | 2014-02-16 19:18:20 -0800 | [diff] [blame] | 597 | if (::std::abs(top_absolute_position() - |
| 598 | values.claw.start_fine_tune_pos) < |
| 599 | values.claw.claw_unimportant_epsilon) { |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 600 | doing_calibration_fine_tune_ = true; |
Austin Schuh | d27931c | 2014-02-16 19:18:20 -0800 | [diff] [blame] | 601 | top_claw_goal_ += values.claw.claw_zeroing_speed * dt; |
Austin Schuh | 069143b | 2014-02-17 02:46:26 -0800 | [diff] [blame] | 602 | top_claw_velocity_ = bottom_claw_velocity_ = |
| 603 | values.claw.claw_zeroing_speed; |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 604 | LOG(DEBUG, "Ready to fine tune the top\n"); |
Austin Schuh | e7f90d1 | 2014-02-17 00:48:25 -0800 | [diff] [blame] | 605 | mode_ = FINE_TUNE_TOP; |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 606 | } else { |
| 607 | // send top to zeroing start |
Austin Schuh | d27931c | 2014-02-16 19:18:20 -0800 | [diff] [blame] | 608 | top_claw_goal_ = values.claw.start_fine_tune_pos; |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 609 | LOG(DEBUG, "Going to the start position for the top\n"); |
Austin Schuh | e7f90d1 | 2014-02-17 00:48:25 -0800 | [diff] [blame] | 610 | mode_ = PREP_FINE_TUNE_TOP; |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 611 | } |
| 612 | } else { |
Austin Schuh | e7f90d1 | 2014-02-17 00:48:25 -0800 | [diff] [blame] | 613 | mode_ = FINE_TUNE_TOP; |
Austin Schuh | d27931c | 2014-02-16 19:18:20 -0800 | [diff] [blame] | 614 | top_claw_goal_ += values.claw.claw_zeroing_speed * dt; |
Austin Schuh | 069143b | 2014-02-17 02:46:26 -0800 | [diff] [blame] | 615 | top_claw_velocity_ = bottom_claw_velocity_ = |
| 616 | values.claw.claw_zeroing_speed; |
Brian Silverman | e0a9546 | 2014-02-17 00:41:09 -0800 | [diff] [blame] | 617 | if (top_claw_.front_or_back_triggered() || |
| 618 | bottom_claw_.front_or_back_triggered()) { |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 619 | // this should not happen, but now we know it won't |
| 620 | doing_calibration_fine_tune_ = false; |
Austin Schuh | d27931c | 2014-02-16 19:18:20 -0800 | [diff] [blame] | 621 | top_claw_goal_ = values.claw.start_fine_tune_pos; |
Austin Schuh | 069143b | 2014-02-17 02:46:26 -0800 | [diff] [blame] | 622 | top_claw_velocity_ = bottom_claw_velocity_ = 0.0; |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 623 | LOG(DEBUG, "Found a limit, starting over.\n"); |
Austin Schuh | e7f90d1 | 2014-02-17 00:48:25 -0800 | [diff] [blame] | 624 | mode_ = PREP_FINE_TUNE_TOP; |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 625 | } |
Ben Fredrickson | eaecbbb | 2014-02-23 12:12:03 +0000 | [diff] [blame] | 626 | |
| 627 | if (position && |
| 628 | top_claw_.SawFilteredPosedge(top_claw_.calibration(), |
| 629 | top_claw_.front(), top_claw_.back())) { |
| 630 | // do calibration |
| 631 | top_claw_.SetCalibration( |
| 632 | position->top.posedge_value, |
| 633 | values.claw.upper_claw.calibration.lower_angle); |
| 634 | top_claw_.set_zeroing_state(ZeroedStateFeedbackLoop::CALIBRATED); |
| 635 | // calibrated so we are done fine tuning top |
| 636 | doing_calibration_fine_tune_ = false; |
| 637 | LOG(DEBUG, "Calibrated the top correctly!\n"); |
| 638 | } else if (top_claw_.calibration().last_value()) { |
| 639 | doing_calibration_fine_tune_ = false; |
| 640 | top_claw_goal_ = values.claw.start_fine_tune_pos; |
| 641 | top_claw_velocity_ = bottom_claw_velocity_ = 0.0; |
| 642 | mode_ = PREP_FINE_TUNE_TOP; |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 643 | } |
| 644 | } |
| 645 | // now set the bottom claw to track |
Austin Schuh | d27931c | 2014-02-16 19:18:20 -0800 | [diff] [blame] | 646 | bottom_claw_goal_ = top_claw_goal_ - values.claw.claw_zeroing_separation; |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 647 | } |
| 648 | } else { |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 649 | doing_calibration_fine_tune_ = false; |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 650 | if (!was_enabled_ && enabled) { |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 651 | if (position) { |
Brian Silverman | 7203569 | 2014-03-14 10:18:27 -0700 | [diff] [blame] | 652 | top_claw_goal_ = position->top.position + top_claw_.offset(); |
| 653 | bottom_claw_goal_ = position->bottom.position + bottom_claw_.offset(); |
Austin Schuh | e7f90d1 | 2014-02-17 00:48:25 -0800 | [diff] [blame] | 654 | initial_separation_ = |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 655 | position->top.position - position->bottom.position; |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 656 | } else { |
| 657 | has_top_claw_goal_ = false; |
| 658 | has_bottom_claw_goal_ = false; |
| 659 | } |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 660 | } |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 661 | |
Austin Schuh | 4cb047f | 2014-02-16 21:10:19 -0800 | [diff] [blame] | 662 | if ((bottom_claw_.zeroing_state() != |
| 663 | ZeroedStateFeedbackLoop::UNKNOWN_POSITION || |
Brian Silverman | e0a9546 | 2014-02-17 00:41:09 -0800 | [diff] [blame] | 664 | bottom_claw_.front().value() || top_claw_.front().value()) && |
| 665 | !top_claw_.back().value() && !bottom_claw_.back().value()) { |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 666 | if (enabled) { |
| 667 | // Time to slowly move back up to find any position to narrow down the |
| 668 | // zero. |
Austin Schuh | d27931c | 2014-02-16 19:18:20 -0800 | [diff] [blame] | 669 | top_claw_goal_ += values.claw.claw_zeroing_off_speed * dt; |
| 670 | bottom_claw_goal_ += values.claw.claw_zeroing_off_speed * dt; |
Austin Schuh | 069143b | 2014-02-17 02:46:26 -0800 | [diff] [blame] | 671 | top_claw_velocity_ = bottom_claw_velocity_ = |
| 672 | values.claw.claw_zeroing_off_speed; |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 673 | LOG(DEBUG, "Bottom is known.\n"); |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 674 | } |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 675 | } else { |
| 676 | // We don't know where either claw is. Slowly start moving down to find |
| 677 | // any hall effect. |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 678 | if (enabled) { |
Austin Schuh | d27931c | 2014-02-16 19:18:20 -0800 | [diff] [blame] | 679 | top_claw_goal_ -= values.claw.claw_zeroing_off_speed * dt; |
| 680 | bottom_claw_goal_ -= values.claw.claw_zeroing_off_speed * dt; |
Austin Schuh | 069143b | 2014-02-17 02:46:26 -0800 | [diff] [blame] | 681 | top_claw_velocity_ = bottom_claw_velocity_ = |
| 682 | -values.claw.claw_zeroing_off_speed; |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 683 | LOG(DEBUG, "Both are unknown.\n"); |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 684 | } |
| 685 | } |
| 686 | |
Ben Fredrickson | eaecbbb | 2014-02-23 12:12:03 +0000 | [diff] [blame] | 687 | if (position) { |
| 688 | if (enabled) { |
| 689 | top_claw_.SetCalibrationOnEdge( |
| 690 | values.claw.upper_claw, |
| 691 | ZeroedStateFeedbackLoop::APPROXIMATE_CALIBRATION); |
| 692 | bottom_claw_.SetCalibrationOnEdge( |
| 693 | values.claw.lower_claw, |
| 694 | ZeroedStateFeedbackLoop::APPROXIMATE_CALIBRATION); |
| 695 | } else { |
| 696 | // TODO(austin): Only calibrate on the predetermined edge. |
| 697 | // We might be able to just ignore this since the backlash is soooo |
| 698 | // low. |
| 699 | // :) |
| 700 | top_claw_.SetCalibrationOnEdge( |
| 701 | values.claw.upper_claw, |
| 702 | ZeroedStateFeedbackLoop::DISABLED_CALIBRATION); |
| 703 | bottom_claw_.SetCalibrationOnEdge( |
| 704 | values.claw.lower_claw, |
| 705 | ZeroedStateFeedbackLoop::DISABLED_CALIBRATION); |
| 706 | } |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 707 | } |
Austin Schuh | e7f90d1 | 2014-02-17 00:48:25 -0800 | [diff] [blame] | 708 | mode_ = UNKNOWN_LOCATION; |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 709 | } |
| 710 | |
Austin Schuh | 069143b | 2014-02-17 02:46:26 -0800 | [diff] [blame] | 711 | // Limit the goals if both claws have been (mostly) found. |
| 712 | if (mode_ != UNKNOWN_LOCATION) { |
| 713 | LimitClawGoal(&bottom_claw_goal_, &top_claw_goal_, values); |
| 714 | } |
| 715 | |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 716 | if (has_top_claw_goal_ && has_bottom_claw_goal_) { |
Austin Schuh | 069143b | 2014-02-17 02:46:26 -0800 | [diff] [blame] | 717 | claw_.R << bottom_claw_goal_, top_claw_goal_ - bottom_claw_goal_, |
| 718 | bottom_claw_velocity_, top_claw_velocity_ - bottom_claw_velocity_; |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 719 | double separation = -971; |
| 720 | if (position != nullptr) { |
| 721 | separation = position->top.position - position->bottom.position; |
| 722 | } |
Brian Silverman | f48fab3 | 2014-03-09 14:32:24 -0700 | [diff] [blame] | 723 | LOG_STRUCT(DEBUG, "actual goal", |
| 724 | ClawGoalToLog(claw_.R(0, 0), claw_.R(1, 0), separation)); |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 725 | |
Austin Schuh | 01c652b | 2014-02-21 23:13:42 -0800 | [diff] [blame] | 726 | // Only cap power when one of the halves of the claw is moving slowly and |
| 727 | // could wind up. |
Austin Schuh | e7f90d1 | 2014-02-17 00:48:25 -0800 | [diff] [blame] | 728 | claw_.set_is_zeroing(mode_ == UNKNOWN_LOCATION || mode_ == FINE_TUNE_TOP || |
| 729 | mode_ == FINE_TUNE_BOTTOM); |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 730 | claw_.Update(output == nullptr); |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 731 | } else { |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 732 | claw_.Update(true); |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 733 | } |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 734 | |
Austin Schuh | 4cb047f | 2014-02-16 21:10:19 -0800 | [diff] [blame] | 735 | capped_goal_ = false; |
Austin Schuh | e7f90d1 | 2014-02-17 00:48:25 -0800 | [diff] [blame] | 736 | switch (mode_) { |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 737 | case READY: |
Austin Schuh | e7f90d1 | 2014-02-17 00:48:25 -0800 | [diff] [blame] | 738 | case PREP_FINE_TUNE_TOP: |
| 739 | case PREP_FINE_TUNE_BOTTOM: |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 740 | break; |
Austin Schuh | e7f90d1 | 2014-02-17 00:48:25 -0800 | [diff] [blame] | 741 | case FINE_TUNE_BOTTOM: |
| 742 | case FINE_TUNE_TOP: |
Austin Schuh | 4cb047f | 2014-02-16 21:10:19 -0800 | [diff] [blame] | 743 | case UNKNOWN_LOCATION: { |
James Kuszmaul | 0e86651 | 2014-02-21 13:12:52 -0800 | [diff] [blame] | 744 | Eigen::Matrix<double, 2, 1> U = claw_.K() * (claw_.R - claw_.X_hat); |
James Kuszmaul | f63b0ae | 2014-03-25 16:52:11 -0700 | [diff] [blame] | 745 | LOG(DEBUG, "Uncapped voltages: Top: %f, Bottom: %f\n", U(1, 0), U(0, 0)); |
Austin Schuh | 4cb047f | 2014-02-16 21:10:19 -0800 | [diff] [blame] | 746 | if (claw_.uncapped_average_voltage() > values.claw.max_zeroing_voltage) { |
James Kuszmaul | 0e86651 | 2014-02-21 13:12:52 -0800 | [diff] [blame] | 747 | double dx_bot = (U(0, 0) - |
Austin Schuh | 4cb047f | 2014-02-16 21:10:19 -0800 | [diff] [blame] | 748 | values.claw.max_zeroing_voltage) / |
| 749 | claw_.K(0, 0); |
James Kuszmaul | 0e86651 | 2014-02-21 13:12:52 -0800 | [diff] [blame] | 750 | double dx_top = (U(1, 0) - |
| 751 | values.claw.max_zeroing_voltage) / |
| 752 | claw_.K(0, 0); |
| 753 | double dx = ::std::max(dx_top, dx_bot); |
Austin Schuh | 4cb047f | 2014-02-16 21:10:19 -0800 | [diff] [blame] | 754 | bottom_claw_goal_ -= dx; |
| 755 | top_claw_goal_ -= dx; |
James Kuszmaul | 0e86651 | 2014-02-21 13:12:52 -0800 | [diff] [blame] | 756 | Eigen::Matrix<double, 4, 1> R; |
| 757 | R << bottom_claw_goal_, top_claw_goal_ - bottom_claw_goal_, claw_.R(2, 0), claw_.R(3, 0); |
| 758 | U = claw_.K() * (R - claw_.X_hat); |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 759 | capped_goal_ = true; |
Brian Silverman | f48fab3 | 2014-03-09 14:32:24 -0700 | [diff] [blame] | 760 | LOG(DEBUG, "Moving the goal by %f to prevent windup." |
| 761 | " Uncapped is %f, max is %f, difference is %f\n", |
| 762 | dx, |
Austin Schuh | e7f90d1 | 2014-02-17 00:48:25 -0800 | [diff] [blame] | 763 | claw_.uncapped_average_voltage(), values.claw.max_zeroing_voltage, |
| 764 | (claw_.uncapped_average_voltage() - |
| 765 | values.claw.max_zeroing_voltage)); |
Austin Schuh | 4cb047f | 2014-02-16 21:10:19 -0800 | [diff] [blame] | 766 | } else if (claw_.uncapped_average_voltage() < |
| 767 | -values.claw.max_zeroing_voltage) { |
James Kuszmaul | 0e86651 | 2014-02-21 13:12:52 -0800 | [diff] [blame] | 768 | double dx_bot = (U(0, 0) + |
Austin Schuh | 4cb047f | 2014-02-16 21:10:19 -0800 | [diff] [blame] | 769 | values.claw.max_zeroing_voltage) / |
| 770 | claw_.K(0, 0); |
James Kuszmaul | 0e86651 | 2014-02-21 13:12:52 -0800 | [diff] [blame] | 771 | double dx_top = (U(1, 0) + |
| 772 | values.claw.max_zeroing_voltage) / |
| 773 | claw_.K(0, 0); |
| 774 | double dx = ::std::min(dx_top, dx_bot); |
Austin Schuh | 4cb047f | 2014-02-16 21:10:19 -0800 | [diff] [blame] | 775 | bottom_claw_goal_ -= dx; |
| 776 | top_claw_goal_ -= dx; |
James Kuszmaul | 0e86651 | 2014-02-21 13:12:52 -0800 | [diff] [blame] | 777 | Eigen::Matrix<double, 4, 1> R; |
| 778 | R << bottom_claw_goal_, top_claw_goal_ - bottom_claw_goal_, claw_.R(2, 0), claw_.R(3, 0); |
| 779 | U = claw_.K() * (R - claw_.X_hat); |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 780 | capped_goal_ = true; |
Austin Schuh | 4cb047f | 2014-02-16 21:10:19 -0800 | [diff] [blame] | 781 | LOG(DEBUG, "Moving the goal by %f to prevent windup\n", dx); |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 782 | } |
Austin Schuh | 4cb047f | 2014-02-16 21:10:19 -0800 | [diff] [blame] | 783 | } break; |
Austin Schuh | 3bb9a44 | 2014-02-02 16:01:45 -0800 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | if (output) { |
Ben Fredrickson | 2f76ddf | 2014-02-23 05:58:23 +0000 | [diff] [blame] | 787 | if (goal) { |
| 788 | //setup the intake |
Ben Fredrickson | 81ba2d5 | 2014-03-02 08:21:46 +0000 | [diff] [blame] | 789 | output->intake_voltage = |
| 790 | (goal->intake > 12.0) ? 12 : (goal->intake < -12.0) ? -12.0 |
| 791 | : goal->intake; |
Ben Fredrickson | 2f76ddf | 2014-02-23 05:58:23 +0000 | [diff] [blame] | 792 | output->tusk_voltage = goal->centering; |
Ben Fredrickson | 81ba2d5 | 2014-03-02 08:21:46 +0000 | [diff] [blame] | 793 | output->tusk_voltage = |
| 794 | (goal->centering > 12.0) ? 12 : (goal->centering < -12.0) |
| 795 | ? -12.0 |
| 796 | : goal->centering; |
Ben Fredrickson | 2f76ddf | 2014-02-23 05:58:23 +0000 | [diff] [blame] | 797 | } |
James Kuszmaul | d536a40 | 2014-02-18 22:32:12 -0800 | [diff] [blame] | 798 | output->top_claw_voltage = claw_.U(1, 0); |
Ben Fredrickson | 81ba2d5 | 2014-03-02 08:21:46 +0000 | [diff] [blame] | 799 | output->bottom_claw_voltage = claw_.U(0, 0); |
Austin Schuh | f84a130 | 2014-02-19 00:23:30 -0800 | [diff] [blame] | 800 | |
| 801 | if (output->top_claw_voltage > kMaxVoltage) { |
| 802 | output->top_claw_voltage = kMaxVoltage; |
| 803 | } else if (output->top_claw_voltage < -kMaxVoltage) { |
| 804 | output->top_claw_voltage = -kMaxVoltage; |
| 805 | } |
| 806 | |
| 807 | if (output->bottom_claw_voltage > kMaxVoltage) { |
| 808 | output->bottom_claw_voltage = kMaxVoltage; |
| 809 | } else if (output->bottom_claw_voltage < -kMaxVoltage) { |
| 810 | output->bottom_claw_voltage = -kMaxVoltage; |
| 811 | } |
Austin Schuh | 3bb9a44 | 2014-02-02 16:01:45 -0800 | [diff] [blame] | 812 | } |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 813 | |
James Kuszmaul | 4abaf48 | 2014-02-26 21:16:35 -0800 | [diff] [blame] | 814 | status->bottom = bottom_absolute_position(); |
| 815 | status->separation = top_absolute_position() - bottom_absolute_position(); |
| 816 | status->bottom_velocity = claw_.X_hat(2, 0); |
| 817 | status->separation_velocity = claw_.X_hat(3, 0); |
Austin Schuh | 4b7b5d0 | 2014-02-10 21:20:34 -0800 | [diff] [blame] | 818 | |
Brian Silverman | 71fbee0 | 2014-03-13 17:24:54 -0700 | [diff] [blame] | 819 | if (goal) { |
| 820 | bool bottom_done = |
| 821 | ::std::abs(bottom_absolute_position() - goal->bottom_angle) < 0.020; |
| 822 | bool bottom_velocity_done = ::std::abs(status->bottom_velocity) < 0.2; |
| 823 | bool separation_done = |
| 824 | ::std::abs((top_absolute_position() - bottom_absolute_position()) - |
| 825 | goal->separation_angle) < 0.020; |
| 826 | bool separation_done_with_ball = |
| 827 | ::std::abs((top_absolute_position() - bottom_absolute_position()) - |
| 828 | goal->separation_angle) < 0.06; |
| 829 | status->done = is_ready() && separation_done && bottom_done && bottom_velocity_done; |
| 830 | status->done_with_ball = |
| 831 | is_ready() && separation_done_with_ball && bottom_done && bottom_velocity_done; |
| 832 | } else { |
| 833 | status->done = status->done_with_ball = false; |
| 834 | } |
Austin Schuh | a556b01 | 2014-03-02 11:55:52 -0800 | [diff] [blame] | 835 | |
Austin Schuh | 4f8633f | 2014-03-02 13:59:46 -0800 | [diff] [blame] | 836 | status->zeroed = is_ready(); |
Brian Silverman | 80fc94c | 2014-03-09 16:56:01 -0700 | [diff] [blame] | 837 | status->zeroed_for_auto = |
| 838 | (top_claw_.zeroing_state() == ZeroedStateFeedbackLoop::CALIBRATED || |
| 839 | top_claw_.zeroing_state() == |
| 840 | ZeroedStateFeedbackLoop::DISABLED_CALIBRATION) && |
| 841 | (bottom_claw_.zeroing_state() == ZeroedStateFeedbackLoop::CALIBRATED || |
| 842 | bottom_claw_.zeroing_state() == |
| 843 | ZeroedStateFeedbackLoop::DISABLED_CALIBRATION); |
Austin Schuh | 4f8633f | 2014-03-02 13:59:46 -0800 | [diff] [blame] | 844 | |
Brian Silverman | 71fbee0 | 2014-03-13 17:24:54 -0700 | [diff] [blame] | 845 | was_enabled_ = enabled; |
Austin Schuh | 3bb9a44 | 2014-02-02 16:01:45 -0800 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | } // namespace control_loops |
| 849 | } // namespace frc971 |
Ben Fredrickson | 81ba2d5 | 2014-03-02 08:21:46 +0000 | [diff] [blame] | 850 | |