blob: 4c42bdc8f116493c39fcdc3b603bd1f0bb739fae [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
35namespace y2023_bot3 {
36namespace input {
37namespace joysticks {
38
39namespace superstructure = y2023_bot3::control_loops::superstructure;
40
41struct ButtonData {
42 ButtonLocation button;
43};
44
Filip Kujawaffff93c2023-11-14 21:33:26 -080045namespace {
46// XBox controller
47const ButtonLocation kSpit(3, 1); // A
48const ButtonLocation kSpitHigh(3, 4); // Y
49const ButtonLocation kPickup(3, 8); // M4
50const ButtonLocation kPickupBack(3, 7); // M3
51const ButtonLocation kScore(3, 9); // M1
52const ButtonLocation kScoreBack(3, 10); // M2
53const ButtonLocation kScoreMid(3, 5); // LB
54const ButtonLocation kScoreMidBack(3, 6); // RB
55} // namespace
Ariv Diggi0af59c02023-10-07 13:15:39 -070056class Reader : public ::frc971::input::ActionJoystickInput {
57 public:
58 Reader(::aos::EventLoop *event_loop)
59 : ::frc971::input::ActionJoystickInput(
60 event_loop,
61 ::y2023_bot3::control_loops::drivetrain::GetDrivetrainConfig(),
Filip Kujawaffff93c2023-11-14 21:33:26 -080062 ::frc971::input::DrivetrainInputReader::InputType::kPistol, {}),
Ariv Diggi0af59c02023-10-07 13:15:39 -070063 superstructure_goal_sender_(
64 event_loop->MakeSender<superstructure::Goal>("/superstructure")),
65 superstructure_status_fetcher_(
66 event_loop->MakeFetcher<superstructure::Status>(
67 "/superstructure")) {}
68
69 void AutoEnded() override { AOS_LOG(INFO, "Auto ended.\n"); }
70
71 bool has_scored_ = false;
72
73 void HandleTeleop(
74 const ::frc971::input::driver_station::Data &data) override {
75 (void)data;
76 superstructure_status_fetcher_.Fetch();
77 if (!superstructure_status_fetcher_.get()) {
78 AOS_LOG(ERROR, "Got no superstructure status message.\n");
79 return;
80 }
81
82 std::optional<double> place_index = std::nullopt;
83 (void)place_index;
84
85 {
86 auto builder = superstructure_goal_sender_.MakeBuilder();
87
88 superstructure::Goal::Builder superstructure_goal_builder =
89 builder.MakeBuilder<superstructure::Goal>();
Filip Kujawaffff93c2023-11-14 21:33:26 -080090
Ariv Diggi0af59c02023-10-07 13:15:39 -070091 if (builder.Send(superstructure_goal_builder.Finish()) !=
92 aos::RawSender::Error::kOk) {
93 AOS_LOG(ERROR, "Sending superstructure goal failed.\n");
94 }
95 }
96 }
97
98 private:
99 ::aos::Sender<superstructure::Goal> superstructure_goal_sender_;
100
101 ::aos::Fetcher<superstructure::Status> superstructure_status_fetcher_;
102};
103
104} // namespace joysticks
105} // namespace input
106} // namespace y2023_bot3
107
108int main(int argc, char **argv) {
109 ::aos::InitGoogle(&argc, &argv);
110
111 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
112 aos::configuration::ReadConfig("aos_config.json");
113
114 ::aos::ShmEventLoop event_loop(&config.message());
115 ::y2023_bot3::input::joysticks::Reader reader(&event_loop);
116
117 event_loop.Run();
118
119 return 0;
Maxwell Henderson4d4be542023-11-29 18:26:13 -0800120}