Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 1 | #include "y2024/control_loops/superstructure/superstructure.h" |
| 2 | |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 3 | #include <chrono> |
| 4 | |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 5 | #include "aos/events/event_loop.h" |
| 6 | #include "aos/flatbuffer_merge.h" |
| 7 | #include "aos/network/team_number.h" |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 8 | #include "aos/time/time.h" |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 9 | #include "frc971/shooter_interpolation/interpolation.h" |
| 10 | #include "frc971/zeroing/wrap.h" |
| 11 | |
| 12 | DEFINE_bool(ignore_distance, false, |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 13 | "If true, ignore distance when shooting and obey joystick_reader"); |
| 14 | |
| 15 | // The threshold used when decided if the extend is close enough to a goal to |
| 16 | // continue. |
| 17 | constexpr double kExtendThreshold = 0.01; |
| 18 | |
| 19 | constexpr double kTurretLoadingThreshold = 0.01; |
| 20 | constexpr double kAltitudeLoadingThreshold = 0.01; |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 21 | |
Maxwell Henderson | f0d2262 | 2024-02-26 21:02:11 -0800 | [diff] [blame] | 22 | constexpr std::chrono::milliseconds kExtraIntakingTime = |
| 23 | std::chrono::milliseconds(500); |
| 24 | |
Filip Kujawa | 77e3d8a | 2024-03-02 11:34:56 -0800 | [diff] [blame] | 25 | // Exit catapult loading state after this much time if we never |
| 26 | // trigger any beambreaks. |
| 27 | constexpr std::chrono::milliseconds kMaxCatapultLoadingTime = |
| 28 | std::chrono::milliseconds(3000); |
| 29 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 30 | namespace y2024::control_loops::superstructure { |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 31 | |
| 32 | using ::aos::monotonic_clock; |
| 33 | |
| 34 | using frc971::control_loops::AbsoluteEncoderProfiledJointStatus; |
| 35 | using frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus; |
| 36 | using frc971::control_loops::RelativeEncoderProfiledJointStatus; |
| 37 | |
| 38 | Superstructure::Superstructure(::aos::EventLoop *event_loop, |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 39 | const ::std::string &name) |
| 40 | : frc971::controls::ControlLoop<Goal, Position, Status, Output>(event_loop, |
| 41 | name), |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 42 | constants_fetcher_(event_loop), |
Niko Sohmers | afc51fe | 2024-01-29 17:48:35 -0800 | [diff] [blame] | 43 | robot_constants_(CHECK_NOTNULL(&constants_fetcher_.constants())), |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 44 | drivetrain_status_fetcher_( |
| 45 | event_loop->MakeFetcher<frc971::control_loops::drivetrain::Status>( |
| 46 | "/drivetrain")), |
| 47 | joystick_state_fetcher_( |
Niko Sohmers | afc51fe | 2024-01-29 17:48:35 -0800 | [diff] [blame] | 48 | event_loop->MakeFetcher<aos::JoystickState>("/aos")), |
Niko Sohmers | 74b0ad5 | 2024-02-03 18:00:31 -0800 | [diff] [blame] | 49 | intake_pivot_(robot_constants_->common()->intake_pivot(), |
| 50 | robot_constants_->robot()->intake_constants()), |
Filip Kujawa | 6d71763 | 2024-02-01 11:40:55 -0800 | [diff] [blame] | 51 | climber_( |
| 52 | robot_constants_->common()->climber(), |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 53 | robot_constants_->robot()->climber_constants()->zeroing_constants()), |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 54 | shooter_(event_loop, robot_constants_), |
| 55 | extend_( |
| 56 | robot_constants_->common()->extend(), |
| 57 | robot_constants_->robot()->extend_constants()->zeroing_constants()) { |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 58 | event_loop->SetRuntimeRealtimePriority(30); |
| 59 | } |
| 60 | |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 61 | bool PositionNear(double position, double goal, double threshold) { |
| 62 | return std::abs(position - goal) < threshold; |
| 63 | } |
| 64 | |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 65 | void Superstructure::RunIteration(const Goal *unsafe_goal, |
| 66 | const Position *position, |
| 67 | aos::Sender<Output>::Builder *output, |
| 68 | aos::Sender<Status>::Builder *status) { |
| 69 | const monotonic_clock::time_point timestamp = |
| 70 | event_loop()->context().monotonic_event_time; |
| 71 | |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 72 | if (WasReset()) { |
| 73 | AOS_LOG(ERROR, "WPILib reset, restarting\n"); |
Niko Sohmers | afc51fe | 2024-01-29 17:48:35 -0800 | [diff] [blame] | 74 | intake_pivot_.Reset(); |
Filip Kujawa | 6d71763 | 2024-02-01 11:40:55 -0800 | [diff] [blame] | 75 | climber_.Reset(); |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 76 | shooter_.Reset(); |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 77 | extend_.Reset(); |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | OutputT output_struct; |
Niko Sohmers | afc51fe | 2024-01-29 17:48:35 -0800 | [diff] [blame] | 81 | |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 82 | // Handle Climber Goal separately from main superstructure state machine |
Filip Kujawa | 6d71763 | 2024-02-01 11:40:55 -0800 | [diff] [blame] | 83 | double climber_position = |
| 84 | robot_constants_->common()->climber_set_points()->retract(); |
| 85 | |
| 86 | if (unsafe_goal != nullptr) { |
| 87 | switch (unsafe_goal->climber_goal()) { |
| 88 | case ClimberGoal::FULL_EXTEND: |
| 89 | climber_position = |
| 90 | robot_constants_->common()->climber_set_points()->full_extend(); |
| 91 | break; |
Filip Kujawa | 6d71763 | 2024-02-01 11:40:55 -0800 | [diff] [blame] | 92 | case ClimberGoal::RETRACT: |
| 93 | climber_position = |
| 94 | robot_constants_->common()->climber_set_points()->retract(); |
| 95 | break; |
Maxwell Henderson | 7db2978 | 2024-02-24 20:10:26 -0800 | [diff] [blame] | 96 | case ClimberGoal::STOWED: |
| 97 | climber_position = |
| 98 | robot_constants_->common()->climber_set_points()->stowed(); |
Filip Kujawa | 6d71763 | 2024-02-01 11:40:55 -0800 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 102 | // If we started off preloaded, skip to the ready state. |
| 103 | if (unsafe_goal != nullptr && unsafe_goal->shooter_goal() && |
| 104 | unsafe_goal->shooter_goal()->preloaded()) { |
| 105 | if (state_ != SuperstructureState::READY && |
| 106 | state_ != SuperstructureState::FIRING) { |
| 107 | state_ = SuperstructureState::READY; |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 108 | requested_note_goal_ = NoteGoal::CATAPULT; |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
| 112 | // Handle the intake pivot goal separately from the main superstructure state |
| 113 | IntakeRollerStatus intake_roller_state = IntakeRollerStatus::NONE; |
| 114 | double intake_pivot_position = |
| 115 | robot_constants_->common()->intake_pivot_set_points()->retracted(); |
| 116 | |
| 117 | if (unsafe_goal != nullptr) { |
| 118 | switch (unsafe_goal->intake_goal()) { |
| 119 | case IntakeGoal::INTAKE: |
| 120 | intake_pivot_position = |
| 121 | robot_constants_->common()->intake_pivot_set_points()->extended(); |
Maxwell Henderson | f0d2262 | 2024-02-26 21:02:11 -0800 | [diff] [blame] | 122 | intake_end_time_ = timestamp; |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 123 | break; |
| 124 | case IntakeGoal::SPIT: |
| 125 | intake_pivot_position = |
| 126 | robot_constants_->common()->intake_pivot_set_points()->retracted(); |
| 127 | break; |
| 128 | case IntakeGoal::NONE: |
| 129 | intake_pivot_position = |
| 130 | robot_constants_->common()->intake_pivot_set_points()->retracted(); |
| 131 | break; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | ExtendRollerStatus extend_roller_status = ExtendRollerStatus::IDLE; |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 136 | ExtendStatus extend_goal_location = ExtendStatus::RETRACTED; |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 137 | |
| 138 | // True if the extend is moving towards a goal |
| 139 | bool extend_moving = false; |
| 140 | |
| 141 | TransferRollerStatus transfer_roller_status = TransferRollerStatus::NONE; |
| 142 | |
| 143 | const ExtendSetPoints *extend_set_points = |
| 144 | robot_constants_->common()->extend_set_points(); |
| 145 | |
| 146 | // Checks if the extend is close enough to the retracted position to be |
| 147 | // considered ready to accept note from the transfer rollers. |
Niko Sohmers | dd971dc | 2024-02-25 11:40:47 -0800 | [diff] [blame] | 148 | const bool extend_at_retracted = PositionNear( |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 149 | extend_.position(), extend_set_points->retracted(), kExtendThreshold); |
| 150 | |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 151 | // Check if the turret is at the position to accept the note from extend |
| 152 | const bool turret_ready_for_load = |
| 153 | PositionNear(shooter_.turret().estimated_position(), |
| 154 | robot_constants_->common()->turret_loading_position(), |
| 155 | kTurretLoadingThreshold); |
| 156 | |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 157 | // Check if the altitude is at the position to accept the note from |
| 158 | // extend |
| 159 | const bool altitude_ready_for_load = |
| 160 | PositionNear(shooter_.altitude().estimated_position(), |
| 161 | robot_constants_->common()->altitude_loading_position(), |
| 162 | kAltitudeLoadingThreshold); |
| 163 | |
| 164 | // Check if the extend is at the position to load the catapult |
| 165 | const bool extend_ready_for_catapult_transfer = PositionNear( |
| 166 | extend_.position(), extend_set_points->catapult(), kExtendThreshold); |
| 167 | |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 168 | // Only update the reuested note goal to the first goal that is requested by |
| 169 | // the manipulator |
| 170 | if (unsafe_goal != nullptr && unsafe_goal->note_goal() != NoteGoal::NONE && |
| 171 | requested_note_goal_ == NoteGoal::NONE) { |
| 172 | requested_note_goal_ = unsafe_goal->note_goal(); |
| 173 | } |
| 174 | |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 175 | // Superstructure state machine: |
| 176 | // 1. IDLE. The intake is retracted and there is no note in the robot. |
| 177 | // Wait for a intake goal to switch state to INTAKING if the extend is ready |
| 178 | // 2. INTAKING. Intake the note and transfer it towards the extend. |
| 179 | // Give intake, transfer, and extend rollers positive voltage to intake and |
| 180 | // transfer. Switch to LOADED when the extend beambreak is triggered. |
| 181 | // 3. LOADED. The note is in the extend and the extend is retracted. |
| 182 | // Wait for a note goal to switch state to MOVING. |
| 183 | // For AMP/TRAP goals, check that the turret is in a position to avoid |
| 184 | // collision. |
| 185 | // 4. MOVING. The extend is moving towards a goal (AMP, TRAP, or CATAPULT). |
| 186 | // For CATAPULT goals, wait for the turret and altitude to be in a position to |
| 187 | // accept the note from the extend. |
| 188 | // Wait for the extend to reach the goal and switch state to READY if |
| 189 | // AMP or TRAP, or to LOADING_CATAPULT if CATAPULT. |
| 190 | // 5. LOADING_CATAPULT. The extend is at the position to load the catapult. |
| 191 | // Activate the extend roller to transfer the note to the catapult. |
| 192 | // Switch state to READY when the catapult beambreak is triggered. |
| 193 | // 6. READY. Ready for fire command. The note is either loaded in the catapult |
| 194 | // or in the extend and at the AMP or TRAP position. Wait for a fire command. |
| 195 | // 7. FIRING. The note is being fired, either from the extend or the catapult. |
| 196 | // Switch state back to IDLE when the note is fired. |
| 197 | |
| 198 | switch (state_) { |
| 199 | case SuperstructureState::IDLE: |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 200 | requested_note_goal_ = NoteGoal::NONE; |
| 201 | |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 202 | if (unsafe_goal != nullptr && |
| 203 | unsafe_goal->intake_goal() == IntakeGoal::INTAKE && |
Niko Sohmers | dd971dc | 2024-02-25 11:40:47 -0800 | [diff] [blame] | 204 | extend_at_retracted) { |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 205 | state_ = SuperstructureState::INTAKING; |
| 206 | } |
Maxwell Henderson | 4567e28 | 2024-02-25 15:38:15 -0800 | [diff] [blame] | 207 | |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 208 | extend_goal_location = ExtendStatus::RETRACTED; |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 209 | catapult_requested_ = false; |
| 210 | break; |
| 211 | case SuperstructureState::INTAKING: |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 212 | // Switch to LOADED state when the extend beambreak is triggered |
| 213 | // meaning the note is loaded in the extend |
| 214 | if (position->extend_beambreak()) { |
| 215 | state_ = SuperstructureState::LOADED; |
| 216 | } |
| 217 | intake_roller_state = IntakeRollerStatus::INTAKING; |
| 218 | transfer_roller_status = TransferRollerStatus::TRANSFERING_IN; |
| 219 | extend_roller_status = ExtendRollerStatus::TRANSFERING_TO_EXTEND; |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 220 | extend_goal_location = ExtendStatus::RETRACTED; |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 221 | |
| 222 | if (!catapult_requested_ && unsafe_goal != nullptr && |
| 223 | unsafe_goal->note_goal() == NoteGoal::CATAPULT) { |
| 224 | catapult_requested_ = true; |
| 225 | } |
| 226 | |
Maxwell Henderson | f0d2262 | 2024-02-26 21:02:11 -0800 | [diff] [blame] | 227 | // If we are no longer requesting INTAKE or we are no longer requesting |
| 228 | // an INTAKE goal, wait 0.5 seconds then go back to IDLE. |
| 229 | if (!(unsafe_goal != nullptr && |
| 230 | unsafe_goal->intake_goal() == IntakeGoal::INTAKE) && |
| 231 | timestamp > intake_end_time_ + kExtraIntakingTime) { |
| 232 | state_ = SuperstructureState::IDLE; |
| 233 | } |
| 234 | |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 235 | break; |
| 236 | case SuperstructureState::LOADED: |
Maxwell Henderson | 4567e28 | 2024-02-25 15:38:15 -0800 | [diff] [blame] | 237 | if (!position->extend_beambreak() && !position->catapult_beambreak()) { |
| 238 | state_ = SuperstructureState::IDLE; |
| 239 | } |
| 240 | |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 241 | switch (requested_note_goal_) { |
| 242 | case NoteGoal::NONE: |
| 243 | break; |
| 244 | case NoteGoal::CATAPULT: |
| 245 | state_ = SuperstructureState::MOVING; |
| 246 | transfer_roller_status = TransferRollerStatus::TRANSFERING_IN; |
| 247 | break; |
| 248 | case NoteGoal::TRAP: |
| 249 | [[fallthrough]]; |
| 250 | case NoteGoal::AMP: |
James Kuszmaul | 6cae7d7 | 2024-03-01 21:29:56 -0800 | [diff] [blame] | 251 | transfer_roller_status = TransferRollerStatus::EXTEND_MOVING; |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 252 | state_ = SuperstructureState::MOVING; |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 253 | break; |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 254 | } |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 255 | extend_goal_location = ExtendStatus::RETRACTED; |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 256 | break; |
| 257 | case SuperstructureState::MOVING: |
James Kuszmaul | 6cae7d7 | 2024-03-01 21:29:56 -0800 | [diff] [blame] | 258 | transfer_roller_status = TransferRollerStatus::EXTEND_MOVING; |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 259 | switch (requested_note_goal_) { |
| 260 | case NoteGoal::NONE: |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 261 | extend_goal_location = ExtendStatus::RETRACTED; |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 262 | if (extend_at_retracted) { |
| 263 | state_ = SuperstructureState::LOADED; |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 264 | } |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 265 | break; |
| 266 | case NoteGoal::CATAPULT: |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 267 | extend_goal_location = ExtendStatus::CATAPULT; |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 268 | if (extend_ready_for_catapult_transfer && turret_ready_for_load && |
| 269 | altitude_ready_for_load) { |
Filip Kujawa | 77e3d8a | 2024-03-02 11:34:56 -0800 | [diff] [blame] | 270 | loading_catapult_start_time_ = timestamp; |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 271 | state_ = SuperstructureState::LOADING_CATAPULT; |
| 272 | } |
| 273 | break; |
| 274 | case NoteGoal::TRAP: |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 275 | extend_goal_location = ExtendStatus::TRAP; |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 276 | // Check if the extend is at the TRAP position and if it is |
| 277 | // switch to READY state |
| 278 | if (PositionNear(extend_.position(), extend_set_points->trap(), |
| 279 | kExtendThreshold)) { |
| 280 | state_ = SuperstructureState::READY; |
| 281 | } |
| 282 | break; |
| 283 | case NoteGoal::AMP: |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 284 | extend_goal_location = ExtendStatus::AMP; |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 285 | // Check if the extend is at the AMP position and if it is |
| 286 | // switch to READY state |
| 287 | if (PositionNear(extend_.position(), extend_set_points->amp(), |
| 288 | kExtendThreshold)) { |
| 289 | state_ = SuperstructureState::READY; |
| 290 | } |
| 291 | break; |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | extend_moving = true; |
| 295 | break; |
| 296 | case SuperstructureState::LOADING_CATAPULT: |
| 297 | extend_moving = false; |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 298 | extend_goal_location = ExtendStatus::CATAPULT; |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 299 | extend_roller_status = ExtendRollerStatus::TRANSFERING_TO_CATAPULT; |
| 300 | |
Filip Kujawa | 77e3d8a | 2024-03-02 11:34:56 -0800 | [diff] [blame] | 301 | // If we lost the game piece, reset state to idle. |
| 302 | if (((timestamp - loading_catapult_start_time_) > |
| 303 | kMaxCatapultLoadingTime) && |
| 304 | !position->catapult_beambreak() && !position->extend_beambreak()) { |
| 305 | state_ = SuperstructureState::IDLE; |
| 306 | } |
| 307 | |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 308 | // Switch to READY state when the catapult beambreak is triggered |
| 309 | if (position->catapult_beambreak()) { |
| 310 | state_ = SuperstructureState::READY; |
| 311 | } |
| 312 | break; |
| 313 | case SuperstructureState::READY: |
| 314 | extend_moving = false; |
| 315 | |
| 316 | // Switch to FIRING state when the fire button is pressed |
| 317 | if (unsafe_goal != nullptr && unsafe_goal->fire()) { |
| 318 | state_ = SuperstructureState::FIRING; |
| 319 | } |
| 320 | |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 321 | switch (requested_note_goal_) { |
| 322 | case NoteGoal::NONE: |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 323 | extend_goal_location = ExtendStatus::RETRACTED; |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 324 | extend_moving = true; |
| 325 | state_ = SuperstructureState::MOVING; |
| 326 | break; |
| 327 | case NoteGoal::CATAPULT: |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 328 | extend_goal_location = ExtendStatus::CATAPULT; |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 329 | break; |
| 330 | case NoteGoal::TRAP: |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 331 | extend_goal_location = ExtendStatus::TRAP; |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 332 | break; |
| 333 | case NoteGoal::AMP: |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 334 | extend_goal_location = ExtendStatus::AMP; |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 335 | break; |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 336 | } |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 337 | break; |
| 338 | case SuperstructureState::FIRING: |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 339 | switch (requested_note_goal_) { |
| 340 | case NoteGoal::NONE: |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 341 | |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 342 | break; |
| 343 | case NoteGoal::CATAPULT: |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 344 | extend_goal_location = ExtendStatus::CATAPULT; |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 345 | // Reset the state to IDLE when the game piece is fired from the |
| 346 | // catapult. We consider the game piece to be fired from the catapult |
| 347 | // when the catapultbeambreak is no longer triggered. |
| 348 | if (!position->catapult_beambreak()) { |
| 349 | state_ = SuperstructureState::IDLE; |
| 350 | } |
| 351 | break; |
| 352 | case NoteGoal::TRAP: |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 353 | extend_roller_status = ExtendRollerStatus::SCORING_IN_TRAP; |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 354 | extend_goal_location = ExtendStatus::TRAP; |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 355 | if (!position->extend_beambreak() && unsafe_goal != nullptr && |
| 356 | !unsafe_goal->fire()) { |
| 357 | state_ = SuperstructureState::IDLE; |
| 358 | } |
| 359 | break; |
| 360 | case NoteGoal::AMP: |
| 361 | extend_roller_status = ExtendRollerStatus::SCORING_IN_AMP; |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 362 | extend_goal_location = ExtendStatus::AMP; |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 363 | if (!position->extend_beambreak() && unsafe_goal != nullptr && |
| 364 | !unsafe_goal->fire()) { |
| 365 | state_ = SuperstructureState::IDLE; |
| 366 | } |
| 367 | break; |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 368 | } |
| 369 | break; |
| 370 | } |
| 371 | |
| 372 | if (unsafe_goal != nullptr && |
| 373 | unsafe_goal->intake_goal() == IntakeGoal::SPIT) { |
| 374 | intake_roller_state = IntakeRollerStatus::SPITTING; |
| 375 | transfer_roller_status = TransferRollerStatus::TRANSFERING_OUT; |
| 376 | } |
| 377 | |
| 378 | // Update Intake Roller voltage based on status from state machine. |
| 379 | switch (intake_roller_state) { |
| 380 | case IntakeRollerStatus::NONE: |
| 381 | output_struct.intake_roller_voltage = 0.0; |
| 382 | break; |
| 383 | case IntakeRollerStatus::SPITTING: |
| 384 | output_struct.intake_roller_voltage = |
| 385 | robot_constants_->common()->intake_roller_voltages()->spitting(); |
| 386 | break; |
| 387 | case IntakeRollerStatus::INTAKING: |
| 388 | output_struct.intake_roller_voltage = |
| 389 | robot_constants_->common()->intake_roller_voltages()->intaking(); |
| 390 | break; |
| 391 | } |
| 392 | |
| 393 | // Update Transfer Roller voltage based on status from state machine. |
| 394 | switch (transfer_roller_status) { |
| 395 | case TransferRollerStatus::NONE: |
| 396 | output_struct.transfer_roller_voltage = 0.0; |
| 397 | break; |
| 398 | case TransferRollerStatus::TRANSFERING_IN: |
| 399 | output_struct.transfer_roller_voltage = |
| 400 | robot_constants_->common()->transfer_roller_voltages()->transfer_in(); |
| 401 | break; |
| 402 | case TransferRollerStatus::TRANSFERING_OUT: |
| 403 | output_struct.transfer_roller_voltage = robot_constants_->common() |
| 404 | ->transfer_roller_voltages() |
| 405 | ->transfer_out(); |
| 406 | break; |
James Kuszmaul | 6cae7d7 | 2024-03-01 21:29:56 -0800 | [diff] [blame] | 407 | case TransferRollerStatus::EXTEND_MOVING: |
| 408 | output_struct.transfer_roller_voltage = robot_constants_->common() |
| 409 | ->transfer_roller_voltages() |
| 410 | ->extend_moving(); |
| 411 | break; |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | // Update Extend Roller voltage based on status from state machine. |
| 415 | const ExtendRollerVoltages *extend_roller_voltages = |
| 416 | robot_constants_->common()->extend_roller_voltages(); |
| 417 | switch (extend_roller_status) { |
| 418 | case ExtendRollerStatus::IDLE: |
| 419 | // No voltage applied when idle |
| 420 | output_struct.extend_roller_voltage = 0.0; |
| 421 | break; |
| 422 | case ExtendRollerStatus::TRANSFERING_TO_EXTEND: |
| 423 | output_struct.extend_roller_voltage = extend_roller_voltages->scoring(); |
| 424 | break; |
| 425 | case ExtendRollerStatus::SCORING_IN_AMP: |
| 426 | [[fallthrough]]; |
| 427 | case ExtendRollerStatus::SCORING_IN_TRAP: |
| 428 | // Apply scoring voltage during scoring in amp or trap |
| 429 | output_struct.extend_roller_voltage = extend_roller_voltages->scoring(); |
| 430 | break; |
| 431 | case ExtendRollerStatus::TRANSFERING_TO_CATAPULT: |
| 432 | // Apply scoring voltage during transferring to catapult |
| 433 | output_struct.extend_roller_voltage = extend_roller_voltages->scoring(); |
| 434 | break; |
| 435 | } |
| 436 | |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 437 | double extend_goal_position = 0.0; |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 438 | |
James Kuszmaul | 0281e15 | 2024-02-26 22:26:16 -0800 | [diff] [blame] | 439 | if (unsafe_goal != nullptr && unsafe_goal->note_goal() == NoteGoal::TRAP) { |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 440 | extend_goal_location = ExtendStatus::TRAP; |
James Kuszmaul | 0281e15 | 2024-02-26 22:26:16 -0800 | [diff] [blame] | 441 | } |
| 442 | |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 443 | // Set the extend position based on the state machine output |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 444 | switch (extend_goal_location) { |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 445 | case ExtendStatus::RETRACTED: |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 446 | extend_goal_position = extend_set_points->retracted(); |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 447 | break; |
| 448 | case ExtendStatus::AMP: |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 449 | extend_goal_position = extend_set_points->amp(); |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 450 | break; |
| 451 | case ExtendStatus::TRAP: |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 452 | extend_goal_position = extend_set_points->trap(); |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 453 | break; |
| 454 | case ExtendStatus::CATAPULT: |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 455 | extend_goal_position = extend_set_points->catapult(); |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 456 | break; |
| 457 | case ExtendStatus::MOVING: |
| 458 | // Should never happen |
| 459 | break; |
| 460 | } |
| 461 | |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 462 | NoteStatus uncompleted_note_goal_status = NoteStatus::NONE; |
| 463 | |
| 464 | switch (requested_note_goal_) { |
| 465 | case NoteGoal::NONE: |
| 466 | uncompleted_note_goal_status = NoteStatus::NONE; |
| 467 | break; |
| 468 | case NoteGoal::CATAPULT: |
| 469 | uncompleted_note_goal_status = NoteStatus::CATAPULT; |
| 470 | break; |
| 471 | case NoteGoal::AMP: |
| 472 | uncompleted_note_goal_status = NoteStatus::AMP; |
| 473 | break; |
| 474 | case NoteGoal::TRAP: |
| 475 | uncompleted_note_goal_status = NoteStatus::TRAP; |
| 476 | break; |
| 477 | } |
| 478 | |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 479 | // Set the extend status based on the state machine output |
| 480 | // If the extend is moving, the status is MOVING, otherwise it is the same |
| 481 | // as extend_status |
| 482 | ExtendStatus extend_status = |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 483 | (extend_moving ? ExtendStatus::MOVING : extend_goal_location); |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 484 | |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 485 | if (joystick_state_fetcher_.Fetch() && |
| 486 | joystick_state_fetcher_->has_alliance()) { |
| 487 | alliance_ = joystick_state_fetcher_->alliance(); |
| 488 | } |
Niko Sohmers | afc51fe | 2024-01-29 17:48:35 -0800 | [diff] [blame] | 489 | |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 490 | drivetrain_status_fetcher_.Fetch(); |
| 491 | |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 492 | const bool collided = collision_avoidance_.IsCollided({ |
| 493 | .intake_pivot_position = intake_pivot_.estimated_position(), |
| 494 | .turret_position = shooter_.turret().estimated_position(), |
| 495 | .extend_position = extend_.estimated_position(), |
| 496 | }); |
Niko Sohmers | afc51fe | 2024-01-29 17:48:35 -0800 | [diff] [blame] | 497 | |
Filip Kujawa | 6d71763 | 2024-02-01 11:40:55 -0800 | [diff] [blame] | 498 | aos::FlatbufferFixedAllocatorArray< |
| 499 | frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal, 512> |
| 500 | climber_goal_buffer; |
| 501 | |
| 502 | climber_goal_buffer.Finish( |
| 503 | frc971::control_loops::CreateStaticZeroingSingleDOFProfiledSubsystemGoal( |
| 504 | *climber_goal_buffer.fbb(), climber_position)); |
| 505 | |
| 506 | const frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal |
| 507 | *climber_goal = &climber_goal_buffer.message(); |
| 508 | |
| 509 | const flatbuffers::Offset<PotAndAbsoluteEncoderProfiledJointStatus> |
| 510 | climber_status_offset = climber_.Iterate( |
| 511 | climber_goal, position->climber(), |
| 512 | output != nullptr ? &output_struct.climber_voltage : nullptr, |
| 513 | status->fbb()); |
| 514 | |
Niko Sohmers | ac4d887 | 2024-02-23 13:55:47 -0800 | [diff] [blame] | 515 | double max_intake_pivot_position = 0; |
| 516 | double min_intake_pivot_position = 0; |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 517 | double max_extend_position = 0; |
| 518 | double min_extend_position = 0; |
Niko Sohmers | ac4d887 | 2024-02-23 13:55:47 -0800 | [diff] [blame] | 519 | |
| 520 | aos::FlatbufferFixedAllocatorArray< |
| 521 | frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal, 512> |
| 522 | intake_pivot_goal_buffer; |
| 523 | |
| 524 | intake_pivot_goal_buffer.Finish( |
| 525 | frc971::control_loops::CreateStaticZeroingSingleDOFProfiledSubsystemGoal( |
| 526 | *intake_pivot_goal_buffer.fbb(), intake_pivot_position)); |
| 527 | |
| 528 | const frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal |
| 529 | *intake_pivot_goal = &intake_pivot_goal_buffer.message(); |
| 530 | |
| 531 | double *intake_output = |
| 532 | (output != nullptr ? &output_struct.intake_pivot_voltage : nullptr); |
| 533 | |
| 534 | const bool disabled = intake_pivot_.Correct( |
| 535 | intake_pivot_goal, position->intake_pivot(), intake_output == nullptr); |
| 536 | |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 537 | aos::FlatbufferFixedAllocatorArray< |
| 538 | frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal, 512> |
| 539 | extend_goal_buffer; |
| 540 | |
| 541 | extend_goal_buffer.Finish( |
| 542 | frc971::control_loops::CreateStaticZeroingSingleDOFProfiledSubsystemGoal( |
| 543 | *extend_goal_buffer.fbb(), extend_goal_position)); |
| 544 | |
| 545 | const frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal |
| 546 | *extend_goal = &extend_goal_buffer.message(); |
| 547 | |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 548 | // TODO(max): Change how we handle the collision with the turret and |
| 549 | // intake to be clearer |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 550 | const flatbuffers::Offset<ShooterStatus> shooter_status_offset = |
| 551 | shooter_.Iterate( |
| 552 | position, |
| 553 | unsafe_goal != nullptr ? unsafe_goal->shooter_goal() : nullptr, |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 554 | unsafe_goal != nullptr ? unsafe_goal->fire() : false, |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 555 | output != nullptr ? &output_struct.catapult_voltage : nullptr, |
| 556 | output != nullptr ? &output_struct.altitude_voltage : nullptr, |
| 557 | output != nullptr ? &output_struct.turret_voltage : nullptr, |
| 558 | output != nullptr ? &output_struct.retention_roller_voltage : nullptr, |
Maxwell Henderson | d5bf47a | 2024-02-23 17:16:48 -0800 | [diff] [blame] | 559 | output != nullptr |
| 560 | ? &output_struct.retention_roller_stator_current_limit |
| 561 | : nullptr, |
Maxwell Henderson | 461a8a4 | 2024-02-23 17:07:39 -0800 | [diff] [blame] | 562 | robot_state().voltage_battery(), &collision_avoidance_, |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 563 | extend_goal_position, extend_.estimated_position(), |
| 564 | &max_extend_position, &min_extend_position, |
Niko Sohmers | ac4d887 | 2024-02-23 13:55:47 -0800 | [diff] [blame] | 565 | intake_pivot_.estimated_position(), &max_intake_pivot_position, |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 566 | &min_intake_pivot_position, status->fbb(), timestamp); |
Niko Sohmers | ac4d887 | 2024-02-23 13:55:47 -0800 | [diff] [blame] | 567 | |
| 568 | intake_pivot_.set_min_position(min_intake_pivot_position); |
| 569 | intake_pivot_.set_max_position(max_intake_pivot_position); |
| 570 | |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 571 | extend_.set_min_position(min_extend_position); |
| 572 | extend_.set_max_position(max_extend_position); |
| 573 | |
Niko Sohmers | ac4d887 | 2024-02-23 13:55:47 -0800 | [diff] [blame] | 574 | // Calculate the loops for a cycle. |
| 575 | const double voltage = intake_pivot_.UpdateController(disabled); |
| 576 | |
| 577 | intake_pivot_.UpdateObserver(voltage); |
| 578 | |
| 579 | // Write out all the voltages. |
| 580 | if (intake_output) { |
| 581 | *intake_output = voltage; |
| 582 | } |
| 583 | |
| 584 | const flatbuffers::Offset<AbsoluteEncoderProfiledJointStatus> |
| 585 | intake_pivot_status_offset = intake_pivot_.MakeStatus(status->fbb()); |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 586 | |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 587 | const flatbuffers::Offset<PotAndAbsoluteEncoderProfiledJointStatus> |
| 588 | extend_status_offset = extend_.Iterate( |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 589 | extend_goal, position->extend(), |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 590 | output != nullptr ? &output_struct.extend_voltage : nullptr, |
| 591 | status->fbb()); |
| 592 | |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 593 | if (output) { |
| 594 | output->CheckOk(output->Send(Output::Pack(*output->fbb(), &output_struct))); |
| 595 | } |
| 596 | |
| 597 | Status::Builder status_builder = status->MakeBuilder<Status>(); |
Niko Sohmers | afc51fe | 2024-01-29 17:48:35 -0800 | [diff] [blame] | 598 | |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 599 | const bool zeroed = intake_pivot_.zeroed() && climber_.zeroed() && |
| 600 | shooter_.zeroed() && extend_.zeroed(); |
| 601 | const bool estopped = intake_pivot_.estopped() || climber_.estopped() || |
| 602 | shooter_.estopped() || extend_.estopped(); |
Niko Sohmers | afc51fe | 2024-01-29 17:48:35 -0800 | [diff] [blame] | 603 | |
| 604 | status_builder.add_zeroed(zeroed); |
| 605 | status_builder.add_estopped(estopped); |
Filip Kujawa | 102a9b2 | 2024-02-18 09:40:23 -0800 | [diff] [blame] | 606 | status_builder.add_intake_roller(intake_roller_state); |
| 607 | status_builder.add_intake_pivot(intake_pivot_status_offset); |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 608 | status_builder.add_transfer_roller(transfer_roller_status); |
Filip Kujawa | 102a9b2 | 2024-02-18 09:40:23 -0800 | [diff] [blame] | 609 | status_builder.add_climber(climber_status_offset); |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 610 | status_builder.add_shooter(shooter_status_offset); |
Niko Sohmers | ac4d887 | 2024-02-23 13:55:47 -0800 | [diff] [blame] | 611 | status_builder.add_collided(collided); |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 612 | status_builder.add_extend_roller(extend_roller_status); |
| 613 | status_builder.add_extend_status(extend_status); |
| 614 | status_builder.add_extend(extend_status_offset); |
| 615 | status_builder.add_state(state_); |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 616 | status_builder.add_uncompleted_note_goal(uncompleted_note_goal_status); |
James Kuszmaul | 0281e15 | 2024-02-26 22:26:16 -0800 | [diff] [blame] | 617 | status_builder.add_extend_ready_for_transfer(extend_at_retracted); |
Niko Sohmers | 2a251cd | 2024-03-02 19:16:15 -0800 | [diff] [blame^] | 618 | status_builder.add_extend_at_retracted(extend_at_retracted); |
| 619 | status_builder.add_turret_ready_for_load(turret_ready_for_load); |
| 620 | status_builder.add_altitude_ready_for_load(altitude_ready_for_load); |
| 621 | status_builder.add_extend_ready_for_catapult_transfer( |
| 622 | extend_ready_for_catapult_transfer); |
| 623 | status_builder.add_extend_beambreak(position->extend_beambreak()); |
| 624 | status_builder.add_catapult_beambreak(position->catapult_beambreak()); |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 625 | |
| 626 | (void)status->Send(status_builder.Finish()); |
| 627 | } |
| 628 | |
| 629 | double Superstructure::robot_velocity() const { |
| 630 | return (drivetrain_status_fetcher_.get() != nullptr |
| 631 | ? drivetrain_status_fetcher_->robot_speed() |
| 632 | : 0.0); |
| 633 | } |
| 634 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 635 | } // namespace y2024::control_loops::superstructure |