Ariv Diggi | 0af59c0 | 2023-10-07 13:15:39 -0700 | [diff] [blame] | 1 | #include "y2023_bot3/control_loops/superstructure/superstructure.h" |
| 2 | |
| 3 | #include "aos/events/event_loop.h" |
| 4 | #include "aos/flatbuffer_merge.h" |
| 5 | #include "aos/network/team_number.h" |
| 6 | #include "frc971/shooter_interpolation/interpolation.h" |
| 7 | #include "frc971/zeroing/wrap.h" |
| 8 | |
| 9 | DEFINE_bool(ignore_distance, false, |
| 10 | "If true, ignore distance when shooting and obay joystick_reader"); |
| 11 | |
| 12 | namespace y2023_bot3 { |
| 13 | namespace control_loops { |
| 14 | namespace superstructure { |
| 15 | |
| 16 | using ::aos::monotonic_clock; |
| 17 | |
Ariv Diggi | 0af59c0 | 2023-10-07 13:15:39 -0700 | [diff] [blame] | 18 | using frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus; |
| 19 | using frc971::control_loops::RelativeEncoderProfiledJointStatus; |
| 20 | |
| 21 | Superstructure::Superstructure(::aos::EventLoop *event_loop, |
| 22 | std::shared_ptr<const constants::Values> values, |
| 23 | const ::std::string &name) |
| 24 | : frc971::controls::ControlLoop<Goal, Position, Status, Output>(event_loop, |
| 25 | name), |
Maxwell Henderson | 4d4be54 | 2023-11-29 18:26:13 -0800 | [diff] [blame^] | 26 | values_(values) { |
Ariv Diggi | 0af59c0 | 2023-10-07 13:15:39 -0700 | [diff] [blame] | 27 | event_loop->SetRuntimeRealtimePriority(30); |
| 28 | } |
| 29 | |
| 30 | void Superstructure::RunIteration(const Goal *unsafe_goal, |
| 31 | const Position *position, |
| 32 | aos::Sender<Output>::Builder *output, |
| 33 | aos::Sender<Status>::Builder *status) { |
Maxwell Henderson | 4d4be54 | 2023-11-29 18:26:13 -0800 | [diff] [blame^] | 34 | (void)unsafe_goal; |
| 35 | (void)position; |
Ariv Diggi | 0af59c0 | 2023-10-07 13:15:39 -0700 | [diff] [blame] | 36 | |
| 37 | if (WasReset()) { |
| 38 | AOS_LOG(ERROR, "WPILib reset, restarting\n"); |
| 39 | } |
| 40 | |
| 41 | OutputT output_struct; |
| 42 | |
Ariv Diggi | 0af59c0 | 2023-10-07 13:15:39 -0700 | [diff] [blame] | 43 | Status::Builder status_builder = status->MakeBuilder<Status>(); |
Maxwell Henderson | 43684fa | 2023-11-06 11:08:06 -0800 | [diff] [blame] | 44 | |
Maxwell Henderson | 0d22077 | 2023-11-06 11:09:58 -0800 | [diff] [blame] | 45 | if (output) { |
| 46 | output->CheckOk(output->Send(Output::Pack(*output->fbb(), &output_struct))); |
| 47 | } |
| 48 | |
Maxwell Henderson | 4d4be54 | 2023-11-29 18:26:13 -0800 | [diff] [blame^] | 49 | status_builder.add_zeroed(true); |
| 50 | |
Ariv Diggi | 0af59c0 | 2023-10-07 13:15:39 -0700 | [diff] [blame] | 51 | (void)status->Send(status_builder.Finish()); |
| 52 | } |
| 53 | |
| 54 | } // namespace superstructure |
| 55 | } // namespace control_loops |
| 56 | } // namespace y2023_bot3 |