blob: 532bd9bf3c80d13a3391805456fb19e0823b5725 [file] [log] [blame]
Nikolai Sohmers0991b1f2024-10-20 14:24:34 -07001#ifndef AOS_INPUT_SWERVE_JOYSTICK_INPUT_H_
2#define AOS_INPUT_SWERVE_JOYSTICK_INPUT_H_
3
4#include "aos/actions/actions.h"
5#include "frc971/input/driver_station_data.h"
6#include "frc971/input/drivetrain_input.h"
7#include "frc971/input/joystick_input.h"
8
9using frc971::control_loops::drivetrain::PistolBottomButtonUse;
10using frc971::control_loops::drivetrain::PistolSecondButtonUse;
11using frc971::control_loops::drivetrain::PistolTopButtonUse;
12
13namespace frc971::input {
14
15class SwerveJoystickInput : public ::frc971::input::JoystickInput {
16 public:
17 // Configuration parameters that don't really belong in the DrivetrainConfig.
18 struct InputConfig {
19 // Use button 14 and 15 to encode the id of the joystick and remap the
20 // joysticks so that their ids are independent of their order on the
21 // driverstation.
22 bool use_redundant_joysticks = false;
23 };
24 SwerveJoystickInput(::aos::EventLoop *event_loop,
25 const InputConfig &input_config)
26 : ::frc971::input::JoystickInput(event_loop),
27 input_config_(input_config),
28 drivetrain_input_reader_(SwerveDrivetrainInputReader::Make(event_loop)),
29 goal_sender_(event_loop->MakeSender<control_loops::swerve::GoalStatic>(
30 "/drivetrain")) {}
31
32 virtual ~SwerveJoystickInput() {}
33
34 protected:
35 bool was_running_action() { return was_running_; }
36
37 // Returns true if an action is running.
38 bool ActionRunning() { return action_queue_.Running(); }
39 // Cancels all actions.
40 void CancelAllActions() { action_queue_.CancelAllActions(); }
41 // Cancels the current action.
42 void CancelCurrentAction() { action_queue_.CancelCurrentAction(); }
43
44 // Enqueues an action.
45 void EnqueueAction(::std::unique_ptr<::aos::common::actions::Action> action) {
46 action_queue_.EnqueueAction(::std::move(action));
47 }
48
49 private:
50 // Handles any year specific superstructure code.
51 virtual void HandleTeleop(
52 const ::frc971::input::driver_station::Data &data) = 0;
53
54 void RunIteration(const ::frc971::input::driver_station::Data &data) override;
55
56 void DoRunIteration(const ::frc971::input::driver_station::Data &data);
57
58 void HandleDrivetrain(const ::frc971::input::driver_station::Data &data);
59
60 // True if an action was running last cycle.
61 bool was_running_ = false;
62
63 // Bool to track if auto was running the last cycle through. This lets us
64 // call AutoEnded when the auto mode function stops.
65
66 const InputConfig input_config_;
67
68 ::std::unique_ptr<SwerveDrivetrainInputReader> drivetrain_input_reader_;
69 ::aos::Sender<control_loops::swerve::GoalStatic> goal_sender_;
70
71 ::aos::common::actions::ActionQueue action_queue_;
72};
73
74} // namespace frc971::input
75
76#endif // AOS_SWERVE_ACTION_JOYSTICK_INPUT_H_