blob: 7cdb2965e1200d66a1be5bd9db9f1f0c0f795111 [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
26namespace y2021_bot3 {
27namespace input {
28namespace joysticks {
29
30namespace superstructure = y2021_bot3::control_loops::superstructure;
31
James Kuszmaul7077d342021-06-09 20:23:58 -070032class Reader : public ::frc971::input::ActionJoystickInput {
Ravago Jones486de802021-05-19 20:47:55 -070033 public:
34 Reader(::aos::EventLoop *event_loop)
James Kuszmaul7077d342021-06-09 20:23:58 -070035 : ::frc971::input::ActionJoystickInput(
Ravago Jones486de802021-05-19 20:47:55 -070036 event_loop,
37 ::y2021_bot3::control_loops::drivetrain::GetDrivetrainConfig(),
James Kuszmaul7077d342021-06-09 20:23:58 -070038 ::frc971::input::DrivetrainInputReader::InputType::kPistol, {}),
Ravago Jones486de802021-05-19 20:47:55 -070039 superstructure_goal_sender_(
40 event_loop->MakeSender<superstructure::Goal>("/superstructure")),
41 superstructure_status_fetcher_(
42 event_loop->MakeFetcher<superstructure::Status>(
43 "/superstructure")) {}
44
45 void AutoEnded() override { AOS_LOG(INFO, "Auto ended.\n"); }
46
47 void HandleTeleop(
James Kuszmaul7077d342021-06-09 20:23:58 -070048 const ::frc971::input::driver_station::Data & /*data*/) override {
Ravago Jones486de802021-05-19 20:47:55 -070049 superstructure_status_fetcher_.Fetch();
50 if (!superstructure_status_fetcher_.get()) {
51 AOS_LOG(ERROR, "Got no superstructure status message.\n");
52 return;
53 }
54 }
55
56 private:
57 ::aos::Sender<superstructure::Goal> superstructure_goal_sender_;
58
59 ::aos::Fetcher<superstructure::Status> superstructure_status_fetcher_;
60};
61
62} // namespace joysticks
63} // namespace input
64} // namespace y2021_bot3
65
66int main(int argc, char **argv) {
67 ::aos::InitGoogle(&argc, &argv);
68
69 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
70 aos::configuration::ReadConfig("config.json");
71
72 ::aos::ShmEventLoop event_loop(&config.message());
73 ::y2021_bot3::input::joysticks::Reader reader(&event_loop);
74
75 event_loop.Run();
76
77 return 0;
78}