Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 1 | #include "y2018/control_loops/superstructure/arm/arm.h" |
| 2 | |
| 3 | #include <chrono> |
| 4 | #include <iostream> |
| 5 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame^] | 6 | #include "aos/logging/logging.h" |
| 7 | #include "aos/logging/queue_logging.h" |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 8 | #include "y2018/constants.h" |
| 9 | #include "y2018/control_loops/superstructure/arm/demo_path.h" |
| 10 | #include "y2018/control_loops/superstructure/arm/dynamics.h" |
Austin Schuh | 7dfccf6 | 2018-03-03 21:28:14 -0800 | [diff] [blame] | 11 | #include "y2018/control_loops/superstructure/arm/generated_graph.h" |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 12 | |
| 13 | namespace y2018 { |
| 14 | namespace control_loops { |
| 15 | namespace superstructure { |
| 16 | namespace arm { |
| 17 | |
Austin Schuh | 7afcc23 | 2018-09-16 16:33:47 -0700 | [diff] [blame] | 18 | namespace { |
| 19 | |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 20 | namespace chrono = ::std::chrono; |
| 21 | using ::aos::monotonic_clock; |
| 22 | |
Austin Schuh | 7afcc23 | 2018-09-16 16:33:47 -0700 | [diff] [blame] | 23 | constexpr int kMaxBrownoutCount = 4; |
| 24 | |
| 25 | } // namespace |
| 26 | |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 27 | Arm::Arm() |
| 28 | : proximal_zeroing_estimator_(constants::GetValues().arm_proximal.zeroing), |
| 29 | distal_zeroing_estimator_(constants::GetValues().arm_distal.zeroing), |
| 30 | alpha_unitizer_((::Eigen::Matrix<double, 2, 2>() << 1.0 / kAlpha0Max(), |
| 31 | 0.0, 0.0, 1.0 / kAlpha1Max()) |
| 32 | .finished()), |
Austin Schuh | 7dfccf6 | 2018-03-03 21:28:14 -0800 | [diff] [blame] | 33 | search_graph_(MakeSearchGraph(&trajectories_, alpha_unitizer_, kVMax())), |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 34 | // Go to the start of the first trajectory. |
Austin Schuh | b874fd3 | 2018-03-05 00:27:10 -0800 | [diff] [blame] | 35 | follower_(ReadyAboveBoxPoint()), |
| 36 | points_(PointList()) { |
Austin Schuh | 7dfccf6 | 2018-03-03 21:28:14 -0800 | [diff] [blame] | 37 | int i = 0; |
| 38 | for (const auto &trajectory : trajectories_) { |
| 39 | LOG(INFO, "trajectory length for edge node %d: %f\n", i, |
Austin Schuh | 41c71e4 | 2018-04-04 20:11:20 -0700 | [diff] [blame] | 40 | trajectory.trajectory.path().length()); |
Austin Schuh | 7dfccf6 | 2018-03-03 21:28:14 -0800 | [diff] [blame] | 41 | ++i; |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | |
| 45 | void Arm::Reset() { state_ = State::UNINITIALIZED; } |
| 46 | |
Austin Schuh | 9634153 | 2018-03-09 21:17:24 -0800 | [diff] [blame] | 47 | void Arm::Iterate(const uint32_t *unsafe_goal, bool grab_box, bool open_claw, |
Neil Balch | ba9cbba | 2018-04-06 22:26:38 -0700 | [diff] [blame] | 48 | bool close_claw, const control_loops::ArmPosition *position, |
Austin Schuh | 9634153 | 2018-03-09 21:17:24 -0800 | [diff] [blame] | 49 | const bool claw_beambreak_triggered, |
| 50 | const bool box_back_beambreak_triggered, |
Austin Schuh | d76546a | 2018-07-08 16:05:14 -0700 | [diff] [blame] | 51 | const bool intake_clear_of_box, bool suicide, |
| 52 | bool trajectory_override, double *proximal_output, |
Austin Schuh | 9634153 | 2018-03-09 21:17:24 -0800 | [diff] [blame] | 53 | double *distal_output, bool *release_arm_brake, |
Austin Schuh | d76546a | 2018-07-08 16:05:14 -0700 | [diff] [blame] | 54 | bool *claw_closed, control_loops::ArmStatus *status) { |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 55 | ::Eigen::Matrix<double, 2, 1> Y; |
Austin Schuh | 9634153 | 2018-03-09 21:17:24 -0800 | [diff] [blame] | 56 | const bool outputs_disabled = |
| 57 | ((proximal_output == nullptr) || (distal_output == nullptr) || |
| 58 | (release_arm_brake == nullptr) || (claw_closed == nullptr)); |
Austin Schuh | 7afcc23 | 2018-09-16 16:33:47 -0700 | [diff] [blame] | 59 | if (outputs_disabled) { |
| 60 | ++brownout_count_; |
| 61 | } else { |
| 62 | brownout_count_ = 0; |
| 63 | } |
Austin Schuh | 9634153 | 2018-03-09 21:17:24 -0800 | [diff] [blame] | 64 | |
| 65 | uint32_t filtered_goal = 0; |
| 66 | if (unsafe_goal != nullptr) { |
| 67 | filtered_goal = *unsafe_goal; |
| 68 | } |
| 69 | |
| 70 | if (open_claw) { |
| 71 | claw_closed_ = false; |
| 72 | } |
Neil Balch | ba9cbba | 2018-04-06 22:26:38 -0700 | [diff] [blame] | 73 | if (close_claw) { |
Austin Schuh | 9634153 | 2018-03-09 21:17:24 -0800 | [diff] [blame] | 74 | claw_closed_ = true; |
| 75 | } |
Neil Balch | ba9cbba | 2018-04-06 22:26:38 -0700 | [diff] [blame] | 76 | if (outputs_disabled) { |
| 77 | if (claw_closed_count_ == 0) { |
| 78 | claw_closed_ = true; |
| 79 | } else { |
| 80 | --claw_closed_count_; |
| 81 | } |
| 82 | } else { |
| 83 | // Wait this many iterations before closing the claw. That prevents |
| 84 | // brownouts from closing the claw. |
| 85 | claw_closed_count_ = 50; |
| 86 | } |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 87 | |
| 88 | Y << position->proximal.encoder + proximal_offset_, |
| 89 | position->distal.encoder + distal_offset_; |
| 90 | |
| 91 | proximal_zeroing_estimator_.UpdateEstimate(position->proximal); |
| 92 | distal_zeroing_estimator_.UpdateEstimate(position->distal); |
| 93 | |
| 94 | if (proximal_output != nullptr) { |
| 95 | *proximal_output = 0.0; |
| 96 | } |
| 97 | if (distal_output != nullptr) { |
| 98 | *distal_output = 0.0; |
| 99 | } |
| 100 | |
| 101 | arm_ekf_.Correct(Y, kDt()); |
| 102 | |
| 103 | if (::std::abs(arm_ekf_.X_hat(0) - follower_.theta(0)) <= 0.05 && |
| 104 | ::std::abs(arm_ekf_.X_hat(2) - follower_.theta(1)) <= 0.05) { |
| 105 | close_enough_for_full_power_ = true; |
| 106 | } |
| 107 | if (::std::abs(arm_ekf_.X_hat(0) - follower_.theta(0)) >= 1.10 || |
| 108 | ::std::abs(arm_ekf_.X_hat(2) - follower_.theta(1)) >= 1.10) { |
| 109 | close_enough_for_full_power_ = false; |
| 110 | } |
| 111 | |
| 112 | switch (state_) { |
| 113 | case State::UNINITIALIZED: |
| 114 | // Wait in the uninitialized state until the intake is initialized. |
| 115 | LOG(DEBUG, "Uninitialized, waiting for intake\n"); |
| 116 | state_ = State::ZEROING; |
| 117 | proximal_zeroing_estimator_.Reset(); |
| 118 | distal_zeroing_estimator_.Reset(); |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 119 | break; |
| 120 | |
| 121 | case State::ZEROING: |
| 122 | // Zero by not moving. |
| 123 | if (proximal_zeroing_estimator_.zeroed() && |
| 124 | distal_zeroing_estimator_.zeroed()) { |
Austin Schuh | 9634153 | 2018-03-09 21:17:24 -0800 | [diff] [blame] | 125 | state_ = State::DISABLED; |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 126 | |
| 127 | proximal_offset_ = proximal_zeroing_estimator_.offset(); |
| 128 | distal_offset_ = distal_zeroing_estimator_.offset(); |
| 129 | |
| 130 | Y << position->proximal.encoder + proximal_offset_, |
| 131 | position->distal.encoder + distal_offset_; |
| 132 | |
| 133 | // TODO(austin): Offset ekf rather than reset it. Since we aren't |
| 134 | // moving at this point, it's pretty safe to do this. |
| 135 | ::Eigen::Matrix<double, 4, 1> X; |
| 136 | X << Y(0), 0.0, Y(1), 0.0; |
| 137 | arm_ekf_.Reset(X); |
| 138 | } else { |
| 139 | break; |
| 140 | } |
| 141 | |
Austin Schuh | b874fd3 | 2018-03-05 00:27:10 -0800 | [diff] [blame] | 142 | case State::DISABLED: { |
| 143 | follower_.SwitchTrajectory(nullptr); |
| 144 | close_enough_for_full_power_ = false; |
Austin Schuh | 9634153 | 2018-03-09 21:17:24 -0800 | [diff] [blame] | 145 | |
Austin Schuh | b874fd3 | 2018-03-05 00:27:10 -0800 | [diff] [blame] | 146 | const ::Eigen::Matrix<double, 2, 1> current_theta = |
| 147 | (::Eigen::Matrix<double, 2, 1>() << arm_ekf_.X_hat(0), |
| 148 | arm_ekf_.X_hat(2)) |
| 149 | .finished(); |
| 150 | uint32_t best_index = 0; |
| 151 | double best_distance = (points_[0] - current_theta).norm(); |
| 152 | uint32_t current_index = 0; |
| 153 | for (const ::Eigen::Matrix<double, 2, 1> &point : points_) { |
| 154 | const double new_distance = (point - current_theta).norm(); |
| 155 | if (new_distance < best_distance) { |
| 156 | best_distance = new_distance; |
| 157 | best_index = current_index; |
| 158 | } |
| 159 | ++current_index; |
| 160 | } |
| 161 | follower_.set_theta(points_[best_index]); |
| 162 | current_node_ = best_index; |
| 163 | |
| 164 | if (!outputs_disabled) { |
Austin Schuh | 9634153 | 2018-03-09 21:17:24 -0800 | [diff] [blame] | 165 | state_ = State::GOTO_PATH; |
| 166 | } else { |
| 167 | break; |
| 168 | } |
Austin Schuh | b874fd3 | 2018-03-05 00:27:10 -0800 | [diff] [blame] | 169 | } |
Austin Schuh | 9634153 | 2018-03-09 21:17:24 -0800 | [diff] [blame] | 170 | |
| 171 | case State::GOTO_PATH: |
| 172 | if (outputs_disabled) { |
| 173 | state_ = State::DISABLED; |
Austin Schuh | d76546a | 2018-07-08 16:05:14 -0700 | [diff] [blame] | 174 | } else if (trajectory_override) { |
| 175 | follower_.SwitchTrajectory(nullptr); |
| 176 | current_node_ = filtered_goal; |
| 177 | follower_.set_theta(points_[current_node_]); |
| 178 | state_ = State::GOTO_PATH; |
Austin Schuh | 9634153 | 2018-03-09 21:17:24 -0800 | [diff] [blame] | 179 | } else if (close_enough_for_full_power_) { |
| 180 | state_ = State::RUNNING; |
| 181 | grab_state_ = GrabState::NORMAL; |
| 182 | } |
| 183 | break; |
| 184 | |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 185 | case State::RUNNING: |
| 186 | // ESTOP if we hit the hard limits. |
| 187 | // TODO(austin): Pick some sane limits. |
| 188 | if (proximal_zeroing_estimator_.error() || |
| 189 | distal_zeroing_estimator_.error()) { |
| 190 | LOG(ERROR, "Zeroing error ESTOP\n"); |
| 191 | state_ = State::ESTOP; |
Austin Schuh | 7afcc23 | 2018-09-16 16:33:47 -0700 | [diff] [blame] | 192 | } else if (outputs_disabled && brownout_count_ > kMaxBrownoutCount) { |
Austin Schuh | 9634153 | 2018-03-09 21:17:24 -0800 | [diff] [blame] | 193 | state_ = State::DISABLED; |
Austin Schuh | d76546a | 2018-07-08 16:05:14 -0700 | [diff] [blame] | 194 | } else if (trajectory_override) { |
| 195 | follower_.SwitchTrajectory(nullptr); |
| 196 | current_node_ = filtered_goal; |
| 197 | follower_.set_theta(points_[current_node_]); |
| 198 | state_ = State::GOTO_PATH; |
Austin Schuh | 17e484e | 2018-03-11 01:11:36 -0800 | [diff] [blame] | 199 | } else if (suicide) { |
| 200 | state_ = State::PREP_CLIMB; |
| 201 | climb_count_ = 50; |
| 202 | } |
| 203 | break; |
| 204 | |
| 205 | case State::PREP_CLIMB: |
| 206 | --climb_count_; |
| 207 | if (climb_count_ <= 0) { |
| 208 | state_ = State::ESTOP; |
| 209 | } else if (!suicide) { |
| 210 | state_ = State::RUNNING; |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 211 | } |
| 212 | break; |
| 213 | |
| 214 | case State::ESTOP: |
| 215 | LOG(ERROR, "Estop\n"); |
| 216 | break; |
| 217 | } |
| 218 | |
Austin Schuh | 17e484e | 2018-03-11 01:11:36 -0800 | [diff] [blame] | 219 | const bool disable = outputs_disabled || (state_ != State::RUNNING && |
| 220 | state_ != State::GOTO_PATH && |
| 221 | state_ != State::PREP_CLIMB); |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 222 | if (disable) { |
| 223 | close_enough_for_full_power_ = false; |
| 224 | } |
| 225 | |
Austin Schuh | b874fd3 | 2018-03-05 00:27:10 -0800 | [diff] [blame] | 226 | // TODO(austin): Do we need to debounce box_back_beambreak_triggered ? |
Austin Schuh | 9634153 | 2018-03-09 21:17:24 -0800 | [diff] [blame] | 227 | if (claw_closed_) { |
| 228 | if ((filtered_goal == ReadyAboveBoxIndex()) || |
| 229 | (filtered_goal == TallBoxGrabIndex()) || |
| 230 | (filtered_goal == ShortBoxGrabIndex())) { |
| 231 | filtered_goal = NeutralIndex(); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | // TODO(austin): Do we need to debounce box_back_beambreak_triggered ? |
| 236 | switch (grab_state_) { |
| 237 | case GrabState::NORMAL: |
| 238 | if (grab_box && !claw_closed_) { |
| 239 | grab_state_ = GrabState::WAIT_FOR_BOX; |
| 240 | } else { |
| 241 | break; |
| 242 | } |
| 243 | case GrabState::WAIT_FOR_BOX: |
| 244 | if (!grab_box) { |
| 245 | grab_state_ = GrabState::NORMAL; |
| 246 | } else { |
| 247 | if (AtState(ReadyAboveBoxIndex()) && NearEnd()) { |
| 248 | // We are being asked to grab the box, and the claw is near the box. |
| 249 | if (box_back_beambreak_triggered) { |
| 250 | // And we now see the box! Try for a tall box. |
| 251 | grab_state_ = GrabState::TALL_BOX; |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | break; |
| 256 | case GrabState::TALL_BOX: |
| 257 | if (!grab_box) { |
| 258 | grab_state_ = GrabState::NORMAL; |
Austin Schuh | 9634153 | 2018-03-09 21:17:24 -0800 | [diff] [blame] | 259 | } else if (AtState(TallBoxGrabIndex()) && NearEnd()) { |
| 260 | // We are being asked to grab the box, and the claw is near the box. |
| 261 | if (claw_beambreak_triggered) { |
| 262 | grab_state_ = GrabState::CLAW_CLOSE; |
| 263 | // Snap time for the delay here. |
| 264 | claw_close_start_time_ = ::aos::monotonic_clock::now(); |
| 265 | } else { |
| 266 | grab_state_ = GrabState::SHORT_BOX; |
| 267 | } |
| 268 | } |
| 269 | break; |
| 270 | case GrabState::SHORT_BOX: |
| 271 | if (!grab_box) { |
| 272 | grab_state_ = GrabState::NORMAL; |
Austin Schuh | 9634153 | 2018-03-09 21:17:24 -0800 | [diff] [blame] | 273 | } else if (AtState(ShortBoxGrabIndex()) && NearEnd()) { |
| 274 | // We are being asked to grab the box, and the claw is near the box. |
| 275 | if (claw_beambreak_triggered) { |
| 276 | grab_state_ = GrabState::CLAW_CLOSE; |
| 277 | // Snap time for the delay here. |
| 278 | claw_close_start_time_ = ::aos::monotonic_clock::now(); |
| 279 | } else { |
| 280 | grab_state_ = GrabState::WAIT_FOR_BOX; |
| 281 | } |
| 282 | } |
| 283 | break; |
| 284 | case GrabState::CLAW_CLOSE: |
| 285 | if (::aos::monotonic_clock::now() > |
Austin Schuh | b874fd3 | 2018-03-05 00:27:10 -0800 | [diff] [blame] | 286 | claw_close_start_time_ + ::std::chrono::milliseconds(300)) { |
Austin Schuh | 9634153 | 2018-03-09 21:17:24 -0800 | [diff] [blame] | 287 | grab_state_ = GrabState::OPEN_INTAKE; |
| 288 | } |
| 289 | break; |
| 290 | case GrabState::OPEN_INTAKE: |
| 291 | if (intake_clear_of_box) { |
| 292 | grab_state_ = GrabState::NORMAL; |
| 293 | } |
| 294 | break; |
| 295 | } |
| 296 | |
| 297 | // Now, based out our current state, go to the right state. |
| 298 | switch (grab_state_) { |
| 299 | case GrabState::NORMAL: |
| 300 | // Don't let the intake close fully with the claw closed. |
| 301 | // TODO(austin): If we want to transfer the box from the claw to the |
| 302 | // intake, we'll need to change this. |
| 303 | if (claw_closed_) { |
| 304 | max_intake_override_ = -0.5; |
| 305 | } else { |
| 306 | max_intake_override_ = 1000.0; |
| 307 | } |
| 308 | break; |
| 309 | case GrabState::WAIT_FOR_BOX: |
| 310 | filtered_goal = ReadyAboveBoxIndex(); |
| 311 | claw_closed_ = false; |
| 312 | max_intake_override_ = 1000.0; |
| 313 | break; |
| 314 | case GrabState::TALL_BOX: |
| 315 | filtered_goal = TallBoxGrabIndex(); |
| 316 | claw_closed_ = false; |
| 317 | max_intake_override_ = 1000.0; |
| 318 | break; |
| 319 | case GrabState::SHORT_BOX: |
| 320 | filtered_goal = ShortBoxGrabIndex(); |
| 321 | claw_closed_ = false; |
| 322 | max_intake_override_ = 1000.0; |
| 323 | break; |
| 324 | case GrabState::CLAW_CLOSE: |
| 325 | // Don't move. |
| 326 | filtered_goal = current_node_; |
| 327 | claw_closed_ = true; |
| 328 | max_intake_override_ = 1000.0; |
| 329 | break; |
| 330 | case GrabState::OPEN_INTAKE: |
| 331 | // Don't move. |
| 332 | filtered_goal = current_node_; |
| 333 | claw_closed_ = true; |
| 334 | max_intake_override_ = -0.5; |
| 335 | break; |
| 336 | } |
| 337 | |
| 338 | if (state_ == State::RUNNING && unsafe_goal != nullptr) { |
| 339 | if (current_node_ != filtered_goal) { |
| 340 | LOG(INFO, "Goal is different\n"); |
| 341 | if (filtered_goal >= search_graph_.num_vertexes()) { |
| 342 | LOG(ERROR, "goal node out of range ESTOP\n"); |
| 343 | state_ = State::ESTOP; |
| 344 | } else if (follower_.path_distance_to_go() > 1e-3) { |
| 345 | // Still on the old path segment. Can't change yet. |
| 346 | } else { |
| 347 | search_graph_.SetGoal(filtered_goal); |
| 348 | |
| 349 | size_t min_edge = 0; |
| 350 | double min_cost = ::std::numeric_limits<double>::infinity(); |
| 351 | for (const SearchGraph::HalfEdge &edge : |
| 352 | search_graph_.Neighbors(current_node_)) { |
| 353 | const double cost = search_graph_.GetCostToGoal(edge.dest); |
| 354 | if (cost < min_cost) { |
| 355 | min_edge = edge.edge_id; |
| 356 | min_cost = cost; |
| 357 | } |
| 358 | } |
| 359 | // Ok, now we know which edge we are on. Figure out the path and |
| 360 | // trajectory. |
| 361 | const SearchGraph::Edge &next_edge = search_graph_.edges()[min_edge]; |
| 362 | LOG(INFO, "Switching from node %d to %d along edge %d\n", |
| 363 | static_cast<int>(current_node_), static_cast<int>(next_edge.end), |
| 364 | static_cast<int>(min_edge)); |
Austin Schuh | 41c71e4 | 2018-04-04 20:11:20 -0700 | [diff] [blame] | 365 | vmax_ = trajectories_[min_edge].vmax; |
| 366 | follower_.SwitchTrajectory(&trajectories_[min_edge].trajectory); |
Austin Schuh | 9634153 | 2018-03-09 21:17:24 -0800 | [diff] [blame] | 367 | current_node_ = next_edge.end; |
| 368 | } |
| 369 | } |
| 370 | } |
| 371 | |
Austin Schuh | 345a373 | 2018-03-21 20:49:32 -0700 | [diff] [blame] | 372 | const double max_operating_voltage = |
| 373 | close_enough_for_full_power_ |
| 374 | ? kOperatingVoltage() |
| 375 | : (state_ == State::GOTO_PATH ? kGotoPathVMax() : kPathlessVMax()); |
Austin Schuh | 41c71e4 | 2018-04-04 20:11:20 -0700 | [diff] [blame] | 376 | follower_.Update(arm_ekf_.X_hat(), disable, kDt(), vmax_, |
Austin Schuh | 345a373 | 2018-03-21 20:49:32 -0700 | [diff] [blame] | 377 | max_operating_voltage); |
| 378 | LOG(INFO, "Max voltage: %f\n", max_operating_voltage); |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 379 | status->goal_theta0 = follower_.theta(0); |
| 380 | status->goal_theta1 = follower_.theta(1); |
| 381 | status->goal_omega0 = follower_.omega(0); |
| 382 | status->goal_omega1 = follower_.omega(1); |
| 383 | |
| 384 | status->theta0 = arm_ekf_.X_hat(0); |
| 385 | status->theta1 = arm_ekf_.X_hat(2); |
| 386 | status->omega0 = arm_ekf_.X_hat(1); |
| 387 | status->omega1 = arm_ekf_.X_hat(3); |
| 388 | status->voltage_error0 = arm_ekf_.X_hat(4); |
| 389 | status->voltage_error1 = arm_ekf_.X_hat(5); |
| 390 | |
| 391 | if (!disable) { |
| 392 | *proximal_output = ::std::max( |
| 393 | -kOperatingVoltage(), ::std::min(kOperatingVoltage(), follower_.U(0))); |
| 394 | *distal_output = ::std::max( |
| 395 | -kOperatingVoltage(), ::std::min(kOperatingVoltage(), follower_.U(1))); |
Austin Schuh | 17e484e | 2018-03-11 01:11:36 -0800 | [diff] [blame] | 396 | if (state_ != State::PREP_CLIMB) { |
| 397 | *release_arm_brake = true; |
| 398 | } else { |
| 399 | *release_arm_brake = false; |
| 400 | } |
Austin Schuh | 9634153 | 2018-03-09 21:17:24 -0800 | [diff] [blame] | 401 | *claw_closed = claw_closed_; |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | status->proximal_estimator_state = |
| 405 | proximal_zeroing_estimator_.GetEstimatorState(); |
| 406 | status->distal_estimator_state = |
| 407 | distal_zeroing_estimator_.GetEstimatorState(); |
| 408 | |
| 409 | status->path_distance_to_go = follower_.path_distance_to_go(); |
| 410 | status->current_node = current_node_; |
| 411 | |
| 412 | status->zeroed = (proximal_zeroing_estimator_.zeroed() && |
| 413 | distal_zeroing_estimator_.zeroed()); |
| 414 | status->estopped = (state_ == State::ESTOP); |
| 415 | status->state = static_cast<int32_t>(state_); |
Austin Schuh | 9634153 | 2018-03-09 21:17:24 -0800 | [diff] [blame] | 416 | status->grab_state = static_cast<int32_t>(grab_state_); |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 417 | status->failed_solutions = follower_.failed_solutions(); |
| 418 | |
| 419 | arm_ekf_.Predict(follower_.U(), kDt()); |
| 420 | } |
| 421 | |
| 422 | } // namespace arm |
| 423 | } // namespace superstructure |
| 424 | } // namespace control_loops |
| 425 | } // namespace y2018 |