milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 1 | #include "y2023/control_loops/superstructure/arm/arm.h" |
| 2 | |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 3 | #include "y2023/control_loops/superstructure/roll/integral_hybrid_roll_plant.h" |
| 4 | #include "y2023/control_loops/superstructure/roll/integral_roll_plant.h" |
| 5 | |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 6 | namespace y2023 { |
| 7 | namespace control_loops { |
| 8 | namespace superstructure { |
| 9 | namespace arm { |
| 10 | namespace { |
| 11 | |
| 12 | namespace chrono = ::std::chrono; |
| 13 | using ::aos::monotonic_clock; |
| 14 | |
| 15 | constexpr int kMaxBrownoutCount = 4; |
| 16 | |
| 17 | } // namespace |
| 18 | |
Maxwell Henderson | b392b74 | 2023-03-05 07:53:51 -0800 | [diff] [blame^] | 19 | Arm::Arm(std::shared_ptr<const constants::Values> values, |
| 20 | const ArmTrajectories &arm_trajectories) |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 21 | : values_(values), |
| 22 | state_(ArmState::UNINITIALIZED), |
| 23 | proximal_zeroing_estimator_(values_->arm_proximal.zeroing), |
| 24 | distal_zeroing_estimator_(values_->arm_distal.zeroing), |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 25 | roll_joint_zeroing_estimator_(values_->roll_joint.zeroing), |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 26 | proximal_offset_(0.0), |
| 27 | distal_offset_(0.0), |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 28 | roll_joint_offset_(0.0), |
| 29 | alpha_unitizer_((::Eigen::DiagonalMatrix<double, 3>().diagonal() |
Maxwell Henderson | 5c47a46 | 2023-02-25 14:40:44 -0800 | [diff] [blame] | 30 | << (1.0 / constants::Values::kArmAlpha0Max()), |
| 31 | (1.0 / constants::Values::kArmAlpha1Max()), |
| 32 | (1.0 / constants::Values::kArmAlpha2Max())) |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 33 | .finished()), |
| 34 | dynamics_(kArmConstants), |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 35 | close_enough_for_full_power_(false), |
| 36 | brownout_count_(0), |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 37 | roll_joint_loop_(roll::MakeIntegralRollLoop()), |
| 38 | hybrid_roll_joint_loop_(roll::MakeIntegralHybridRollLoop()), |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 39 | arm_ekf_(&dynamics_), |
Maxwell Henderson | b392b74 | 2023-03-05 07:53:51 -0800 | [diff] [blame^] | 40 | search_graph_(GetSearchGraph(arm_trajectories)), |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 41 | // Go to the start of the first trajectory. |
Austin Schuh | 9a11ebd | 2023-02-26 14:16:31 -0800 | [diff] [blame] | 42 | follower_(&dynamics_, &hybrid_roll_joint_loop_, NeutralPoint()), |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 43 | points_(PointList()), |
| 44 | current_node_(0) { |
Maxwell Henderson | b392b74 | 2023-03-05 07:53:51 -0800 | [diff] [blame^] | 45 | // Creating trajectories from fbs |
| 46 | for (const auto *trajectory : *arm_trajectories.trajectories()) { |
| 47 | trajectories_.emplace_back(&dynamics_, &hybrid_roll_joint_loop_.plant(), |
| 48 | *trajectory); |
| 49 | } |
| 50 | |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 51 | int i = 0; |
| 52 | for (const auto &trajectory : trajectories_) { |
| 53 | AOS_LOG(INFO, "trajectory length for edge node %d: %f\n", i, |
| 54 | trajectory.trajectory.path().length()); |
| 55 | ++i; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | void Arm::Reset() { state_ = ArmState::UNINITIALIZED; } |
| 60 | |
milind-u | 3b91b75 | 2023-02-25 15:21:06 -0800 | [diff] [blame] | 61 | namespace { |
milind-u | 3b91b75 | 2023-02-25 15:21:06 -0800 | [diff] [blame] | 62 | // Proximal joint center in xy space |
| 63 | constexpr std::pair<double, double> kJointCenter = {-0.203, 0.787}; |
| 64 | |
| 65 | std::tuple<double, double, int> ArmThetasToXY(double theta_proximal, |
| 66 | double theta_distal) { |
| 67 | double theta_proximal_shifted = M_PI / 2.0 - theta_proximal; |
| 68 | double theta_distal_shifted = M_PI / 2.0 - theta_distal; |
| 69 | |
| 70 | double x = std::cos(theta_proximal_shifted) * kArmConstants.l0 + |
| 71 | std::cos(theta_distal_shifted) * kArmConstants.l1 + |
| 72 | kJointCenter.first; |
| 73 | double y = std::sin(theta_proximal_shifted) * kArmConstants.l0 + |
| 74 | std::sin(theta_distal_shifted) * kArmConstants.l1 + |
| 75 | kJointCenter.second; |
| 76 | |
| 77 | int circular_index = |
| 78 | std::floor((theta_distal_shifted - theta_proximal_shifted) / M_PI); |
| 79 | |
| 80 | return std::make_tuple(x, y, circular_index); |
| 81 | } |
| 82 | |
| 83 | } // namespace |
| 84 | |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 85 | flatbuffers::Offset<superstructure::ArmStatus> Arm::Iterate( |
| 86 | const ::aos::monotonic_clock::time_point /*monotonic_now*/, |
| 87 | const uint32_t *unsafe_goal, const superstructure::ArmPosition *position, |
| 88 | bool trajectory_override, double *proximal_output, double *distal_output, |
Maxwell Henderson | 5938a83 | 2023-02-23 09:33:15 -0800 | [diff] [blame] | 89 | double *roll_joint_output, flatbuffers::FlatBufferBuilder *fbb) { |
| 90 | ::Eigen::Matrix<double, 2, 1> Y; |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 91 | const bool outputs_disabled = |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 92 | ((proximal_output == nullptr) || (distal_output == nullptr) || |
| 93 | (roll_joint_output == nullptr)); |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 94 | if (outputs_disabled) { |
| 95 | ++brownout_count_; |
| 96 | } else { |
| 97 | brownout_count_ = 0; |
| 98 | } |
| 99 | |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 100 | // TODO(milind): should we default to the closest position? |
Austin Schuh | 9a11ebd | 2023-02-26 14:16:31 -0800 | [diff] [blame] | 101 | uint32_t filtered_goal = arm::NeutralIndex(); |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 102 | if (unsafe_goal != nullptr) { |
| 103 | filtered_goal = *unsafe_goal; |
| 104 | } |
| 105 | |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 106 | ::Eigen::Matrix<double, 2, 1> Y_arm; |
| 107 | Y_arm << position->proximal()->encoder() + proximal_offset_, |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 108 | position->distal()->encoder() + distal_offset_; |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 109 | ::Eigen::Matrix<double, 1, 1> Y_roll_joint; |
| 110 | Y_roll_joint << position->roll_joint()->encoder() + roll_joint_offset_; |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 111 | |
| 112 | proximal_zeroing_estimator_.UpdateEstimate(*position->proximal()); |
| 113 | distal_zeroing_estimator_.UpdateEstimate(*position->distal()); |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 114 | roll_joint_zeroing_estimator_.UpdateEstimate(*position->roll_joint()); |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 115 | |
| 116 | if (proximal_output != nullptr) { |
| 117 | *proximal_output = 0.0; |
| 118 | } |
| 119 | if (distal_output != nullptr) { |
| 120 | *distal_output = 0.0; |
| 121 | } |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 122 | if (roll_joint_output != nullptr) { |
| 123 | *roll_joint_output = 0.0; |
| 124 | } |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 125 | |
Maxwell Henderson | 5c47a46 | 2023-02-25 14:40:44 -0800 | [diff] [blame] | 126 | arm_ekf_.Correct(Y_arm, constants::Values::kArmDt()); |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 127 | roll_joint_loop_.Correct(Y_roll_joint); |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 128 | |
| 129 | if (::std::abs(arm_ekf_.X_hat(0) - follower_.theta(0)) <= 0.05 && |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 130 | ::std::abs(arm_ekf_.X_hat(2) - follower_.theta(1)) <= 0.05 && |
| 131 | ::std::abs(roll_joint_loop_.X_hat(0) - follower_.theta(2)) <= 0.05) { |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 132 | close_enough_for_full_power_ = true; |
| 133 | } |
| 134 | if (::std::abs(arm_ekf_.X_hat(0) - follower_.theta(0)) >= 1.10 || |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 135 | ::std::abs(arm_ekf_.X_hat(2) - follower_.theta(1)) >= 1.10 || |
| 136 | ::std::abs(roll_joint_loop_.X_hat(0) - follower_.theta(2)) >= 0.50) { |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 137 | close_enough_for_full_power_ = false; |
| 138 | } |
| 139 | |
| 140 | switch (state_) { |
| 141 | case ArmState::UNINITIALIZED: |
| 142 | // Wait in the uninitialized state until the intake is initialized. |
| 143 | AOS_LOG(DEBUG, "Uninitialized, waiting for intake\n"); |
| 144 | state_ = ArmState::ZEROING; |
| 145 | proximal_zeroing_estimator_.Reset(); |
| 146 | distal_zeroing_estimator_.Reset(); |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 147 | roll_joint_zeroing_estimator_.Reset(); |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 148 | break; |
| 149 | |
| 150 | case ArmState::ZEROING: |
| 151 | // Zero by not moving. |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 152 | if (zeroed()) { |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 153 | state_ = ArmState::DISABLED; |
| 154 | |
| 155 | proximal_offset_ = proximal_zeroing_estimator_.offset(); |
| 156 | distal_offset_ = distal_zeroing_estimator_.offset(); |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 157 | roll_joint_offset_ = roll_joint_zeroing_estimator_.offset(); |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 158 | |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 159 | Y_arm << position->proximal()->encoder() + proximal_offset_, |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 160 | position->distal()->encoder() + distal_offset_; |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 161 | Y_roll_joint << position->roll_joint()->encoder() + roll_joint_offset_; |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 162 | |
| 163 | // TODO(austin): Offset ekf rather than reset it. Since we aren't |
| 164 | // moving at this point, it's pretty safe to do this. |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 165 | ::Eigen::Matrix<double, 4, 1> X_arm; |
| 166 | X_arm << Y_arm(0), 0.0, Y_arm(1), 0.0; |
| 167 | arm_ekf_.Reset(X_arm); |
| 168 | |
| 169 | ::Eigen::Matrix<double, 3, 1> X_roll_joint; |
| 170 | X_roll_joint << Y_roll_joint(0), 0.0, 0.0; |
| 171 | roll_joint_loop_.mutable_X_hat() = X_roll_joint; |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 172 | } else { |
| 173 | break; |
| 174 | } |
| 175 | [[fallthrough]]; |
| 176 | |
| 177 | case ArmState::DISABLED: { |
| 178 | follower_.SwitchTrajectory(nullptr); |
| 179 | close_enough_for_full_power_ = false; |
| 180 | |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 181 | const ::Eigen::Matrix<double, 3, 1> current_theta = |
| 182 | (::Eigen::Matrix<double, 3, 1>() << arm_ekf_.X_hat(0), |
| 183 | arm_ekf_.X_hat(2), roll_joint_loop_.X_hat(0)) |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 184 | .finished(); |
| 185 | uint32_t best_index = 0; |
| 186 | double best_distance = (points_[0] - current_theta).norm(); |
| 187 | uint32_t current_index = 0; |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 188 | for (const ::Eigen::Matrix<double, 3, 1> &point : points_) { |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 189 | const double new_distance = (point - current_theta).norm(); |
| 190 | if (new_distance < best_distance) { |
| 191 | best_distance = new_distance; |
| 192 | best_index = current_index; |
| 193 | } |
| 194 | ++current_index; |
| 195 | } |
| 196 | follower_.set_theta(points_[best_index]); |
| 197 | current_node_ = best_index; |
| 198 | |
| 199 | if (!outputs_disabled) { |
| 200 | state_ = ArmState::GOTO_PATH; |
| 201 | } else { |
| 202 | break; |
| 203 | } |
| 204 | } |
| 205 | [[fallthrough]]; |
| 206 | |
| 207 | case ArmState::GOTO_PATH: |
| 208 | if (outputs_disabled) { |
| 209 | state_ = ArmState::DISABLED; |
| 210 | } else if (trajectory_override) { |
| 211 | follower_.SwitchTrajectory(nullptr); |
| 212 | current_node_ = filtered_goal; |
| 213 | follower_.set_theta(points_[current_node_]); |
| 214 | state_ = ArmState::GOTO_PATH; |
| 215 | } else if (close_enough_for_full_power_) { |
| 216 | state_ = ArmState::RUNNING; |
| 217 | } |
| 218 | break; |
| 219 | |
| 220 | case ArmState::RUNNING: |
| 221 | // ESTOP if we hit the hard limits. |
| 222 | // TODO(austin): Pick some sane limits. |
| 223 | if (proximal_zeroing_estimator_.error() || |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 224 | distal_zeroing_estimator_.error() || |
| 225 | roll_joint_zeroing_estimator_.error()) { |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 226 | AOS_LOG(ERROR, "Zeroing error ESTOP\n"); |
| 227 | state_ = ArmState::ESTOP; |
| 228 | } else if (outputs_disabled && brownout_count_ > kMaxBrownoutCount) { |
| 229 | state_ = ArmState::DISABLED; |
| 230 | } else if (trajectory_override) { |
| 231 | follower_.SwitchTrajectory(nullptr); |
| 232 | current_node_ = filtered_goal; |
| 233 | follower_.set_theta(points_[current_node_]); |
| 234 | state_ = ArmState::GOTO_PATH; |
| 235 | } |
| 236 | break; |
| 237 | |
| 238 | case ArmState::ESTOP: |
| 239 | AOS_LOG(ERROR, "Estop\n"); |
| 240 | break; |
| 241 | } |
| 242 | |
| 243 | const bool disable = outputs_disabled || (state_ != ArmState::RUNNING && |
| 244 | state_ != ArmState::GOTO_PATH); |
| 245 | if (disable) { |
| 246 | close_enough_for_full_power_ = false; |
| 247 | } |
| 248 | |
| 249 | if (state_ == ArmState::RUNNING && unsafe_goal != nullptr) { |
| 250 | if (current_node_ != filtered_goal) { |
| 251 | AOS_LOG(INFO, "Goal is different\n"); |
| 252 | if (filtered_goal >= search_graph_.num_vertexes()) { |
| 253 | AOS_LOG(ERROR, "goal node out of range ESTOP\n"); |
| 254 | state_ = ArmState::ESTOP; |
| 255 | } else if (follower_.path_distance_to_go() > 1e-3) { |
| 256 | // Still on the old path segment. Can't change yet. |
| 257 | } else { |
| 258 | search_graph_.SetGoal(filtered_goal); |
| 259 | |
| 260 | size_t min_edge = 0; |
| 261 | double min_cost = ::std::numeric_limits<double>::infinity(); |
| 262 | for (const SearchGraph::HalfEdge &edge : |
| 263 | search_graph_.Neighbors(current_node_)) { |
| 264 | const double cost = search_graph_.GetCostToGoal(edge.dest); |
| 265 | if (cost < min_cost) { |
| 266 | min_edge = edge.edge_id; |
| 267 | min_cost = cost; |
| 268 | } |
| 269 | } |
| 270 | // Ok, now we know which edge we are on. Figure out the path and |
| 271 | // trajectory. |
| 272 | const SearchGraph::Edge &next_edge = search_graph_.edges()[min_edge]; |
| 273 | AOS_LOG(INFO, "Switching from node %d to %d along edge %d\n", |
| 274 | static_cast<int>(current_node_), |
| 275 | static_cast<int>(next_edge.end), static_cast<int>(min_edge)); |
| 276 | vmax_ = trajectories_[min_edge].vmax; |
| 277 | follower_.SwitchTrajectory(&trajectories_[min_edge].trajectory); |
| 278 | current_node_ = next_edge.end; |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | const double max_operating_voltage = |
| 284 | close_enough_for_full_power_ |
Maxwell Henderson | 5c47a46 | 2023-02-25 14:40:44 -0800 | [diff] [blame] | 285 | ? constants::Values::kArmOperatingVoltage() |
| 286 | : (state_ == ArmState::GOTO_PATH |
| 287 | ? constants::Values::kArmGotoPathVMax() |
| 288 | : constants::Values::kArmPathlessVMax()); |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 289 | ::Eigen::Matrix<double, 9, 1> X_hat; |
| 290 | X_hat.block<6, 1>(0, 0) = arm_ekf_.X_hat(); |
| 291 | X_hat.block<3, 1>(6, 0) = roll_joint_loop_.X_hat(); |
| 292 | |
Maxwell Henderson | 5c47a46 | 2023-02-25 14:40:44 -0800 | [diff] [blame] | 293 | follower_.Update(X_hat, disable, constants::Values::kArmDt(), vmax_, |
| 294 | max_operating_voltage); |
| 295 | AOS_LOG(INFO, "Max voltage: %f\n", max_operating_voltage); |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 296 | |
Maxwell Henderson | 5c47a46 | 2023-02-25 14:40:44 -0800 | [diff] [blame] | 297 | arm_ekf_.Predict(follower_.U().head<2>(), constants::Values::kArmDt()); |
| 298 | roll_joint_loop_.UpdateObserver(follower_.U().tail<1>(), |
| 299 | constants::Values::kArmDtDuration()); |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 300 | |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 301 | flatbuffers::Offset<frc971::PotAndAbsoluteEncoderEstimatorState> |
| 302 | proximal_estimator_state_offset = |
| 303 | proximal_zeroing_estimator_.GetEstimatorState(fbb); |
| 304 | flatbuffers::Offset<frc971::PotAndAbsoluteEncoderEstimatorState> |
| 305 | distal_estimator_state_offset = |
| 306 | distal_zeroing_estimator_.GetEstimatorState(fbb); |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 307 | flatbuffers::Offset<frc971::PotAndAbsoluteEncoderEstimatorState> |
| 308 | roll_joint_estimator_state_offset = |
| 309 | roll_joint_zeroing_estimator_.GetEstimatorState(fbb); |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 310 | |
milind-u | 3b91b75 | 2023-02-25 15:21:06 -0800 | [diff] [blame] | 311 | const auto [arm_x, arm_y, arm_circular_index] = |
| 312 | ArmThetasToXY(arm_ekf_.X_hat(0), arm_ekf_.X_hat(2)); |
| 313 | |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 314 | superstructure::ArmStatus::Builder status_builder(*fbb); |
| 315 | status_builder.add_proximal_estimator_state(proximal_estimator_state_offset); |
| 316 | status_builder.add_distal_estimator_state(distal_estimator_state_offset); |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 317 | status_builder.add_roll_joint_estimator_state( |
| 318 | roll_joint_estimator_state_offset); |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 319 | |
| 320 | status_builder.add_goal_theta0(follower_.theta(0)); |
| 321 | status_builder.add_goal_theta1(follower_.theta(1)); |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 322 | status_builder.add_goal_theta2(follower_.theta(2)); |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 323 | status_builder.add_goal_omega0(follower_.omega(0)); |
| 324 | status_builder.add_goal_omega1(follower_.omega(1)); |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 325 | status_builder.add_goal_omega2(follower_.omega(2)); |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 326 | |
| 327 | status_builder.add_theta0(arm_ekf_.X_hat(0)); |
| 328 | status_builder.add_theta1(arm_ekf_.X_hat(2)); |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 329 | status_builder.add_theta2(roll_joint_loop_.X_hat(0)); |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 330 | status_builder.add_omega0(arm_ekf_.X_hat(1)); |
| 331 | status_builder.add_omega1(arm_ekf_.X_hat(3)); |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 332 | status_builder.add_omega2(roll_joint_loop_.X_hat(1)); |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 333 | status_builder.add_voltage_error0(arm_ekf_.X_hat(4)); |
| 334 | status_builder.add_voltage_error1(arm_ekf_.X_hat(5)); |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 335 | status_builder.add_voltage_error2(roll_joint_loop_.X_hat(2)); |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 336 | |
milind-u | 3b91b75 | 2023-02-25 15:21:06 -0800 | [diff] [blame] | 337 | status_builder.add_arm_x(arm_x); |
| 338 | status_builder.add_arm_y(arm_y); |
| 339 | status_builder.add_arm_circular_index(arm_circular_index); |
| 340 | |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 341 | if (!disable) { |
| 342 | *proximal_output = ::std::max( |
Maxwell Henderson | 5c47a46 | 2023-02-25 14:40:44 -0800 | [diff] [blame] | 343 | -constants::Values::kArmOperatingVoltage(), |
| 344 | ::std::min(constants::Values::kArmOperatingVoltage(), follower_.U(0))); |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 345 | *distal_output = ::std::max( |
Maxwell Henderson | 5c47a46 | 2023-02-25 14:40:44 -0800 | [diff] [blame] | 346 | -constants::Values::kArmOperatingVoltage(), |
| 347 | ::std::min(constants::Values::kArmOperatingVoltage(), follower_.U(1))); |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 348 | *roll_joint_output = ::std::max( |
Maxwell Henderson | 5c47a46 | 2023-02-25 14:40:44 -0800 | [diff] [blame] | 349 | -constants::Values::kArmOperatingVoltage(), |
| 350 | ::std::min(constants::Values::kArmOperatingVoltage(), follower_.U(2))); |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | status_builder.add_path_distance_to_go(follower_.path_distance_to_go()); |
| 354 | status_builder.add_current_node(current_node_); |
| 355 | |
| 356 | status_builder.add_zeroed(zeroed()); |
| 357 | status_builder.add_estopped(estopped()); |
| 358 | status_builder.add_state(state_); |
| 359 | status_builder.add_failed_solutions(follower_.failed_solutions()); |
| 360 | |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 361 | return status_builder.Finish(); |
| 362 | } |
| 363 | |
| 364 | } // namespace arm |
| 365 | } // namespace superstructure |
| 366 | } // namespace control_loops |
| 367 | } // namespace y2023 |