blob: 88d16b22d54ed8505039e2fbfd3d29d22e5e13f8 [file] [log] [blame]
Ravago Jones486de802021-05-19 20:47:55 -07001#include <math.h>
2#include <stdio.h>
3#include <string.h>
4#include <unistd.h>
5
6#include "aos/actions/actions.h"
7#include "aos/init.h"
Ravago Jones486de802021-05-19 20:47:55 -07008#include "aos/logging/logging.h"
9#include "aos/network/team_number.h"
10#include "aos/util/log_interval.h"
11#include "frc971/autonomous/base_autonomous_actor.h"
James Kuszmaul7077d342021-06-09 20:23:58 -070012#include "frc971/input/action_joystick_input.h"
13#include "frc971/input/driver_station_data.h"
14#include "frc971/input/drivetrain_input.h"
15#include "frc971/input/joystick_input.h"
Ravago Jones486de802021-05-19 20:47:55 -070016#include "y2021_bot3/control_loops/drivetrain/drivetrain_base.h"
17#include "y2021_bot3/control_loops/superstructure/superstructure_goal_generated.h"
18#include "y2021_bot3/control_loops/superstructure/superstructure_status_generated.h"
19
James Kuszmaul7077d342021-06-09 20:23:58 -070020using frc971::input::driver_station::ButtonLocation;
21using frc971::input::driver_station::ControlBit;
22using frc971::input::driver_station::JoystickAxis;
23using frc971::input::driver_station::POVLocation;
Ravago Jones486de802021-05-19 20:47:55 -070024
25namespace y2021_bot3 {
26namespace input {
27namespace joysticks {
28
29namespace superstructure = y2021_bot3::control_loops::superstructure;
30
James Kuszmaul7077d342021-06-09 20:23:58 -070031class Reader : public ::frc971::input::ActionJoystickInput {
Ravago Jones486de802021-05-19 20:47:55 -070032 public:
33 Reader(::aos::EventLoop *event_loop)
James Kuszmaul7077d342021-06-09 20:23:58 -070034 : ::frc971::input::ActionJoystickInput(
Ravago Jones486de802021-05-19 20:47:55 -070035 event_loop,
36 ::y2021_bot3::control_loops::drivetrain::GetDrivetrainConfig(),
James Kuszmaul7077d342021-06-09 20:23:58 -070037 ::frc971::input::DrivetrainInputReader::InputType::kPistol, {}),
Ravago Jones486de802021-05-19 20:47:55 -070038 superstructure_goal_sender_(
39 event_loop->MakeSender<superstructure::Goal>("/superstructure")),
40 superstructure_status_fetcher_(
41 event_loop->MakeFetcher<superstructure::Status>(
42 "/superstructure")) {}
43
44 void AutoEnded() override { AOS_LOG(INFO, "Auto ended.\n"); }
45
46 void HandleTeleop(
James Kuszmaul7077d342021-06-09 20:23:58 -070047 const ::frc971::input::driver_station::Data & /*data*/) override {
Ravago Jones486de802021-05-19 20:47:55 -070048 superstructure_status_fetcher_.Fetch();
49 if (!superstructure_status_fetcher_.get()) {
50 AOS_LOG(ERROR, "Got no superstructure status message.\n");
51 return;
52 }
53 }
54
55 private:
56 ::aos::Sender<superstructure::Goal> superstructure_goal_sender_;
57
58 ::aos::Fetcher<superstructure::Status> superstructure_status_fetcher_;
59};
60
61} // namespace joysticks
62} // namespace input
63} // namespace y2021_bot3
64
65int main(int argc, char **argv) {
66 ::aos::InitGoogle(&argc, &argv);
67
68 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
69 aos::configuration::ReadConfig("config.json");
70
71 ::aos::ShmEventLoop event_loop(&config.message());
72 ::y2021_bot3::input::joysticks::Reader reader(&event_loop);
73
74 event_loop.Run();
75
76 return 0;
77}