blob: 2e874d3b055e7b89cbd3fb06c3840c9b9b7a19d9 [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
45class Reader : public ::frc971::input::ActionJoystickInput {
46 public:
47 Reader(::aos::EventLoop *event_loop)
48 : ::frc971::input::ActionJoystickInput(
49 event_loop,
50 ::y2023_bot3::control_loops::drivetrain::GetDrivetrainConfig(),
51 ::frc971::input::DrivetrainInputReader::InputType::kPistol,
52 {.use_redundant_joysticks = true}),
53 superstructure_goal_sender_(
54 event_loop->MakeSender<superstructure::Goal>("/superstructure")),
55 superstructure_status_fetcher_(
56 event_loop->MakeFetcher<superstructure::Status>(
57 "/superstructure")) {}
58
59 void AutoEnded() override { AOS_LOG(INFO, "Auto ended.\n"); }
60
61 bool has_scored_ = false;
62
63 void HandleTeleop(
64 const ::frc971::input::driver_station::Data &data) override {
65 (void)data;
66 superstructure_status_fetcher_.Fetch();
67 if (!superstructure_status_fetcher_.get()) {
68 AOS_LOG(ERROR, "Got no superstructure status message.\n");
69 return;
70 }
71
72 std::optional<double> place_index = std::nullopt;
73 (void)place_index;
74
75 {
76 auto builder = superstructure_goal_sender_.MakeBuilder();
77
78 superstructure::Goal::Builder superstructure_goal_builder =
79 builder.MakeBuilder<superstructure::Goal>();
80 if (builder.Send(superstructure_goal_builder.Finish()) !=
81 aos::RawSender::Error::kOk) {
82 AOS_LOG(ERROR, "Sending superstructure goal failed.\n");
83 }
84 }
85 }
86
87 private:
88 ::aos::Sender<superstructure::Goal> superstructure_goal_sender_;
89
90 ::aos::Fetcher<superstructure::Status> superstructure_status_fetcher_;
91};
92
93} // namespace joysticks
94} // namespace input
95} // namespace y2023_bot3
96
97int main(int argc, char **argv) {
98 ::aos::InitGoogle(&argc, &argv);
99
100 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
101 aos::configuration::ReadConfig("aos_config.json");
102
103 ::aos::ShmEventLoop event_loop(&config.message());
104 ::y2023_bot3::input::joysticks::Reader reader(&event_loop);
105
106 event_loop.Run();
107
108 return 0;
109}