blob: 461cfc1c7b80de24b1cd09f7e346f1e16febd67a [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
Milind Upadhyayd86b02c2022-03-13 20:57:46 -070017using control_loops::superstructure::RequestedIntake;
Ravago Jones81e50632022-03-11 16:23:51 -080018using frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal;
19
20namespace superstructure = y2022::control_loops::superstructure;
21
milind-u086d7262022-01-19 20:44:18 -080022class AutonomousActor : public ::frc971::autonomous::BaseAutonomousActor {
23 public:
24 explicit AutonomousActor(::aos::EventLoop *event_loop);
25
26 bool RunAction(
27 const ::frc971::autonomous::AutonomousActionParams *params) override;
28
29 private:
30 void Reset();
Ravago Jones81e50632022-03-11 16:23:51 -080031
32 void set_intake_front_goal(double intake_front_goal) {
33 intake_front_goal_ = intake_front_goal;
34 }
35 void set_intake_back_goal(double intake_back_goal) {
36 intake_back_goal_ = intake_back_goal;
37 }
38 void set_roller_front_voltage(double roller_front_voltage) {
39 roller_front_voltage_ = roller_front_voltage;
40 }
41 void set_roller_back_voltage(double roller_back_voltage) {
42 roller_back_voltage_ = roller_back_voltage;
43 }
Milind Upadhyayb1a74ea2022-03-09 20:34:35 -080044 void set_transfer_roller_front_voltage(double voltage) {
45 transfer_roller_front_voltage_ = voltage;
46 }
47 void set_transfer_roller_back_voltage(double voltage) {
48 transfer_roller_back_voltage_ = voltage;
Ravago Jones81e50632022-03-11 16:23:51 -080049 }
Milind Upadhyayd86b02c2022-03-13 20:57:46 -070050 void set_requested_intake(std::optional<RequestedIntake> requested_intake) {
51 requested_intake_ = requested_intake;
52 }
Henry Speiser09e8da92022-03-14 20:58:45 -070053 void set_turret_goal(double turret_goal) {
54 turret_goal_ = turret_goal;
55 }
Ravago Jones81e50632022-03-11 16:23:51 -080056
57 void set_fire_at_will(bool fire) { fire_ = fire; }
Milind Upadhyay803bbf02022-03-11 17:56:26 -080058 void set_preloaded(bool preloaded) { preloaded_ = preloaded; }
Ravago Jones81e50632022-03-11 16:23:51 -080059
60 void SendSuperstructureGoal();
61 void ExtendFrontIntake();
62 void RetractFrontIntake();
63 void ExtendBackIntake();
64 void RetractBackIntake();
65 void SendStartingPosition(const Eigen::Vector3d &start);
66 void MaybeSendStartingPosition();
67
Milind Upadhyay803bbf02022-03-11 17:56:26 -080068 // Tells the superstructure the ball was preloaded and waits until it updates
69 // the state
Milind Upadhyaya7793962022-03-11 19:39:36 -080070 [[nodiscard]] bool WaitForPreloaded();
71 // Waits for a certain number of balls to be shot
72 [[nodiscard]] bool WaitForBallsShot(int num_shot);
Milind Upadhyay803bbf02022-03-11 17:56:26 -080073
Ravago Jones81e50632022-03-11 16:23:51 -080074 void SplineAuto();
Milind Upadhyaya7793962022-03-11 19:39:36 -080075 void RapidReact();
Ravago Jones81e50632022-03-11 16:23:51 -080076
77 void Replan();
78
79 double intake_front_goal_ = 0.0;
80 double intake_back_goal_ = 0.0;
81 double roller_front_voltage_ = 0.0;
82 double roller_back_voltage_ = 0.0;
Milind Upadhyayb1a74ea2022-03-09 20:34:35 -080083 double transfer_roller_front_voltage_ = 0.0;
84 double transfer_roller_back_voltage_ = 0.0;
Milind Upadhyayd86b02c2022-03-13 20:57:46 -070085 std::optional<RequestedIntake> requested_intake_ = std::nullopt;
Henry Speiser09e8da92022-03-14 20:58:45 -070086 double turret_goal_ = 0.0;
Ravago Jones81e50632022-03-11 16:23:51 -080087 bool fire_ = false;
Milind Upadhyay803bbf02022-03-11 17:56:26 -080088 bool preloaded_ = false;
Ravago Jones81e50632022-03-11 16:23:51 -080089
90 aos::Sender<frc971::control_loops::drivetrain::LocalizerControl>
91 localizer_control_sender_;
92 aos::Sender<y2022::control_loops::superstructure::Goal>
93 superstructure_goal_sender_;
94 aos::Fetcher<y2022::control_loops::superstructure::Status>
95 superstructure_status_fetcher_;
96 aos::Fetcher<aos::JoystickState> joystick_state_fetcher_;
97 aos::Fetcher<aos::RobotState> robot_state_fetcher_;
98
99 aos::TimerHandler *replan_timer_;
100 aos::TimerHandler *button_poll_;
101
102 std::optional<SplineHandle> test_spline_;
Henry Speiser09e8da92022-03-14 20:58:45 -0700103 std::optional<std::array<SplineHandle, 3>> rapid_react_splines_;
Ravago Jones81e50632022-03-11 16:23:51 -0800104
105 aos::Alliance alliance_ = aos::Alliance::kInvalid;
106 AutonomousSplines auto_splines_;
107 bool user_indicated_safe_to_reset_ = false;
108 bool sent_starting_position_ = false;
109
110 bool is_planned_ = false;
111
112 std::optional<Eigen::Vector3d> starting_position_;
milind-u086d7262022-01-19 20:44:18 -0800113};
114
115} // namespace actors
116} // namespace y2022
117
118#endif // Y2022_ACTORS_AUTONOMOUS_ACTOR_H_