blob: e45917aa05e8ddfebb4e59c0f93e43ec85dda762 [file] [log] [blame]
milind-u086d7262022-01-19 20:44:18 -08001#include "y2022/control_loops/superstructure/superstructure.h"
2
3#include "aos/events/event_loop.h"
Milind Upadhyay225156b2022-02-25 22:42:12 -08004#include "y2022/control_loops/superstructure/collision_avoidance.h"
milind-u086d7262022-01-19 20:44:18 -08005
6namespace y2022 {
7namespace control_loops {
8namespace superstructure {
9
10using frc971::control_loops::AbsoluteEncoderProfiledJointStatus;
11using frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus;
Henry Speiser55aa3ba2022-02-21 23:21:12 -080012using frc971::control_loops::RelativeEncoderProfiledJointStatus;
milind-u086d7262022-01-19 20:44:18 -080013
14Superstructure::Superstructure(::aos::EventLoop *event_loop,
Henry Speiser55aa3ba2022-02-21 23:21:12 -080015 std::shared_ptr<const constants::Values> values,
milind-u086d7262022-01-19 20:44:18 -080016 const ::std::string &name)
17 : frc971::controls::ControlLoop<Goal, Position, Status, Output>(event_loop,
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080018 name),
Austin Schuh39f26f62022-02-24 21:34:46 -080019 values_(values),
20 climber_(values_->climber.subsystem_params),
21 intake_front_(values_->intake_front.subsystem_params),
22 intake_back_(values_->intake_back.subsystem_params),
23 turret_(values_->turret.subsystem_params),
Ravago Jones5da06352022-03-04 20:26:24 -080024 catapult_(*values_),
Henry Speiser55aa3ba2022-02-21 23:21:12 -080025 drivetrain_status_fetcher_(
26 event_loop->MakeFetcher<frc971::control_loops::drivetrain::Status>(
Austin Schuh39f26f62022-02-24 21:34:46 -080027 "/drivetrain")),
Ravago Jones5da06352022-03-04 20:26:24 -080028 can_position_fetcher_(
29 event_loop->MakeFetcher<CANPosition>("/superstructure")) {
milind-u086d7262022-01-19 20:44:18 -080030 event_loop->SetRuntimeRealtimePriority(30);
31}
32
33void Superstructure::RunIteration(const Goal *unsafe_goal,
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080034 const Position *position,
milind-u086d7262022-01-19 20:44:18 -080035 aos::Sender<Output>::Builder *output,
36 aos::Sender<Status>::Builder *status) {
37 if (WasReset()) {
38 AOS_LOG(ERROR, "WPILib reset, restarting\n");
Henry Speiser55aa3ba2022-02-21 23:21:12 -080039 intake_front_.Reset();
40 intake_back_.Reset();
41 turret_.Reset();
42 climber_.Reset();
Austin Schuh39f26f62022-02-24 21:34:46 -080043 catapult_.Reset();
Henry Speiser55aa3ba2022-02-21 23:21:12 -080044 }
45
Ravago Jones5da06352022-03-04 20:26:24 -080046 OutputT output_struct;
Milind Upadhyay225156b2022-02-25 22:42:12 -080047
Ravago Jones5da06352022-03-04 20:26:24 -080048 aos::FlatbufferFixedAllocatorArray<
49 frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal, 64>
50 turret_goal_buffer;
51
52 const aos::monotonic_clock::time_point timestamp =
53 event_loop()->context().monotonic_event_time;
Milind Upadhyay225156b2022-02-25 22:42:12 -080054
Henry Speiser55aa3ba2022-02-21 23:21:12 -080055 drivetrain_status_fetcher_.Fetch();
56 const float velocity = robot_velocity();
57
James Kuszmaul84083f42022-02-27 17:24:38 -080058 const turret::Aimer::Goal *auto_aim_goal = nullptr;
59 if (drivetrain_status_fetcher_.get() != nullptr) {
60 aimer_.Update(drivetrain_status_fetcher_.get(),
61 turret::Aimer::ShotMode::kShootOnTheFly);
62 auto_aim_goal = aimer_.TurretGoal();
63 }
64
Ravago Jones5da06352022-03-04 20:26:24 -080065 const frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal
66 *turret_goal = nullptr;
67 double roller_speed_compensated_front = 0.0;
68 double roller_speed_compensated_back = 0.0;
Milind Upadhyayb1a74ea2022-03-09 20:34:35 -080069 double transfer_roller_speed_front = 0.0;
70 double transfer_roller_speed_back = 0.0;
Ravago Jones5da06352022-03-04 20:26:24 -080071 double flipper_arms_voltage = 0.0;
Henry Speiser55aa3ba2022-02-21 23:21:12 -080072
73 if (unsafe_goal != nullptr) {
74 roller_speed_compensated_front =
75 unsafe_goal->roller_speed_front() +
76 std::max(velocity * unsafe_goal->roller_speed_compensation(), 0.0);
77
78 roller_speed_compensated_back =
79 unsafe_goal->roller_speed_back() -
80 std::min(velocity * unsafe_goal->roller_speed_compensation(), 0.0);
81
Milind Upadhyayb1a74ea2022-03-09 20:34:35 -080082 transfer_roller_speed_front = unsafe_goal->transfer_roller_speed_front();
83 transfer_roller_speed_back = unsafe_goal->transfer_roller_speed_back();
milind-u086d7262022-01-19 20:44:18 -080084
James Kuszmaul84083f42022-02-27 17:24:38 -080085 turret_goal =
86 unsafe_goal->auto_aim() ? auto_aim_goal : unsafe_goal->turret();
87 }
Austin Schuh39f26f62022-02-24 21:34:46 -080088
Milind Upadhyay803bbf02022-03-11 17:56:26 -080089 // Superstructure state machine:
Ravago Jones5da06352022-03-04 20:26:24 -080090 // 1. IDLE: Wait until an intake beambreak is triggerred, meaning that a ball
91 // is being intaked. This means that the transfer rollers have a ball. If
92 // we've been waiting here for too long without any beambreak triggered, the
93 // ball got lost, so reset.
94 // 2. TRANSFERRING: Until the turret reaches the loading position where the
95 // ball can be transferred into the catapult, wiggle the ball in place.
96 // Once the turret reaches the loading position, send the ball forward with
97 // the transfer rollers until the turret beambreak is triggered.
98 // If we have been in this state for too long, the ball probably got lost so
99 // reset back to IDLE.
100 // 3. LOADING: To load the ball into the catapult, put the flippers at the
101 // feeding speed. Wait for a timeout, and then wait until the ball has gone
102 // past the turret beambreak and the flippers have stopped moving, meaning
103 // that the ball is fully loaded in the catapult.
104 // 4. LOADED: Wait until the user asks us to fire to transition to the
105 // shooting stage. If asked to cancel the shot, reset back to the IDLE state.
106 // 5. SHOOTING: Open the flippers to get ready for the shot. If they don't
107 // open quickly enough, try reseating the ball and going back to the LOADING
108 // stage, which moves the flippers in the opposite direction first.
109 // Now, hold the flippers open and wait until the turret has reached its
110 // aiming goal. Once the turret is ready, tell the catapult to fire.
111 // If the flippers move back for some reason now, it could damage the
112 // catapult, so estop it. Otherwise, wait until the catapult shoots a ball and
113 // goes back to its return position. We have now finished the shot, so return
114 // to IDLE.
115
Milind Upadhyay803bbf02022-03-11 17:56:26 -0800116 // If we started off preloaded, skip to the loaded state.
117 // Make sure we weren't already there just in case.
118 if (unsafe_goal != nullptr && unsafe_goal->preloaded()) {
119 switch (state_) {
120 case SuperstructureState::IDLE:
121 case SuperstructureState::TRANSFERRING:
122 case SuperstructureState::LOADING:
123 state_ = SuperstructureState::LOADED;
124 loading_timer_ = timestamp;
125 break;
126 case SuperstructureState::LOADED:
127 case SuperstructureState::SHOOTING:
128 break;
129 }
130 }
131
Ravago Jones5da06352022-03-04 20:26:24 -0800132 const bool is_spitting = ((intake_state_ == IntakeState::INTAKE_FRONT_BALL &&
Milind Upadhyayb1a74ea2022-03-09 20:34:35 -0800133 transfer_roller_speed_front < 0) ||
Ravago Jones5da06352022-03-04 20:26:24 -0800134 (intake_state_ == IntakeState::INTAKE_BACK_BALL &&
Milind Upadhyayb1a74ea2022-03-09 20:34:35 -0800135 transfer_roller_speed_back < 0));
Ravago Jones5da06352022-03-04 20:26:24 -0800136
137 // Intake handling should happen regardless of the turret state
138 if (position->intake_beambreak_front() || position->intake_beambreak_back()) {
139 if (intake_state_ == IntakeState::NO_BALL) {
140 if (position->intake_beambreak_front()) {
141 intake_state_ = IntakeState::INTAKE_FRONT_BALL;
142 } else if (position->intake_beambreak_back()) {
143 intake_state_ = IntakeState::INTAKE_BACK_BALL;
144 }
145 }
146
147 intake_beambreak_timer_ = timestamp;
148 }
149
Milind Upadhyay5dfabef2022-03-06 14:08:15 -0800150 if (timestamp >
151 intake_beambreak_timer_ + constants::Values::kBallLostTime()) {
152 intake_state_ = IntakeState::NO_BALL;
153 }
154
Ravago Jones5da06352022-03-04 20:26:24 -0800155 if (intake_state_ != IntakeState::NO_BALL) {
Ravago Jones5da06352022-03-04 20:26:24 -0800156 roller_speed_compensated_front = 0.0;
157 roller_speed_compensated_back = 0.0;
158
159 const double wiggle_voltage =
Milind Upadhyayb1a74ea2022-03-09 20:34:35 -0800160 constants::Values::kTransferRollerWiggleVoltage();
Ravago Jones5da06352022-03-04 20:26:24 -0800161 // Wiggle transfer rollers: send the ball back and forth while waiting
162 // for the turret or waiting for another shot to be completed
Milind Upadhyayb1a74ea2022-03-09 20:34:35 -0800163 if (intake_state_ == IntakeState::INTAKE_FRONT_BALL) {
164 if (position->intake_beambreak_front()) {
165 transfer_roller_speed_front = -wiggle_voltage;
166 transfer_roller_speed_back = wiggle_voltage;
167 } else {
168 transfer_roller_speed_front = wiggle_voltage;
169 transfer_roller_speed_back = -wiggle_voltage;
170 }
Ravago Jones5da06352022-03-04 20:26:24 -0800171 } else {
Milind Upadhyayb1a74ea2022-03-09 20:34:35 -0800172 if (position->intake_beambreak_back()) {
173 transfer_roller_speed_back = -wiggle_voltage;
174 transfer_roller_speed_front = wiggle_voltage;
175 } else {
176 transfer_roller_speed_back = wiggle_voltage;
177 transfer_roller_speed_front = -wiggle_voltage;
178 }
Ravago Jones5da06352022-03-04 20:26:24 -0800179 }
180 }
181
182 switch (state_) {
183 case SuperstructureState::IDLE: {
Ravago Jones5da06352022-03-04 20:26:24 -0800184 if (is_spitting) {
185 intake_state_ = IntakeState::NO_BALL;
186 }
187
188 if (intake_state_ == IntakeState::NO_BALL ||
189 !(position->intake_beambreak_front() ||
190 position->intake_beambreak_back())) {
191 break;
192 }
193
194 state_ = SuperstructureState::TRANSFERRING;
Ravago Jones5da06352022-03-04 20:26:24 -0800195 // Save the side the ball is on for later
196
197 break;
198 }
199 case SuperstructureState::TRANSFERRING: {
200 // If we've been transferring for too long, the ball probably got lost
Ravago Jones5da06352022-03-04 20:26:24 -0800201 if (intake_state_ == IntakeState::NO_BALL) {
202 state_ = SuperstructureState::IDLE;
203 break;
204 }
205
206 double turret_loading_position =
207 (intake_state_ == IntakeState::INTAKE_FRONT_BALL
208 ? constants::Values::kTurretFrontIntakePos()
209 : constants::Values::kTurretBackIntakePos());
210
Ravago Jones2c390862022-03-11 17:23:21 -0800211 // Turn to the loading position as close to the current position as
212 // possible
213 // Strategy is copied from frc971/control_loops/aiming/aiming.cc
214 turret_loading_position =
215 turret_.estimated_position() +
216 aos::math::NormalizeAngle(turret_loading_position -
217 turret_.estimated_position());
218 // if out of range, reset back to within +/- pi of zero.
219 if (turret_loading_position > constants::Values::kTurretRange().upper ||
220 turret_loading_position < constants::Values::kTurretRange().lower) {
221 turret_loading_position =
222 aos::math::NormalizeAngle(turret_loading_position);
223 }
224
Ravago Jones5da06352022-03-04 20:26:24 -0800225 turret_goal_buffer.Finish(
226 frc971::control_loops::
227 CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
228 *turret_goal_buffer.fbb(), turret_loading_position));
229 turret_goal = &turret_goal_buffer.message();
230
231 const bool turret_near_goal =
232 std::abs(turret_.estimated_position() - turret_loading_position) <
233 kTurretGoalThreshold;
234 if (!turret_near_goal) {
235 break; // Wait for turret to reach the chosen intake
236 }
237
238 // Transfer rollers and flipper arm belt on
Milind Upadhyayb1a74ea2022-03-09 20:34:35 -0800239 if (intake_state_ == IntakeState::INTAKE_FRONT_BALL) {
240 transfer_roller_speed_front =
241 constants::Values::kTransferRollerVoltage();
242 transfer_roller_speed_back =
243 -constants::Values::kTransferRollerVoltage();
244 } else {
245 transfer_roller_speed_back =
246 constants::Values::kTransferRollerVoltage();
247 transfer_roller_speed_front =
248 -constants::Values::kTransferRollerVoltage();
249 }
Ravago Jones5da06352022-03-04 20:26:24 -0800250 flipper_arms_voltage = constants::Values::kFlipperFeedVoltage();
251
252 // Ball is in catapult
253 if (position->turret_beambreak()) {
254 intake_state_ = IntakeState::NO_BALL;
255 state_ = SuperstructureState::LOADING;
256 loading_timer_ = timestamp;
257 }
258 break;
259 }
260 case SuperstructureState::LOADING: {
261 flipper_arms_voltage = constants::Values::kFlipperFeedVoltage();
262
263 // Keep feeding for kExtraLoadingTime
264
Ravago Jones5da06352022-03-04 20:26:24 -0800265 // The ball should go past the turret beambreak to be loaded.
Milind Upadhyay5dfabef2022-03-06 14:08:15 -0800266 // If we got a CAN reading not too long ago, the flippers should have
267 // also stopped.
Milind Upadhyay47e0d032022-03-05 23:06:25 -0800268 if (position->turret_beambreak()) {
269 loading_timer_ = timestamp;
270 } else if (timestamp >
271 loading_timer_ + constants::Values::kExtraLoadingTime()) {
Ravago Jones5da06352022-03-04 20:26:24 -0800272 state_ = SuperstructureState::LOADED;
273 reseating_in_catapult_ = false;
274 }
275 break;
276 }
277 case SuperstructureState::LOADED: {
278 if (unsafe_goal != nullptr) {
279 if (unsafe_goal->cancel_shot()) {
280 // Cancel the shot process
281 state_ = SuperstructureState::IDLE;
282 } else if (unsafe_goal->fire()) {
283 // Start if we were asked to and the turret is at goal
284 state_ = SuperstructureState::SHOOTING;
285 prev_shot_count_ = catapult_.shot_count();
286
287 // Reset opening timeout
288 flipper_opening_start_time_ = timestamp;
289 }
290 }
291 break;
292 }
293 case SuperstructureState::SHOOTING: {
294 // Opening flipper arms could fail, wait until they are open using their
295 // potentiometers (the member below is just named encoder).
296 // Be a little more lenient if the flippers were already open in case of
297 // noise or collisions.
298 const double flipper_open_position =
299 (flippers_open_ ? constants::Values::kReseatFlipperPosition()
300 : constants::Values::kFlipperOpenPosition());
milind-u37dc40b2022-03-08 19:51:27 -0800301
302 // TODO(milind): add left arm back once it's fixed
Ravago Jones5da06352022-03-04 20:26:24 -0800303 flippers_open_ =
Ravago Jones5da06352022-03-04 20:26:24 -0800304 position->flipper_arm_right()->encoder() >= flipper_open_position;
305
306 if (flippers_open_) {
307 // Hold at kFlipperHoldVoltage
308 flipper_arms_voltage = constants::Values::kFlipperHoldVoltage();
309 } else {
310 // Open at kFlipperOpenVoltage
311 flipper_arms_voltage = constants::Values::kFlipperOpenVoltage();
312 }
313
314 if (!flippers_open_ &&
315 timestamp >
316 loading_timer_ + constants::Values::kFlipperOpeningTimeout()) {
317 // Reseat the ball and try again
318 state_ = SuperstructureState::LOADING;
319 loading_timer_ = timestamp;
320 reseating_in_catapult_ = true;
321 break;
322 }
323
324 const bool turret_near_goal =
325 turret_goal != nullptr &&
326 std::abs(turret_goal->unsafe_goal() - turret_.position()) <
327 kTurretGoalThreshold;
Henry Speiser28288cc2022-03-09 22:59:24 -0800328 const bool collided = collision_avoidance_.IsCollided(
329 {.intake_front_position = intake_front_.estimated_position(),
330 .intake_back_position = intake_back_.estimated_position(),
331 .turret_position = turret_.estimated_position(),
332 .shooting = true});
Ravago Jones5da06352022-03-04 20:26:24 -0800333
Henry Speiser28288cc2022-03-09 22:59:24 -0800334 // If the turret reached the aiming goal and the catapult is safe to move
335 // up, fire!
336 if (flippers_open_ && turret_near_goal && !collided) {
Ravago Jones5da06352022-03-04 20:26:24 -0800337 fire_ = true;
338 }
339
340 // If we started firing and the flippers closed a bit, estop to prevent
341 // damage
342 if (fire_ && !flippers_open_) {
343 catapult_.Estop();
344 }
345
346 const bool near_return_position =
347 (unsafe_goal != nullptr && unsafe_goal->has_catapult() &&
348 unsafe_goal->catapult()->has_return_position() &&
349 std::abs(unsafe_goal->catapult()->return_position()->unsafe_goal() -
350 catapult_.estimated_position()) < kCatapultGoalThreshold);
351
352 // Once the shot is complete and the catapult is back to its return
353 // position, go back to IDLE
354 if (catapult_.shot_count() > prev_shot_count_ && near_return_position) {
355 prev_shot_count_ = catapult_.shot_count();
356 fire_ = false;
357 state_ = SuperstructureState::IDLE;
358 }
359
360 break;
361 }
362 }
363
364 collision_avoidance_.UpdateGoal(
365 {.intake_front_position = intake_front_.estimated_position(),
366 .intake_back_position = intake_back_.estimated_position(),
Henry Speiser28288cc2022-03-09 22:59:24 -0800367 .turret_position = turret_.estimated_position(),
368 .shooting = state_ == SuperstructureState::SHOOTING},
Ravago Jones5da06352022-03-04 20:26:24 -0800369 turret_goal);
370
371 turret_.set_min_position(collision_avoidance_.min_turret_goal());
372 turret_.set_max_position(collision_avoidance_.max_turret_goal());
373 intake_front_.set_min_position(collision_avoidance_.min_intake_front_goal());
374 intake_front_.set_max_position(collision_avoidance_.max_intake_front_goal());
375 intake_back_.set_min_position(collision_avoidance_.min_intake_back_goal());
376 intake_back_.set_max_position(collision_avoidance_.max_intake_back_goal());
377
James Kuszmaul84083f42022-02-27 17:24:38 -0800378 const flatbuffers::Offset<AimerStatus> aimer_offset =
379 aimer_.PopulateStatus(status->fbb());
380
Milind Upadhyay5dfabef2022-03-06 14:08:15 -0800381 // Disable the catapult if we want to restart to prevent damage with
382 // flippers
Austin Schuh39f26f62022-02-24 21:34:46 -0800383 const flatbuffers::Offset<PotAndAbsoluteEncoderProfiledJointStatus>
Ravago Jones5da06352022-03-04 20:26:24 -0800384 catapult_status_offset =
385 catapult_.Iterate(unsafe_goal, position,
386 output != nullptr && !catapult_.estopped()
387 ? &(output_struct.catapult_voltage)
388 : nullptr,
389 fire_, status->fbb());
Siddhant Kanwar0e37f592022-02-21 19:26:50 -0800390
Ravago Jones5da06352022-03-04 20:26:24 -0800391 const flatbuffers::Offset<RelativeEncoderProfiledJointStatus>
Siddhant Kanwar0e37f592022-02-21 19:26:50 -0800392 climber_status_offset = climber_.Iterate(
393 unsafe_goal != nullptr ? unsafe_goal->climber() : nullptr,
Austin Schuh7f120362022-03-05 17:10:11 -0800394 position->climber(),
395 output != nullptr ? &output_struct.climber_voltage : nullptr,
396 status->fbb());
Siddhant Kanwar0e37f592022-02-21 19:26:50 -0800397
Ravago Jones5da06352022-03-04 20:26:24 -0800398 const flatbuffers::Offset<PotAndAbsoluteEncoderProfiledJointStatus>
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800399 intake_status_offset_front = intake_front_.Iterate(
400 unsafe_goal != nullptr ? unsafe_goal->intake_front() : nullptr,
Austin Schuh7f120362022-03-05 17:10:11 -0800401 position->intake_front(),
402 output != nullptr ? &output_struct.intake_voltage_front : nullptr,
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800403 status->fbb());
404
Ravago Jones5da06352022-03-04 20:26:24 -0800405 const flatbuffers::Offset<PotAndAbsoluteEncoderProfiledJointStatus>
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800406 intake_status_offset_back = intake_back_.Iterate(
407 unsafe_goal != nullptr ? unsafe_goal->intake_back() : nullptr,
Austin Schuh7f120362022-03-05 17:10:11 -0800408 position->intake_back(),
409 output != nullptr ? &output_struct.intake_voltage_back : nullptr,
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800410 status->fbb());
411
Ravago Jones5da06352022-03-04 20:26:24 -0800412 const flatbuffers::Offset<PotAndAbsoluteEncoderProfiledJointStatus>
Austin Schuh7f120362022-03-05 17:10:11 -0800413 turret_status_offset = turret_.Iterate(
414 turret_goal, position->turret(),
415 output != nullptr ? &output_struct.turret_voltage : nullptr,
416 status->fbb());
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800417
Siddhant Kanwar0e37f592022-02-21 19:26:50 -0800418 if (output != nullptr) {
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800419 output_struct.roller_voltage_front = roller_speed_compensated_front;
420 output_struct.roller_voltage_back = roller_speed_compensated_back;
Milind Upadhyayb1a74ea2022-03-09 20:34:35 -0800421 output_struct.transfer_roller_voltage_front = transfer_roller_speed_front;
422 output_struct.transfer_roller_voltage_back = transfer_roller_speed_back;
Ravago Jones5da06352022-03-04 20:26:24 -0800423 output_struct.flipper_arms_voltage = flipper_arms_voltage;
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800424
milind-u086d7262022-01-19 20:44:18 -0800425 output->CheckOk(output->Send(Output::Pack(*output->fbb(), &output_struct)));
426 }
427
428 Status::Builder status_builder = status->MakeBuilder<Status>();
429
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800430 const bool zeroed = intake_front_.zeroed() && intake_back_.zeroed() &&
Ravago Jones5da06352022-03-04 20:26:24 -0800431 turret_.zeroed() && climber_.zeroed() &&
432 catapult_.zeroed();
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800433 const bool estopped = intake_front_.estopped() || intake_back_.estopped() ||
Ravago Jones5da06352022-03-04 20:26:24 -0800434 turret_.estopped() || climber_.estopped() ||
435 catapult_.estopped();
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800436
437 status_builder.add_zeroed(zeroed);
438 status_builder.add_estopped(estopped);
439
440 status_builder.add_intake_front(intake_status_offset_front);
441 status_builder.add_intake_back(intake_status_offset_back);
442 status_builder.add_turret(turret_status_offset);
Siddhant Kanwar0e37f592022-02-21 19:26:50 -0800443 status_builder.add_climber(climber_status_offset);
Ravago Jones5da06352022-03-04 20:26:24 -0800444
Austin Schuh39f26f62022-02-24 21:34:46 -0800445 status_builder.add_catapult(catapult_status_offset);
446 status_builder.add_solve_time(catapult_.solve_time());
Austin Schuh80fc2752022-02-25 13:33:56 -0800447 status_builder.add_shot_count(catapult_.shot_count());
Ravago Jones5da06352022-03-04 20:26:24 -0800448 status_builder.add_mpc_active(catapult_.mpc_active());
449
450 status_builder.add_flippers_open(flippers_open_);
451 status_builder.add_reseating_in_catapult(reseating_in_catapult_);
452 status_builder.add_fire(fire_);
453 status_builder.add_state(state_);
454 status_builder.add_intake_state(intake_state_);
milind-u086d7262022-01-19 20:44:18 -0800455
James Kuszmaul84083f42022-02-27 17:24:38 -0800456 status_builder.add_aimer(aimer_offset);
457
milind-u086d7262022-01-19 20:44:18 -0800458 (void)status->Send(status_builder.Finish());
459}
460
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800461double Superstructure::robot_velocity() const {
462 return (drivetrain_status_fetcher_.get() != nullptr
463 ? drivetrain_status_fetcher_->robot_speed()
464 : 0.0);
465}
466
milind-u086d7262022-01-19 20:44:18 -0800467} // namespace superstructure
468} // namespace control_loops
469} // namespace y2022