blob: 628de2550da6ae83b069496e50efa700803dbb63 [file] [log] [blame]
milind-u086d7262022-01-19 20:44:18 -08001#ifndef Y2022_ACTORS_AUTONOMOUS_ACTOR_H_
2#define Y2022_ACTORS_AUTONOMOUS_ACTOR_H_
3
4#include "aos/actions/actions.h"
5#include "aos/actions/actor.h"
6#include "frc971/autonomous/base_autonomous_actor.h"
7#include "frc971/control_loops/control_loops_generated.h"
8#include "frc971/control_loops/drivetrain/drivetrain_config.h"
Ravago Jones81e50632022-03-11 16:23:51 -08009#include "frc971/control_loops/drivetrain/localizer_generated.h"
10#include "y2022/actors/auto_splines.h"
11#include "y2022/control_loops/superstructure/superstructure_goal_generated.h"
12#include "y2022/control_loops/superstructure/superstructure_status_generated.h"
milind-u086d7262022-01-19 20:44:18 -080013
14namespace y2022 {
15namespace actors {
16
Ravago Jones81e50632022-03-11 16:23:51 -080017using frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal;
18
19namespace superstructure = y2022::control_loops::superstructure;
20
milind-u086d7262022-01-19 20:44:18 -080021class AutonomousActor : public ::frc971::autonomous::BaseAutonomousActor {
22 public:
23 explicit AutonomousActor(::aos::EventLoop *event_loop);
24
25 bool RunAction(
26 const ::frc971::autonomous::AutonomousActionParams *params) override;
27
28 private:
29 void Reset();
Ravago Jones81e50632022-03-11 16:23:51 -080030
31 void set_intake_front_goal(double intake_front_goal) {
32 intake_front_goal_ = intake_front_goal;
33 }
34 void set_intake_back_goal(double intake_back_goal) {
35 intake_back_goal_ = intake_back_goal;
36 }
37 void set_roller_front_voltage(double roller_front_voltage) {
38 roller_front_voltage_ = roller_front_voltage;
39 }
40 void set_roller_back_voltage(double roller_back_voltage) {
41 roller_back_voltage_ = roller_back_voltage;
42 }
43 void set_transfer_roller_voltage(double voltage) {
44 transfer_roller_voltage_ = voltage;
45 }
46
47 void set_fire_at_will(bool fire) { fire_ = fire; }
Milind Upadhyay803bbf02022-03-11 17:56:26 -080048 void set_preloaded(bool preloaded) { preloaded_ = preloaded; }
Ravago Jones81e50632022-03-11 16:23:51 -080049
50 void SendSuperstructureGoal();
51 void ExtendFrontIntake();
52 void RetractFrontIntake();
53 void ExtendBackIntake();
54 void RetractBackIntake();
55 void SendStartingPosition(const Eigen::Vector3d &start);
56 void MaybeSendStartingPosition();
57
Milind Upadhyay803bbf02022-03-11 17:56:26 -080058 // Tells the superstructure the ball was preloaded and waits until it updates
59 // the state
Milind Upadhyaya7793962022-03-11 19:39:36 -080060 [[nodiscard]] bool WaitForPreloaded();
61 // Waits for a certain number of balls to be shot
62 [[nodiscard]] bool WaitForBallsShot(int num_shot);
Milind Upadhyay803bbf02022-03-11 17:56:26 -080063
Ravago Jones81e50632022-03-11 16:23:51 -080064 void SplineAuto();
Milind Upadhyaya7793962022-03-11 19:39:36 -080065 void RapidReact();
Ravago Jones81e50632022-03-11 16:23:51 -080066
67 void Replan();
68
69 double intake_front_goal_ = 0.0;
70 double intake_back_goal_ = 0.0;
71 double roller_front_voltage_ = 0.0;
72 double roller_back_voltage_ = 0.0;
73 double transfer_roller_voltage_ = 0.0;
74 bool fire_ = false;
Milind Upadhyay803bbf02022-03-11 17:56:26 -080075 bool preloaded_ = false;
Ravago Jones81e50632022-03-11 16:23:51 -080076
77 aos::Sender<frc971::control_loops::drivetrain::LocalizerControl>
78 localizer_control_sender_;
79 aos::Sender<y2022::control_loops::superstructure::Goal>
80 superstructure_goal_sender_;
81 aos::Fetcher<y2022::control_loops::superstructure::Status>
82 superstructure_status_fetcher_;
83 aos::Fetcher<aos::JoystickState> joystick_state_fetcher_;
84 aos::Fetcher<aos::RobotState> robot_state_fetcher_;
85
86 aos::TimerHandler *replan_timer_;
87 aos::TimerHandler *button_poll_;
88
89 std::optional<SplineHandle> test_spline_;
Milind Upadhyaya7793962022-03-11 19:39:36 -080090 std::optional<std::array<SplineHandle, 5>> rapid_react_splines_;
Ravago Jones81e50632022-03-11 16:23:51 -080091
92 aos::Alliance alliance_ = aos::Alliance::kInvalid;
93 AutonomousSplines auto_splines_;
94 bool user_indicated_safe_to_reset_ = false;
95 bool sent_starting_position_ = false;
96
97 bool is_planned_ = false;
98
99 std::optional<Eigen::Vector3d> starting_position_;
milind-u086d7262022-01-19 20:44:18 -0800100};
101
102} // namespace actors
103} // namespace y2022
104
105#endif // Y2022_ACTORS_AUTONOMOUS_ACTOR_H_