Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame^] | 1 | #include "y2023/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/zeroing/wrap.h" |
| 7 | |
| 8 | DEFINE_bool(ignore_distance, false, |
| 9 | "If true, ignore distance when shooting and obay joystick_reader"); |
| 10 | |
| 11 | namespace y2023 { |
| 12 | namespace control_loops { |
| 13 | namespace superstructure { |
| 14 | |
| 15 | using frc971::control_loops::AbsoluteEncoderProfiledJointStatus; |
| 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), |
| 24 | values_(values), |
| 25 | drivetrain_status_fetcher_( |
| 26 | event_loop->MakeFetcher<frc971::control_loops::drivetrain::Status>( |
| 27 | "/drivetrain")), |
| 28 | joystick_state_fetcher_( |
| 29 | event_loop->MakeFetcher<aos::JoystickState>("/aos")) { |
| 30 | (void)values; |
| 31 | } |
| 32 | |
| 33 | void Superstructure::RunIteration(const Goal *unsafe_goal, |
| 34 | const Position *position, |
| 35 | aos::Sender<Output>::Builder *output, |
| 36 | aos::Sender<Status>::Builder *status) { |
| 37 | (void)unsafe_goal; |
| 38 | (void)position; |
| 39 | |
| 40 | if (WasReset()) { |
| 41 | AOS_LOG(ERROR, "WPILib reset, restarting\n"); |
| 42 | } |
| 43 | |
| 44 | OutputT output_struct; |
| 45 | if (joystick_state_fetcher_.Fetch() && |
| 46 | joystick_state_fetcher_->has_alliance()) { |
| 47 | alliance_ = joystick_state_fetcher_->alliance(); |
| 48 | } |
| 49 | drivetrain_status_fetcher_.Fetch(); |
| 50 | output->CheckOk(output->Send(Output::Pack(*output->fbb(), &output_struct))); |
| 51 | |
| 52 | Status::Builder status_builder = status->MakeBuilder<Status>(); |
| 53 | status_builder.add_zeroed(true); |
| 54 | status_builder.add_estopped(false); |
| 55 | (void)status->Send(status_builder.Finish()); |
| 56 | } |
| 57 | |
| 58 | double Superstructure::robot_velocity() const { |
| 59 | return (drivetrain_status_fetcher_.get() != nullptr |
| 60 | ? drivetrain_status_fetcher_->robot_speed() |
| 61 | : 0.0); |
| 62 | } |
| 63 | |
| 64 | } // namespace superstructure |
| 65 | } // namespace control_loops |
| 66 | } // namespace y2023 |