blob: 9516d7060be887888e1ae852607b13ef83791ac9 [file] [log] [blame]
Ariv Diggi0af59c02023-10-07 13:15:39 -07001#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
26using frc971::CreateProfileParameters;
27using frc971::control_loops::CreateStaticZeroingSingleDOFProfiledSubsystemGoal;
28using frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal;
29using frc971::input::driver_station::ButtonLocation;
30using frc971::input::driver_station::ControlBit;
31using frc971::input::driver_station::JoystickAxis;
32using frc971::input::driver_station::POVLocation;
33using Side = frc971::control_loops::drivetrain::RobotSide;
34
Stephan Pleinesf63bde82024-01-13 15:59:33 -080035namespace y2023_bot3::input::joysticks {
Ariv Diggi0af59c02023-10-07 13:15:39 -070036
37namespace superstructure = y2023_bot3::control_loops::superstructure;
38
39struct ButtonData {
40 ButtonLocation button;
41};
42
Filip Kujawaffff93c2023-11-14 21:33:26 -080043namespace {
44// XBox controller
45const ButtonLocation kSpit(3, 1); // A
46const ButtonLocation kSpitHigh(3, 4); // Y
47const ButtonLocation kPickup(3, 8); // M4
48const ButtonLocation kPickupBack(3, 7); // M3
49const ButtonLocation kScore(3, 9); // M1
50const ButtonLocation kScoreBack(3, 10); // M2
51const ButtonLocation kScoreMid(3, 5); // LB
52const ButtonLocation kScoreMidBack(3, 6); // RB
53} // namespace
Ariv Diggi0af59c02023-10-07 13:15:39 -070054class 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 Kujawaffff93c2023-11-14 21:33:26 -080060 ::frc971::input::DrivetrainInputReader::InputType::kPistol, {}),
Ariv Diggi0af59c02023-10-07 13:15:39 -070061 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 Kujawaffff93c2023-11-14 21:33:26 -080088
Ariv Diggi0af59c02023-10-07 13:15:39 -070089 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 Pleinesf63bde82024-01-13 15:59:33 -0800102} // namespace y2023_bot3::input::joysticks
Ariv Diggi0af59c02023-10-07 13:15:39 -0700103
104int 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 Henderson4d4be542023-11-29 18:26:13 -0800116}