milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 1 | #include "y2022/control_loops/superstructure/superstructure.h" |
| 2 | |
| 3 | #include "aos/events/event_loop.h" |
| 4 | |
| 5 | namespace y2022 { |
| 6 | namespace control_loops { |
| 7 | namespace superstructure { |
| 8 | |
| 9 | using frc971::control_loops::AbsoluteEncoderProfiledJointStatus; |
| 10 | using frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus; |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame^] | 11 | using frc971::control_loops:: RelativeEncoderProfiledJointStatus; |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 12 | |
| 13 | Superstructure::Superstructure(::aos::EventLoop *event_loop, |
| 14 | const ::std::string &name) |
| 15 | : frc971::controls::ControlLoop<Goal, Position, Status, Output>(event_loop, |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame^] | 16 | name), |
| 17 | climber_(constants::GetValues().climber.subsystem_params) { |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 18 | event_loop->SetRuntimeRealtimePriority(30); |
| 19 | } |
| 20 | |
| 21 | void Superstructure::RunIteration(const Goal *unsafe_goal, |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame^] | 22 | const Position *position, |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 23 | aos::Sender<Output>::Builder *output, |
| 24 | aos::Sender<Status>::Builder *status) { |
| 25 | if (WasReset()) { |
| 26 | AOS_LOG(ERROR, "WPILib reset, restarting\n"); |
| 27 | } |
| 28 | |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame^] | 29 | OutputT output_struct; |
| 30 | |
| 31 | flatbuffers::Offset<RelativeEncoderProfiledJointStatus> |
| 32 | climber_status_offset = climber_.Iterate( |
| 33 | unsafe_goal != nullptr ? unsafe_goal->climber() : nullptr, |
| 34 | position->climber(), |
| 35 | output != nullptr ? &(output_struct.climber_voltage) : nullptr, |
| 36 | status->fbb()); |
| 37 | |
| 38 | if (output != nullptr) { |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 39 | output->CheckOk(output->Send(Output::Pack(*output->fbb(), &output_struct))); |
| 40 | } |
| 41 | |
| 42 | Status::Builder status_builder = status->MakeBuilder<Status>(); |
| 43 | |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame^] | 44 | // Climber is always zeroed; only has a pot |
| 45 | status_builder.add_zeroed(climber_.zeroed()); |
| 46 | status_builder.add_estopped(climber_.estopped()); |
| 47 | status_builder.add_climber(climber_status_offset); |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 48 | |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 49 | (void)status->Send(status_builder.Finish()); |
| 50 | } |
| 51 | |
| 52 | } // namespace superstructure |
| 53 | } // namespace control_loops |
| 54 | } // namespace y2022 |