blob: a1a42f489c493b7ce301f1d5b31f29fc23cc85e5 [file] [log] [blame]
Maxwell Hendersonad312342023-01-10 12:07:47 -08001#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/zeroing/wrap.h"
20#include "y2023/constants.h"
21#include "y2023/control_loops/drivetrain/drivetrain_base.h"
22#include "y2023/control_loops/superstructure/superstructure_goal_generated.h"
23#include "y2023/control_loops/superstructure/superstructure_status_generated.h"
24
25using frc971::CreateProfileParameters;
26using frc971::control_loops::CreateStaticZeroingSingleDOFProfiledSubsystemGoal;
27using frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal;
28using frc971::input::driver_station::ButtonLocation;
29using frc971::input::driver_station::ControlBit;
30using frc971::input::driver_station::JoystickAxis;
31using frc971::input::driver_station::POVLocation;
32
33namespace y2023 {
34namespace input {
35namespace joysticks {
36
37namespace superstructure = y2023::control_loops::superstructure;
38
39class Reader : public ::frc971::input::ActionJoystickInput {
40 public:
41 Reader(::aos::EventLoop *event_loop)
42 : ::frc971::input::ActionJoystickInput(
43 event_loop,
44 ::y2023::control_loops::drivetrain::GetDrivetrainConfig(),
45 ::frc971::input::DrivetrainInputReader::InputType::kPistol, {}),
46 superstructure_goal_sender_(
47 event_loop->MakeSender<superstructure::Goal>("/superstructure")),
48 superstructure_status_fetcher_(
49 event_loop->MakeFetcher<superstructure::Status>(
50 "/superstructure")) {}
51
52 void AutoEnded() override { AOS_LOG(INFO, "Auto ended.\n"); }
53
54 void HandleTeleop(
55 const ::frc971::input::driver_station::Data &data) override {
56 superstructure_status_fetcher_.Fetch();
57 if (!superstructure_status_fetcher_.get()) {
58 AOS_LOG(ERROR, "Got no superstructure status message.\n");
59 return;
60 }
61
62 (void)data;
63 // TODO(Xander): Use driverstaion data to provide instructions.
64 {
65 auto builder = superstructure_goal_sender_.MakeBuilder();
66
67 superstructure::Goal::Builder superstructure_goal_builder =
68 builder.MakeBuilder<superstructure::Goal>();
69
70 if (builder.Send(superstructure_goal_builder.Finish()) !=
71 aos::RawSender::Error::kOk) {
72 AOS_LOG(ERROR, "Sending superstructure goal failed.\n");
73 }
74 }
75 }
76
77 private:
78 ::aos::Sender<superstructure::Goal> superstructure_goal_sender_;
79
80 ::aos::Fetcher<superstructure::Status> superstructure_status_fetcher_;
81};
82
83} // namespace joysticks
84} // namespace input
85} // namespace y2023
86
87int main(int argc, char **argv) {
88 ::aos::InitGoogle(&argc, &argv);
89
90 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
91 aos::configuration::ReadConfig("aos_config.json");
92
93 ::aos::ShmEventLoop event_loop(&config.message());
94 ::y2023::input::joysticks::Reader reader(&event_loop);
95
96 event_loop.Run();
97
98 return 0;
99}