milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame^] | 1 | #include <unistd.h> |
| 2 | |
| 3 | #include <cmath> |
| 4 | #include <cstdio> |
| 5 | #include <cstring> |
| 6 | |
| 7 | #include "aos/actions/actions.h" |
| 8 | #include "aos/init.h" |
| 9 | #include "aos/logging/logging.h" |
| 10 | #include "aos/network/team_number.h" |
| 11 | #include "aos/util/log_interval.h" |
| 12 | #include "frc971/autonomous/base_autonomous_actor.h" |
| 13 | #include "frc971/input/action_joystick_input.h" |
| 14 | #include "frc971/input/driver_station_data.h" |
| 15 | #include "frc971/input/drivetrain_input.h" |
| 16 | #include "frc971/input/joystick_input.h" |
| 17 | #include "y2022/control_loops/drivetrain/drivetrain_base.h" |
| 18 | #include "y2022/control_loops/superstructure/superstructure_goal_generated.h" |
| 19 | #include "y2022/control_loops/superstructure/superstructure_status_generated.h" |
| 20 | |
| 21 | using frc971::input::driver_station::ButtonLocation; |
| 22 | using frc971::input::driver_station::ControlBit; |
| 23 | using frc971::input::driver_station::JoystickAxis; |
| 24 | using frc971::input::driver_station::POVLocation; |
| 25 | |
| 26 | namespace y2022 { |
| 27 | namespace input { |
| 28 | namespace joysticks { |
| 29 | |
| 30 | namespace superstructure = y2022::control_loops::superstructure; |
| 31 | |
| 32 | class Reader : public ::frc971::input::ActionJoystickInput { |
| 33 | public: |
| 34 | Reader(::aos::EventLoop *event_loop) |
| 35 | : ::frc971::input::ActionJoystickInput( |
| 36 | event_loop, |
| 37 | ::y2022::control_loops::drivetrain::GetDrivetrainConfig(), |
| 38 | ::frc971::input::DrivetrainInputReader::InputType::kPistol, {}), |
| 39 | superstructure_goal_sender_( |
| 40 | event_loop->MakeSender<superstructure::Goal>("/superstructure")), |
| 41 | superstructure_status_fetcher_( |
| 42 | event_loop->MakeFetcher<superstructure::Status>( |
| 43 | "/superstructure")) {} |
| 44 | |
| 45 | void AutoEnded() override { AOS_LOG(INFO, "Auto ended.\n"); } |
| 46 | |
| 47 | void HandleTeleop( |
| 48 | const ::frc971::input::driver_station::Data & /*data*/) override { |
| 49 | superstructure_status_fetcher_.Fetch(); |
| 50 | if (!superstructure_status_fetcher_.get()) { |
| 51 | AOS_LOG(ERROR, "Got no superstructure status message.\n"); |
| 52 | return; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | private: |
| 57 | ::aos::Sender<superstructure::Goal> superstructure_goal_sender_; |
| 58 | |
| 59 | ::aos::Fetcher<superstructure::Status> superstructure_status_fetcher_; |
| 60 | }; |
| 61 | |
| 62 | } // namespace joysticks |
| 63 | } // namespace input |
| 64 | } // namespace y2022 |
| 65 | |
| 66 | int main(int argc, char **argv) { |
| 67 | ::aos::InitGoogle(&argc, &argv); |
| 68 | |
| 69 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 70 | aos::configuration::ReadConfig("config.json"); |
| 71 | |
| 72 | ::aos::ShmEventLoop event_loop(&config.message()); |
| 73 | ::y2022::input::joysticks::Reader reader(&event_loop); |
| 74 | |
| 75 | event_loop.Run(); |
| 76 | |
| 77 | return 0; |
| 78 | } |