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 | |
| 18 | using frc971::control_loops::AbsoluteEncoderProfiledJointStatus; |
| 19 | using frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus; |
| 20 | using frc971::control_loops::RelativeEncoderProfiledJointStatus; |
| 21 | |
| 22 | Superstructure::Superstructure(::aos::EventLoop *event_loop, |
| 23 | std::shared_ptr<const constants::Values> values, |
| 24 | const ::std::string &name) |
| 25 | : frc971::controls::ControlLoop<Goal, Position, Status, Output>(event_loop, |
| 26 | name), |
| 27 | values_(values), |
| 28 | constants_fetcher_(event_loop) { |
| 29 | event_loop->SetRuntimeRealtimePriority(30); |
| 30 | } |
| 31 | |
| 32 | void Superstructure::RunIteration(const Goal *unsafe_goal, |
| 33 | const Position *position, |
| 34 | aos::Sender<Output>::Builder *output, |
| 35 | aos::Sender<Status>::Builder *status) { |
Ariv Diggi | 0af59c0 | 2023-10-07 13:15:39 -0700 | [diff] [blame] | 36 | const monotonic_clock::time_point timestamp = |
| 37 | event_loop()->context().monotonic_event_time; |
Ariv Diggi | 0af59c0 | 2023-10-07 13:15:39 -0700 | [diff] [blame] | 38 | |
| 39 | if (WasReset()) { |
| 40 | AOS_LOG(ERROR, "WPILib reset, restarting\n"); |
Maxwell Henderson | 3772d28 | 2023-11-06 11:07:49 -0800 | [diff] [blame^] | 41 | end_effector_.Reset(); |
Ariv Diggi | 0af59c0 | 2023-10-07 13:15:39 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | OutputT output_struct; |
| 45 | |
Maxwell Henderson | 3772d28 | 2023-11-06 11:07:49 -0800 | [diff] [blame^] | 46 | end_effector_.RunIteration( |
| 47 | timestamp, |
| 48 | unsafe_goal != nullptr ? unsafe_goal->roller_goal() : RollerGoal::IDLE, |
| 49 | position->end_effector_cube_beam_break(), &output_struct.roller_voltage, |
| 50 | unsafe_goal != nullptr ? unsafe_goal->preloaded_with_cube() : false); |
| 51 | |
Ariv Diggi | 0af59c0 | 2023-10-07 13:15:39 -0700 | [diff] [blame] | 52 | if (output) { |
| 53 | output->CheckOk(output->Send(Output::Pack(*output->fbb(), &output_struct))); |
| 54 | } |
| 55 | |
| 56 | Status::Builder status_builder = status->MakeBuilder<Status>(); |
| 57 | status_builder.add_zeroed(true); |
Maxwell Henderson | 3772d28 | 2023-11-06 11:07:49 -0800 | [diff] [blame^] | 58 | status_builder.add_end_effector_state(end_effector_.state()); |
Ariv Diggi | 0af59c0 | 2023-10-07 13:15:39 -0700 | [diff] [blame] | 59 | |
| 60 | (void)status->Send(status_builder.Finish()); |
| 61 | } |
| 62 | |
| 63 | } // namespace superstructure |
| 64 | } // namespace control_loops |
| 65 | } // namespace y2023_bot3 |