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