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