Ariv Diggi | 0af59c0 | 2023-10-07 13:15:39 -0700 | [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/control_loops/drivetrain/localizer_generated.h" |
| 14 | #include "frc971/control_loops/profiled_subsystem_generated.h" |
| 15 | #include "frc971/input/action_joystick_input.h" |
| 16 | #include "frc971/input/driver_station_data.h" |
| 17 | #include "frc971/input/drivetrain_input.h" |
| 18 | #include "frc971/input/joystick_input.h" |
| 19 | #include "frc971/input/redundant_joystick_data.h" |
| 20 | #include "frc971/zeroing/wrap.h" |
| 21 | #include "y2023_bot3/constants.h" |
| 22 | #include "y2023_bot3/control_loops/drivetrain/drivetrain_base.h" |
| 23 | #include "y2023_bot3/control_loops/superstructure/superstructure_goal_generated.h" |
| 24 | #include "y2023_bot3/control_loops/superstructure/superstructure_status_generated.h" |
| 25 | |
| 26 | using frc971::CreateProfileParameters; |
| 27 | using frc971::control_loops::CreateStaticZeroingSingleDOFProfiledSubsystemGoal; |
| 28 | using frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal; |
| 29 | using frc971::input::driver_station::ButtonLocation; |
| 30 | using frc971::input::driver_station::ControlBit; |
| 31 | using frc971::input::driver_station::JoystickAxis; |
| 32 | using frc971::input::driver_station::POVLocation; |
| 33 | using Side = frc971::control_loops::drivetrain::RobotSide; |
| 34 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame^] | 35 | namespace y2023_bot3::input::joysticks { |
Ariv Diggi | 0af59c0 | 2023-10-07 13:15:39 -0700 | [diff] [blame] | 36 | |
| 37 | namespace superstructure = y2023_bot3::control_loops::superstructure; |
| 38 | |
| 39 | struct ButtonData { |
| 40 | ButtonLocation button; |
| 41 | }; |
| 42 | |
Filip Kujawa | ffff93c | 2023-11-14 21:33:26 -0800 | [diff] [blame] | 43 | namespace { |
| 44 | // XBox controller |
| 45 | const ButtonLocation kSpit(3, 1); // A |
| 46 | const ButtonLocation kSpitHigh(3, 4); // Y |
| 47 | const ButtonLocation kPickup(3, 8); // M4 |
| 48 | const ButtonLocation kPickupBack(3, 7); // M3 |
| 49 | const ButtonLocation kScore(3, 9); // M1 |
| 50 | const ButtonLocation kScoreBack(3, 10); // M2 |
| 51 | const ButtonLocation kScoreMid(3, 5); // LB |
| 52 | const ButtonLocation kScoreMidBack(3, 6); // RB |
| 53 | } // namespace |
Ariv Diggi | 0af59c0 | 2023-10-07 13:15:39 -0700 | [diff] [blame] | 54 | class Reader : public ::frc971::input::ActionJoystickInput { |
| 55 | public: |
| 56 | Reader(::aos::EventLoop *event_loop) |
| 57 | : ::frc971::input::ActionJoystickInput( |
| 58 | event_loop, |
| 59 | ::y2023_bot3::control_loops::drivetrain::GetDrivetrainConfig(), |
Filip Kujawa | ffff93c | 2023-11-14 21:33:26 -0800 | [diff] [blame] | 60 | ::frc971::input::DrivetrainInputReader::InputType::kPistol, {}), |
Ariv Diggi | 0af59c0 | 2023-10-07 13:15:39 -0700 | [diff] [blame] | 61 | superstructure_goal_sender_( |
| 62 | event_loop->MakeSender<superstructure::Goal>("/superstructure")), |
| 63 | superstructure_status_fetcher_( |
| 64 | event_loop->MakeFetcher<superstructure::Status>( |
| 65 | "/superstructure")) {} |
| 66 | |
| 67 | void AutoEnded() override { AOS_LOG(INFO, "Auto ended.\n"); } |
| 68 | |
| 69 | bool has_scored_ = false; |
| 70 | |
| 71 | void HandleTeleop( |
| 72 | const ::frc971::input::driver_station::Data &data) override { |
| 73 | (void)data; |
| 74 | superstructure_status_fetcher_.Fetch(); |
| 75 | if (!superstructure_status_fetcher_.get()) { |
| 76 | AOS_LOG(ERROR, "Got no superstructure status message.\n"); |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | std::optional<double> place_index = std::nullopt; |
| 81 | (void)place_index; |
| 82 | |
| 83 | { |
| 84 | auto builder = superstructure_goal_sender_.MakeBuilder(); |
| 85 | |
| 86 | superstructure::Goal::Builder superstructure_goal_builder = |
| 87 | builder.MakeBuilder<superstructure::Goal>(); |
Filip Kujawa | ffff93c | 2023-11-14 21:33:26 -0800 | [diff] [blame] | 88 | |
Ariv Diggi | 0af59c0 | 2023-10-07 13:15:39 -0700 | [diff] [blame] | 89 | if (builder.Send(superstructure_goal_builder.Finish()) != |
| 90 | aos::RawSender::Error::kOk) { |
| 91 | AOS_LOG(ERROR, "Sending superstructure goal failed.\n"); |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | private: |
| 97 | ::aos::Sender<superstructure::Goal> superstructure_goal_sender_; |
| 98 | |
| 99 | ::aos::Fetcher<superstructure::Status> superstructure_status_fetcher_; |
| 100 | }; |
| 101 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame^] | 102 | } // namespace y2023_bot3::input::joysticks |
Ariv Diggi | 0af59c0 | 2023-10-07 13:15:39 -0700 | [diff] [blame] | 103 | |
| 104 | int main(int argc, char **argv) { |
| 105 | ::aos::InitGoogle(&argc, &argv); |
| 106 | |
| 107 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 108 | aos::configuration::ReadConfig("aos_config.json"); |
| 109 | |
| 110 | ::aos::ShmEventLoop event_loop(&config.message()); |
| 111 | ::y2023_bot3::input::joysticks::Reader reader(&event_loop); |
| 112 | |
| 113 | event_loop.Run(); |
| 114 | |
| 115 | return 0; |
Maxwell Henderson | 4d4be54 | 2023-11-29 18:26:13 -0800 | [diff] [blame] | 116 | } |