Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 1 | #include "y2024/control_loops/superstructure/shooter.h" |
| 2 | |
| 3 | #include "aos/flatbuffers.h" |
| 4 | #include "aos/flatbuffers/base.h" |
| 5 | #include "frc971/control_loops/aiming/aiming.h" |
| 6 | #include "y2024/control_loops/superstructure/catapult/catapult_plant.h" |
Niko Sohmers | ac4d887 | 2024-02-23 13:55:47 -0800 | [diff] [blame] | 7 | #include "y2024/control_loops/superstructure/collision_avoidance.h" |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 8 | |
| 9 | namespace y2024::control_loops::superstructure { |
| 10 | |
| 11 | using frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus; |
| 12 | |
Niko Sohmers | 6adb5b9 | 2024-03-16 17:47:54 -0700 | [diff] [blame] | 13 | constexpr double kCatapultActivationTurretThreshold = 0.03; |
| 14 | constexpr double kCatapultActivationAltitudeThreshold = 0.01; |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 15 | |
| 16 | Shooter::Shooter(aos::EventLoop *event_loop, const Constants *robot_constants) |
| 17 | : drivetrain_status_fetcher_( |
| 18 | event_loop->MakeFetcher<frc971::control_loops::drivetrain::Status>( |
| 19 | "/drivetrain")), |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 20 | robot_constants_(robot_constants), |
| 21 | catapult_( |
| 22 | robot_constants->common()->catapult(), |
| 23 | robot_constants->robot()->catapult_constants()->zeroing_constants()), |
| 24 | turret_( |
| 25 | robot_constants_->common()->turret(), |
| 26 | robot_constants_->robot()->turret_constants()->zeroing_constants()), |
| 27 | altitude_( |
| 28 | robot_constants_->common()->altitude(), |
| 29 | robot_constants_->robot()->altitude_constants()->zeroing_constants()), |
| 30 | aimer_(event_loop, robot_constants_), |
| 31 | interpolation_table_( |
| 32 | y2024::constants::Values::InterpolationTableFromFlatbuffer( |
Maxwell Henderson | 6b1be31 | 2024-02-28 20:15:06 -0800 | [diff] [blame] | 33 | robot_constants_->common()->shooter_interpolation_table())), |
| 34 | debouncer_(std::chrono::milliseconds(100), std::chrono::milliseconds(8)) { |
| 35 | } |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 36 | |
| 37 | flatbuffers::Offset<y2024::control_loops::superstructure::ShooterStatus> |
| 38 | Shooter::Iterate( |
| 39 | const y2024::control_loops::superstructure::Position *position, |
| 40 | const y2024::control_loops::superstructure::ShooterGoal *shooter_goal, |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 41 | bool fire, double *catapult_output, double *altitude_output, |
| 42 | double *turret_output, double *retention_roller_output, |
Maxwell Henderson | d5bf47a | 2024-02-23 17:16:48 -0800 | [diff] [blame] | 43 | double *retention_roller_stator_current_limit, double /*battery_voltage*/, |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 44 | CollisionAvoidance *collision_avoidance, const double extend_position, |
| 45 | const double extend_goal, double *max_extend_position, |
| 46 | double *min_extend_position, const double intake_pivot_position, |
Niko Sohmers | ac4d887 | 2024-02-23 13:55:47 -0800 | [diff] [blame] | 47 | double *max_intake_pivot_position, double *min_intake_pivot_position, |
Stephan Pleines | 9f3983a | 2024-03-13 20:22:38 -0700 | [diff] [blame] | 48 | NoteGoal requested_note_goal, flatbuffers::FlatBufferBuilder *fbb, |
Maxwell Henderson | 6b1be31 | 2024-02-28 20:15:06 -0800 | [diff] [blame] | 49 | aos::monotonic_clock::time_point monotonic_now) { |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 50 | drivetrain_status_fetcher_.Fetch(); |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 51 | |
| 52 | // If our current is over the minimum current and our velocity is under our |
| 53 | // maximum velocity, then set loaded to true. If we are preloaded set it to |
| 54 | // true as well. |
Maxwell Henderson | 6b1be31 | 2024-02-28 20:15:06 -0800 | [diff] [blame] | 55 | debouncer_.Update(position->catapult_beambreak() || |
| 56 | (shooter_goal != nullptr && shooter_goal->preloaded()), |
| 57 | monotonic_now); |
| 58 | const bool piece_loaded = debouncer_.state(); |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 59 | |
| 60 | aos::fbs::FixedStackAllocator<aos::fbs::Builder< |
| 61 | frc971::control_loops:: |
| 62 | StaticZeroingSingleDOFProfiledSubsystemGoalStatic>::kBufferSize> |
| 63 | turret_allocator; |
| 64 | |
| 65 | aos::fbs::Builder< |
| 66 | frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoalStatic> |
| 67 | turret_goal_builder(&turret_allocator); |
| 68 | |
| 69 | aos::fbs::FixedStackAllocator<aos::fbs::Builder< |
| 70 | frc971::control_loops:: |
| 71 | StaticZeroingSingleDOFProfiledSubsystemGoalStatic>::kBufferSize> |
Niko Sohmers | 6adb5b9 | 2024-03-16 17:47:54 -0700 | [diff] [blame] | 72 | auto_aim_allocator; |
| 73 | |
| 74 | aos::fbs::Builder< |
| 75 | frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoalStatic> |
| 76 | auto_aim_goal_builder(&auto_aim_allocator); |
| 77 | |
| 78 | aos::fbs::FixedStackAllocator<aos::fbs::Builder< |
| 79 | frc971::control_loops:: |
| 80 | StaticZeroingSingleDOFProfiledSubsystemGoalStatic>::kBufferSize> |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 81 | altitude_allocator; |
| 82 | |
| 83 | aos::fbs::Builder< |
| 84 | frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoalStatic> |
| 85 | altitude_goal_builder(&altitude_allocator); |
| 86 | |
| 87 | const double distance_to_goal = aimer_.DistanceToGoal(); |
| 88 | |
| 89 | // Always retain the game piece if we are enabled. |
| 90 | if (retention_roller_output != nullptr) { |
| 91 | *retention_roller_output = |
| 92 | robot_constants_->common()->retention_roller_voltages()->retaining(); |
Maxwell Henderson | d5bf47a | 2024-02-23 17:16:48 -0800 | [diff] [blame] | 93 | |
| 94 | if (piece_loaded) { |
| 95 | *retention_roller_stator_current_limit = |
| 96 | robot_constants_->common() |
| 97 | ->current_limits() |
| 98 | ->slower_retention_roller_stator_current_limit(); |
| 99 | } else { |
| 100 | *retention_roller_stator_current_limit = |
| 101 | robot_constants_->common() |
| 102 | ->current_limits() |
| 103 | ->retention_roller_stator_current_limit(); |
| 104 | } |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | bool aiming = false; |
| 108 | |
Niko Sohmers | 6adb5b9 | 2024-03-16 17:47:54 -0700 | [diff] [blame] | 109 | if (requested_note_goal == NoteGoal::AMP || |
| 110 | requested_note_goal == NoteGoal::TRAP) { |
Stephan Pleines | 9f3983a | 2024-03-13 20:22:38 -0700 | [diff] [blame] | 111 | // Being asked to amp, lift the altitude up. |
| 112 | PopulateStaticZeroingSingleDOFProfiledSubsystemGoal( |
| 113 | turret_goal_builder.get(), |
| 114 | robot_constants_->common()->turret_loading_position()); |
| 115 | |
| 116 | PopulateStaticZeroingSingleDOFProfiledSubsystemGoal( |
Niko Sohmers | 6adb5b9 | 2024-03-16 17:47:54 -0700 | [diff] [blame] | 117 | altitude_goal_builder.get(), |
| 118 | robot_constants_->common()->altitude_avoid_extend_collision_position()); |
Stephan Pleines | 9f3983a | 2024-03-13 20:22:38 -0700 | [diff] [blame] | 119 | } else if (shooter_goal == nullptr || !shooter_goal->auto_aim() || |
| 120 | (!piece_loaded && state_ == CatapultState::READY)) { |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 121 | // We don't have the note so we should be ready to intake it. |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 122 | PopulateStaticZeroingSingleDOFProfiledSubsystemGoal( |
| 123 | turret_goal_builder.get(), |
| 124 | robot_constants_->common()->turret_loading_position()); |
| 125 | |
| 126 | PopulateStaticZeroingSingleDOFProfiledSubsystemGoal( |
| 127 | altitude_goal_builder.get(), |
| 128 | robot_constants_->common()->altitude_loading_position()); |
| 129 | } else { |
| 130 | // We have a game piece, lets start aiming. |
| 131 | if (drivetrain_status_fetcher_.get() != nullptr) { |
| 132 | aiming = true; |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | |
Niko Sohmers | 6adb5b9 | 2024-03-16 17:47:54 -0700 | [diff] [blame] | 136 | // Auto aim builder is a dummy so we get a status when we aren't aiming. |
| 137 | aimer_.Update( |
| 138 | drivetrain_status_fetcher_.get(), |
| 139 | frc971::control_loops::aiming::ShotMode::kShootOnTheFly, |
| 140 | aiming ? turret_goal_builder.get() : auto_aim_goal_builder.get()); |
| 141 | |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 142 | // We have a game piece and are being asked to aim. |
| 143 | constants::Values::ShotParams shot_params; |
Niko Sohmers | 6adb5b9 | 2024-03-16 17:47:54 -0700 | [diff] [blame] | 144 | if ((piece_loaded || state_ == CatapultState::FIRING) && |
| 145 | shooter_goal != nullptr && shooter_goal->auto_aim() && |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 146 | interpolation_table_.GetInRange(distance_to_goal, &shot_params)) { |
| 147 | PopulateStaticZeroingSingleDOFProfiledSubsystemGoal( |
| 148 | altitude_goal_builder.get(), shot_params.shot_altitude_angle); |
| 149 | } |
| 150 | |
| 151 | // The builder will contain either the auto-aim goal, or the loading goal. Use |
| 152 | // it if we have no goal, or no subsystem goal, or if we are auto-aiming. |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 153 | |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 154 | const frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal |
| 155 | *turret_goal = (shooter_goal != nullptr && !shooter_goal->auto_aim() && |
Niko Sohmers | 6adb5b9 | 2024-03-16 17:47:54 -0700 | [diff] [blame] | 156 | (piece_loaded || state_ == CatapultState::FIRING) && |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 157 | shooter_goal->has_turret_position()) |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 158 | ? shooter_goal->turret_position() |
| 159 | : &turret_goal_builder->AsFlatbuffer(); |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 160 | |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 161 | const frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal |
| 162 | *altitude_goal = (shooter_goal != nullptr && !shooter_goal->auto_aim() && |
Niko Sohmers | 6adb5b9 | 2024-03-16 17:47:54 -0700 | [diff] [blame] | 163 | (piece_loaded || state_ == CatapultState::FIRING) && |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 164 | shooter_goal->has_altitude_position()) |
| 165 | ? shooter_goal->altitude_position() |
| 166 | : &altitude_goal_builder->AsFlatbuffer(); |
| 167 | |
Niko Sohmers | cc3aa45 | 2024-03-03 17:20:04 -0800 | [diff] [blame] | 168 | const bool turret_in_range = |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 169 | (std::abs(turret_.estimated_position() - turret_goal->unsafe_goal()) < |
Niko Sohmers | 6adb5b9 | 2024-03-16 17:47:54 -0700 | [diff] [blame] | 170 | kCatapultActivationTurretThreshold); |
Niko Sohmers | cc3aa45 | 2024-03-03 17:20:04 -0800 | [diff] [blame] | 171 | const bool altitude_in_range = |
| 172 | (std::abs(altitude_.estimated_position() - altitude_goal->unsafe_goal()) < |
Niko Sohmers | 6adb5b9 | 2024-03-16 17:47:54 -0700 | [diff] [blame] | 173 | kCatapultActivationAltitudeThreshold); |
Niko Sohmers | cc3aa45 | 2024-03-03 17:20:04 -0800 | [diff] [blame] | 174 | const bool altitude_above_min_angle = |
| 175 | (altitude_.estimated_position() > |
| 176 | robot_constants_->common()->min_altitude_shooting_angle()); |
| 177 | |
| 178 | bool subsystems_in_range = |
| 179 | (turret_in_range && altitude_in_range && altitude_above_min_angle); |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 180 | |
Niko Sohmers | ac4d887 | 2024-02-23 13:55:47 -0800 | [diff] [blame] | 181 | const bool disabled = turret_.Correct(turret_goal, position->turret(), |
| 182 | turret_output == nullptr); |
| 183 | |
Niko Sohmers | 77bf1fd | 2024-03-16 23:22:57 -0700 | [diff] [blame^] | 184 | // Zero out extend goal and position if "disable_extend" is true |
Niko Sohmers | ac4d887 | 2024-02-23 13:55:47 -0800 | [diff] [blame] | 185 | collision_avoidance->UpdateGoal( |
| 186 | {.intake_pivot_position = intake_pivot_position, |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 187 | .turret_position = turret_.estimated_position(), |
Niko Sohmers | 77bf1fd | 2024-03-16 23:22:57 -0700 | [diff] [blame^] | 188 | .extend_position = |
| 189 | ((!robot_constants_->common()->disable_extend()) ? extend_position |
| 190 | : 0.0)}, |
| 191 | turret_goal->unsafe_goal(), |
| 192 | ((!robot_constants_->common()->disable_extend()) ? extend_goal : 0.0)); |
Niko Sohmers | 6adb5b9 | 2024-03-16 17:47:54 -0700 | [diff] [blame] | 193 | |
| 194 | if (!CatapultRetracted()) { |
| 195 | altitude_.set_min_position( |
| 196 | robot_constants_->common()->min_altitude_shooting_angle()); |
| 197 | } else { |
| 198 | altitude_.clear_min_position(); |
| 199 | } |
| 200 | |
Niko Sohmers | ac4d887 | 2024-02-23 13:55:47 -0800 | [diff] [blame] | 201 | turret_.set_min_position(collision_avoidance->min_turret_goal()); |
| 202 | turret_.set_max_position(collision_avoidance->max_turret_goal()); |
| 203 | |
| 204 | *max_intake_pivot_position = collision_avoidance->max_intake_pivot_goal(); |
| 205 | *min_intake_pivot_position = collision_avoidance->min_intake_pivot_goal(); |
| 206 | |
Austin Schuh | 027fd62 | 2024-03-01 21:26:07 -0800 | [diff] [blame] | 207 | *max_extend_position = collision_avoidance->max_extend_goal(); |
| 208 | *min_extend_position = collision_avoidance->min_extend_goal(); |
| 209 | |
Niko Sohmers | ac4d887 | 2024-02-23 13:55:47 -0800 | [diff] [blame] | 210 | // Calculate the loops for a cycle. |
| 211 | const double voltage = turret_.UpdateController(disabled); |
| 212 | |
| 213 | turret_.UpdateObserver(voltage); |
| 214 | |
| 215 | // Write out all the voltages. |
| 216 | if (turret_output) { |
| 217 | *turret_output = voltage; |
| 218 | } |
| 219 | |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 220 | const flatbuffers::Offset<PotAndAbsoluteEncoderProfiledJointStatus> |
Niko Sohmers | ac4d887 | 2024-02-23 13:55:47 -0800 | [diff] [blame] | 221 | turret_status_offset = turret_.MakeStatus(fbb); |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 222 | |
| 223 | const flatbuffers::Offset<PotAndAbsoluteEncoderProfiledJointStatus> |
| 224 | altitude_status_offset = altitude_.Iterate( |
| 225 | altitude_goal, position->altitude(), altitude_output, fbb); |
| 226 | |
| 227 | flatbuffers::Offset<PotAndAbsoluteEncoderProfiledJointStatus> |
| 228 | catapult_status_offset; |
| 229 | { |
| 230 | // The catapult will never use a provided goal. We'll always fabricate one |
| 231 | // for it. |
| 232 | // |
| 233 | // Correct handles resetting our state when disabled. |
| 234 | const bool disabled = catapult_.Correct(nullptr, position->catapult(), |
Maxwell Henderson | 3d68e14 | 2024-02-25 09:58:11 -0800 | [diff] [blame] | 235 | catapult_output == nullptr); |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 236 | |
| 237 | catapult_.set_enable_profile(true); |
| 238 | // We want a trajectory which accelerates up over the first portion of the |
| 239 | // range of motion, holds top speed for a little bit, then decelerates |
| 240 | // before it swings too far. |
| 241 | // |
| 242 | // We can solve for these 3 parameters through the range of motion. Top |
| 243 | // speed is goverened by the voltage headroom we want to have for the |
| 244 | // controller. |
| 245 | // |
| 246 | // Accel can be tuned given the distance to accelerate over, and decel can |
| 247 | // be solved similarly. |
| 248 | // |
| 249 | // accel = v^2 / (2 * x) |
| 250 | catapult_.mutable_profile()->set_maximum_velocity( |
| 251 | catapult::kFreeSpeed * catapult::kOutputRatio * 4.0 / 12.0); |
| 252 | |
| 253 | if (disabled) { |
| 254 | state_ = CatapultState::RETRACTING; |
| 255 | } |
| 256 | |
Niko Sohmers | 6adb5b9 | 2024-03-16 17:47:54 -0700 | [diff] [blame] | 257 | constexpr double kLoadingAcceleration = 40.0; |
| 258 | constexpr double kLoadingDeceleration = 20.0; |
Maxwell Henderson | 6b1be31 | 2024-02-28 20:15:06 -0800 | [diff] [blame] | 259 | |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 260 | switch (state_) { |
| 261 | case CatapultState::READY: |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 262 | [[fallthrough]]; |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 263 | case CatapultState::LOADED: { |
| 264 | if (piece_loaded) { |
| 265 | state_ = CatapultState::LOADED; |
| 266 | } else { |
| 267 | state_ = CatapultState::READY; |
| 268 | } |
| 269 | |
| 270 | const bool catapult_close = CatapultClose(); |
| 271 | |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 272 | if (subsystems_in_range && shooter_goal != nullptr && fire && |
| 273 | catapult_close && piece_loaded) { |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 274 | state_ = CatapultState::FIRING; |
| 275 | } else { |
| 276 | catapult_.set_controller_index(0); |
Maxwell Henderson | 6b1be31 | 2024-02-28 20:15:06 -0800 | [diff] [blame] | 277 | catapult_.mutable_profile()->set_maximum_acceleration( |
| 278 | kLoadingAcceleration); |
| 279 | catapult_.mutable_profile()->set_maximum_deceleration( |
| 280 | kLoadingDeceleration); |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 281 | catapult_.set_unprofiled_goal(0.0, 0.0); |
| 282 | |
| 283 | if (!catapult_close) { |
| 284 | state_ = CatapultState::RETRACTING; |
| 285 | } |
| 286 | break; |
| 287 | } |
| 288 | [[fallthrough]]; |
| 289 | } |
| 290 | case CatapultState::FIRING: |
| 291 | *retention_roller_output = |
| 292 | robot_constants_->common()->retention_roller_voltages()->spitting(); |
Maxwell Henderson | 6b1be31 | 2024-02-28 20:15:06 -0800 | [diff] [blame] | 293 | *retention_roller_stator_current_limit = |
| 294 | robot_constants_->common() |
| 295 | ->current_limits() |
| 296 | ->shooting_retention_roller_stator_current_limit(); |
| 297 | catapult_.set_controller_index(1); |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 298 | catapult_.mutable_profile()->set_maximum_acceleration(400.0); |
Maxwell Henderson | 6b1be31 | 2024-02-28 20:15:06 -0800 | [diff] [blame] | 299 | catapult_.mutable_profile()->set_maximum_deceleration(500.0); |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 300 | catapult_.set_unprofiled_goal(2.0, 0.0); |
| 301 | if (CatapultClose()) { |
| 302 | state_ = CatapultState::RETRACTING; |
Niko Sohmers | 6adb5b9 | 2024-03-16 17:47:54 -0700 | [diff] [blame] | 303 | ++shot_count_; |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 304 | } else { |
| 305 | break; |
| 306 | } |
| 307 | [[fallthrough]]; |
| 308 | case CatapultState::RETRACTING: |
| 309 | catapult_.set_controller_index(0); |
Maxwell Henderson | 6b1be31 | 2024-02-28 20:15:06 -0800 | [diff] [blame] | 310 | catapult_.mutable_profile()->set_maximum_acceleration( |
| 311 | kLoadingAcceleration); |
| 312 | catapult_.mutable_profile()->set_maximum_deceleration( |
| 313 | kLoadingDeceleration); |
| 314 | // TODO: catapult_return_position |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 315 | catapult_.set_unprofiled_goal(0.0, 0.0); |
| 316 | |
| 317 | if (CatapultClose()) { |
| 318 | if (piece_loaded) { |
| 319 | state_ = CatapultState::LOADED; |
| 320 | } else { |
| 321 | state_ = CatapultState::READY; |
| 322 | } |
| 323 | } |
| 324 | break; |
| 325 | } |
| 326 | |
| 327 | const double voltage = catapult_.UpdateController(disabled); |
| 328 | catapult_.UpdateObserver(voltage); |
| 329 | if (catapult_output != nullptr) { |
| 330 | *catapult_output = voltage; |
| 331 | } |
| 332 | catapult_status_offset = catapult_.MakeStatus(fbb); |
| 333 | } |
| 334 | |
| 335 | flatbuffers::Offset<AimerStatus> aimer_offset; |
Niko Sohmers | 6adb5b9 | 2024-03-16 17:47:54 -0700 | [diff] [blame] | 336 | aimer_offset = aimer_.PopulateStatus(fbb); |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 337 | |
| 338 | y2024::control_loops::superstructure::ShooterStatus::Builder status_builder( |
| 339 | *fbb); |
| 340 | status_builder.add_turret(turret_status_offset); |
| 341 | status_builder.add_altitude(altitude_status_offset); |
| 342 | status_builder.add_catapult(catapult_status_offset); |
| 343 | status_builder.add_catapult_state(state_); |
Niko Sohmers | cc3aa45 | 2024-03-03 17:20:04 -0800 | [diff] [blame] | 344 | status_builder.add_turret_in_range(turret_in_range); |
| 345 | status_builder.add_altitude_in_range(altitude_in_range); |
| 346 | status_builder.add_altitude_above_min_angle(altitude_above_min_angle); |
Niko Sohmers | 6adb5b9 | 2024-03-16 17:47:54 -0700 | [diff] [blame] | 347 | status_builder.add_auto_aiming(aiming); |
| 348 | status_builder.add_aimer(aimer_offset); |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 349 | |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 350 | return status_builder.Finish(); |
| 351 | } |
| 352 | |
| 353 | } // namespace y2024::control_loops::superstructure |