milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 1 | #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 Jones | 81e5063 | 2022-03-11 16:23:51 -0800 | [diff] [blame] | 9 | #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-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 13 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame] | 14 | namespace y2022::actors { |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 15 | |
Milind Upadhyay | d86b02c | 2022-03-13 20:57:46 -0700 | [diff] [blame] | 16 | using control_loops::superstructure::RequestedIntake; |
Ravago Jones | 81e5063 | 2022-03-11 16:23:51 -0800 | [diff] [blame] | 17 | using frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal; |
| 18 | |
| 19 | namespace superstructure = y2022::control_loops::superstructure; |
| 20 | |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 21 | class 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 Jones | 81e5063 | 2022-03-11 16:23:51 -0800 | [diff] [blame] | 30 | |
| 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 | } |
Milind Upadhyay | 29dcc17 | 2022-04-02 19:21:30 -0700 | [diff] [blame] | 43 | void set_transfer_roller_voltage(double voltage) { |
| 44 | transfer_roller_voltage_ = voltage; |
Ravago Jones | 81e5063 | 2022-03-11 16:23:51 -0800 | [diff] [blame] | 45 | } |
Milind Upadhyay | d86b02c | 2022-03-13 20:57:46 -0700 | [diff] [blame] | 46 | void set_requested_intake(std::optional<RequestedIntake> requested_intake) { |
| 47 | requested_intake_ = requested_intake; |
| 48 | } |
Ravago Jones | 81e5063 | 2022-03-11 16:23:51 -0800 | [diff] [blame] | 49 | |
| 50 | void set_fire_at_will(bool fire) { fire_ = fire; } |
Milind Upadhyay | 803bbf0 | 2022-03-11 17:56:26 -0800 | [diff] [blame] | 51 | void set_preloaded(bool preloaded) { preloaded_ = preloaded; } |
Ravago Jones | 81e5063 | 2022-03-11 16:23:51 -0800 | [diff] [blame] | 52 | |
| 53 | void SendSuperstructureGoal(); |
| 54 | void ExtendFrontIntake(); |
| 55 | void RetractFrontIntake(); |
| 56 | void ExtendBackIntake(); |
| 57 | void RetractBackIntake(); |
| 58 | void SendStartingPosition(const Eigen::Vector3d &start); |
| 59 | void MaybeSendStartingPosition(); |
| 60 | |
Milind Upadhyay | 803bbf0 | 2022-03-11 17:56:26 -0800 | [diff] [blame] | 61 | // Tells the superstructure the ball was preloaded and waits until it updates |
| 62 | // the state |
Milind Upadhyay | a779396 | 2022-03-11 19:39:36 -0800 | [diff] [blame] | 63 | [[nodiscard]] bool WaitForPreloaded(); |
Milind Upadhyay | f35bb11 | 2022-03-16 23:08:04 -0700 | [diff] [blame] | 64 | // Waits for the intaked balls to be shot |
| 65 | [[nodiscard]] bool WaitForBallsShot(); |
Milind Upadhyay | 803bbf0 | 2022-03-11 17:56:26 -0800 | [diff] [blame] | 66 | |
Ravago Jones | 81e5063 | 2022-03-11 16:23:51 -0800 | [diff] [blame] | 67 | void SplineAuto(); |
Milind Upadhyay | a779396 | 2022-03-11 19:39:36 -0800 | [diff] [blame] | 68 | void RapidReact(); |
Henry Speiser | 5eed1de | 2022-04-07 21:52:10 -0700 | [diff] [blame] | 69 | void RapidReactTwo(); |
Ravago Jones | 81e5063 | 2022-03-11 16:23:51 -0800 | [diff] [blame] | 70 | |
| 71 | void Replan(); |
| 72 | |
| 73 | double intake_front_goal_ = 0.0; |
| 74 | double intake_back_goal_ = 0.0; |
| 75 | double roller_front_voltage_ = 0.0; |
| 76 | double roller_back_voltage_ = 0.0; |
Milind Upadhyay | 29dcc17 | 2022-04-02 19:21:30 -0700 | [diff] [blame] | 77 | double transfer_roller_voltage_ = 0.0; |
Milind Upadhyay | d86b02c | 2022-03-13 20:57:46 -0700 | [diff] [blame] | 78 | std::optional<RequestedIntake> requested_intake_ = std::nullopt; |
Ravago Jones | 81e5063 | 2022-03-11 16:23:51 -0800 | [diff] [blame] | 79 | bool fire_ = false; |
Milind Upadhyay | 803bbf0 | 2022-03-11 17:56:26 -0800 | [diff] [blame] | 80 | bool preloaded_ = false; |
Ravago Jones | 81e5063 | 2022-03-11 16:23:51 -0800 | [diff] [blame] | 81 | |
| 82 | aos::Sender<frc971::control_loops::drivetrain::LocalizerControl> |
| 83 | localizer_control_sender_; |
| 84 | aos::Sender<y2022::control_loops::superstructure::Goal> |
| 85 | superstructure_goal_sender_; |
| 86 | aos::Fetcher<y2022::control_loops::superstructure::Status> |
| 87 | superstructure_status_fetcher_; |
| 88 | aos::Fetcher<aos::JoystickState> joystick_state_fetcher_; |
| 89 | aos::Fetcher<aos::RobotState> robot_state_fetcher_; |
| 90 | |
| 91 | aos::TimerHandler *replan_timer_; |
| 92 | aos::TimerHandler *button_poll_; |
| 93 | |
| 94 | std::optional<SplineHandle> test_spline_; |
Henry Speiser | 09e8da9 | 2022-03-14 20:58:45 -0700 | [diff] [blame] | 95 | std::optional<std::array<SplineHandle, 3>> rapid_react_splines_; |
Austin Schuh | f3413b7 | 2022-04-16 19:09:33 -0700 | [diff] [blame] | 96 | std::optional<std::array<SplineHandle, 2>> rapid_react_two_spline_; |
Ravago Jones | 81e5063 | 2022-03-11 16:23:51 -0800 | [diff] [blame] | 97 | |
| 98 | aos::Alliance alliance_ = aos::Alliance::kInvalid; |
| 99 | AutonomousSplines auto_splines_; |
| 100 | bool user_indicated_safe_to_reset_ = false; |
| 101 | bool sent_starting_position_ = false; |
| 102 | |
| 103 | bool is_planned_ = false; |
| 104 | |
| 105 | std::optional<Eigen::Vector3d> starting_position_; |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 106 | }; |
| 107 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame] | 108 | } // namespace y2022::actors |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 109 | |
| 110 | #endif // Y2022_ACTORS_AUTONOMOUS_ACTOR_H_ |