blob: dc60c6eb04b6ac312ba419505aa4a6ac95892090 [file] [log] [blame]
Ravago Jones486de802021-05-19 20:47:55 -07001#include <unistd.h>
2
Tyler Chatowbf0609c2021-07-31 16:13:27 -07003#include <cmath>
4#include <cstdio>
5#include <cstring>
6
Ravago Jones486de802021-05-19 20:47:55 -07007#include "aos/actions/actions.h"
8#include "aos/init.h"
Ravago Jones486de802021-05-19 20:47:55 -07009#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"
James Kuszmaul7077d342021-06-09 20:23:58 -070013#include "frc971/input/action_joystick_input.h"
14#include "frc971/input/driver_station_data.h"
15#include "frc971/input/drivetrain_input.h"
16#include "frc971/input/joystick_input.h"
Ravago Jones486de802021-05-19 20:47:55 -070017#include "y2021_bot3/control_loops/drivetrain/drivetrain_base.h"
18#include "y2021_bot3/control_loops/superstructure/superstructure_goal_generated.h"
19#include "y2021_bot3/control_loops/superstructure/superstructure_status_generated.h"
20
James Kuszmaul7077d342021-06-09 20:23:58 -070021using frc971::input::driver_station::ButtonLocation;
22using frc971::input::driver_station::ControlBit;
23using frc971::input::driver_station::JoystickAxis;
24using frc971::input::driver_station::POVLocation;
Ravago Jones486de802021-05-19 20:47:55 -070025
Stephan Pleinesf63bde82024-01-13 15:59:33 -080026namespace y2021_bot3::input::joysticks {
Ravago Jones486de802021-05-19 20:47:55 -070027
28namespace superstructure = y2021_bot3::control_loops::superstructure;
29
James Kuszmaul7077d342021-06-09 20:23:58 -070030class Reader : public ::frc971::input::ActionJoystickInput {
Ravago Jones486de802021-05-19 20:47:55 -070031 public:
32 Reader(::aos::EventLoop *event_loop)
James Kuszmaul7077d342021-06-09 20:23:58 -070033 : ::frc971::input::ActionJoystickInput(
Ravago Jones486de802021-05-19 20:47:55 -070034 event_loop,
35 ::y2021_bot3::control_loops::drivetrain::GetDrivetrainConfig(),
James Kuszmaul7077d342021-06-09 20:23:58 -070036 ::frc971::input::DrivetrainInputReader::InputType::kPistol, {}),
Ravago Jones486de802021-05-19 20:47:55 -070037 superstructure_goal_sender_(
38 event_loop->MakeSender<superstructure::Goal>("/superstructure")),
39 superstructure_status_fetcher_(
40 event_loop->MakeFetcher<superstructure::Status>(
41 "/superstructure")) {}
42
43 void AutoEnded() override { AOS_LOG(INFO, "Auto ended.\n"); }
44
45 void HandleTeleop(
James Kuszmaul7077d342021-06-09 20:23:58 -070046 const ::frc971::input::driver_station::Data & /*data*/) override {
Ravago Jones486de802021-05-19 20:47:55 -070047 superstructure_status_fetcher_.Fetch();
48 if (!superstructure_status_fetcher_.get()) {
49 AOS_LOG(ERROR, "Got no superstructure status message.\n");
50 return;
51 }
52 }
53
54 private:
55 ::aos::Sender<superstructure::Goal> superstructure_goal_sender_;
56
57 ::aos::Fetcher<superstructure::Status> superstructure_status_fetcher_;
58};
59
Stephan Pleinesf63bde82024-01-13 15:59:33 -080060} // namespace y2021_bot3::input::joysticks
Ravago Jones486de802021-05-19 20:47:55 -070061
62int main(int argc, char **argv) {
63 ::aos::InitGoogle(&argc, &argv);
64
65 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
Austin Schuhc5fa6d92022-02-25 14:36:28 -080066 aos::configuration::ReadConfig("aos_config.json");
Ravago Jones486de802021-05-19 20:47:55 -070067
68 ::aos::ShmEventLoop event_loop(&config.message());
69 ::y2021_bot3::input::joysticks::Reader reader(&event_loop);
70
71 event_loop.Run();
72
73 return 0;
74}