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