Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [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 "y2020/control_loops/drivetrain/drivetrain_base.h" |
| 17 | #include "y2020/control_loops/superstructure/superstructure_goal_generated.h" |
| 18 | #include "y2020/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 y2020 { |
| 26 | namespace input { |
| 27 | namespace joysticks { |
| 28 | |
| 29 | namespace superstructure = y2020::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 | ::y2020::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 { |
| 45 | AOS_LOG(INFO, "Auto ended, assuming disc and have piece\n"); |
| 46 | } |
| 47 | |
| 48 | void HandleTeleop( |
| 49 | const ::aos::input::driver_station::Data & /*data*/) override { |
| 50 | superstructure_status_fetcher_.Fetch(); |
| 51 | if (!superstructure_status_fetcher_.get()) { |
| 52 | AOS_LOG(ERROR, "Got no superstructure status message.\n"); |
| 53 | return; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | private: |
| 58 | ::aos::Sender<superstructure::Goal> superstructure_goal_sender_; |
| 59 | |
| 60 | ::aos::Fetcher<superstructure::Status> superstructure_status_fetcher_; |
| 61 | }; |
| 62 | |
| 63 | } // namespace joysticks |
| 64 | } // namespace input |
| 65 | } // namespace y2020 |
| 66 | |
| 67 | int main() { |
James Kuszmaul | ad8a808 | 2020-02-14 21:21:58 -0800 | [diff] [blame] | 68 | ::aos::InitNRT(); |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 69 | |
| 70 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 71 | aos::configuration::ReadConfig("config.json"); |
| 72 | |
| 73 | ::aos::ShmEventLoop event_loop(&config.message()); |
| 74 | ::y2020::input::joysticks::Reader reader(&event_loop); |
| 75 | |
| 76 | event_loop.Run(); |
| 77 | |
| 78 | ::aos::Cleanup(); |
| 79 | } |