Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 1 | #include "y2024/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 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame^] | 12 | namespace y2024::control_loops::superstructure { |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 13 | |
| 14 | using ::aos::monotonic_clock; |
| 15 | |
| 16 | using frc971::control_loops::AbsoluteEncoderProfiledJointStatus; |
| 17 | using frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus; |
| 18 | using frc971::control_loops::RelativeEncoderProfiledJointStatus; |
| 19 | |
| 20 | Superstructure::Superstructure(::aos::EventLoop *event_loop, |
| 21 | std::shared_ptr<const constants::Values> values, |
| 22 | const ::std::string &name) |
| 23 | : frc971::controls::ControlLoop<Goal, Position, Status, Output>(event_loop, |
| 24 | name), |
| 25 | values_(values), |
| 26 | constants_fetcher_(event_loop), |
| 27 | drivetrain_status_fetcher_( |
| 28 | event_loop->MakeFetcher<frc971::control_loops::drivetrain::Status>( |
| 29 | "/drivetrain")), |
| 30 | joystick_state_fetcher_( |
| 31 | event_loop->MakeFetcher<aos::JoystickState>("/aos")) { |
| 32 | event_loop->SetRuntimeRealtimePriority(30); |
| 33 | } |
| 34 | |
| 35 | void Superstructure::RunIteration(const Goal *unsafe_goal, |
| 36 | const Position *position, |
| 37 | aos::Sender<Output>::Builder *output, |
| 38 | aos::Sender<Status>::Builder *status) { |
| 39 | const monotonic_clock::time_point timestamp = |
| 40 | event_loop()->context().monotonic_event_time; |
| 41 | |
| 42 | (void)timestamp; |
| 43 | (void)unsafe_goal; |
| 44 | (void)position; |
| 45 | |
| 46 | if (WasReset()) { |
| 47 | AOS_LOG(ERROR, "WPILib reset, restarting\n"); |
| 48 | } |
| 49 | |
| 50 | OutputT output_struct; |
| 51 | if (joystick_state_fetcher_.Fetch() && |
| 52 | joystick_state_fetcher_->has_alliance()) { |
| 53 | alliance_ = joystick_state_fetcher_->alliance(); |
| 54 | } |
| 55 | drivetrain_status_fetcher_.Fetch(); |
| 56 | |
| 57 | if (output) { |
| 58 | output->CheckOk(output->Send(Output::Pack(*output->fbb(), &output_struct))); |
| 59 | } |
| 60 | |
| 61 | Status::Builder status_builder = status->MakeBuilder<Status>(); |
| 62 | status_builder.add_zeroed(true); |
| 63 | status_builder.add_estopped(false); |
| 64 | |
| 65 | (void)status->Send(status_builder.Finish()); |
| 66 | } |
| 67 | |
| 68 | double Superstructure::robot_velocity() const { |
| 69 | return (drivetrain_status_fetcher_.get() != nullptr |
| 70 | ? drivetrain_status_fetcher_->robot_speed() |
| 71 | : 0.0); |
| 72 | } |
| 73 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame^] | 74 | } // namespace y2024::control_loops::superstructure |