Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 1 | #ifndef y2020_ACTORS_AUTONOMOUS_ACTOR_H_ |
| 2 | #define y2020_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" |
James Kuszmaul | 5f6d1d4 | 2020-03-01 18:10:07 -0800 | [diff] [blame] | 9 | #include "frc971/control_loops/drivetrain/localizer_generated.h" |
Ravago Jones | c2a0802 | 2021-02-06 17:40:54 -0800 | [diff] [blame] | 10 | #include "y2020/actors/auto_splines.h" |
Sabina Leaver | a0b43b4 | 2021-03-03 20:30:04 -0800 | [diff] [blame] | 11 | #include "y2020/control_loops/superstructure/superstructure_goal_generated.h" |
| 12 | #include "y2020/control_loops/superstructure/superstructure_status_generated.h" |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 13 | |
| 14 | namespace y2020 { |
| 15 | namespace actors { |
| 16 | |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 17 | using frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal; |
Sabina Leaver | a0b43b4 | 2021-03-03 20:30:04 -0800 | [diff] [blame] | 18 | |
| 19 | namespace superstructure = y2020::control_loops::superstructure; |
| 20 | |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 21 | class AutonomousActor : public frc971::autonomous::BaseAutonomousActor { |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 22 | public: |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 23 | explicit AutonomousActor(aos::EventLoop *event_loop); |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 24 | |
| 25 | bool RunAction( |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 26 | const frc971::autonomous::AutonomousActionParams *params) override; |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 27 | |
| 28 | private: |
| 29 | void Reset(); |
Sabina Leaver | a0b43b4 | 2021-03-03 20:30:04 -0800 | [diff] [blame] | 30 | |
| 31 | void set_intake_goal(double intake_goal) { intake_goal_ = intake_goal; } |
Austin Schuh | d0e9e06 | 2021-10-24 17:40:58 -0700 | [diff] [blame] | 32 | void set_roller(bool roller) { |
| 33 | if (roller) { |
| 34 | roller_voltage_ = 6.0; |
| 35 | } else { |
| 36 | roller_voltage_ = 0.0; |
| 37 | } |
Ravago Jones | f8b7bfe | 2021-10-09 16:25:29 -0700 | [diff] [blame] | 38 | } |
Sabina Leaver | a0b43b4 | 2021-03-03 20:30:04 -0800 | [diff] [blame] | 39 | void set_roller_voltage(double roller_voltage) { |
| 40 | roller_voltage_ = roller_voltage; |
| 41 | } |
Ravago Jones | a7b3c82 | 2021-08-26 12:36:03 -0700 | [diff] [blame] | 42 | void set_shooter_tracking(bool shooter_tracking) { |
| 43 | shooter_tracking_ = shooter_tracking; |
| 44 | } |
| 45 | void set_shooting(bool shooting) { shooting_ = shooting; } |
milind-u | 0e20378 | 2021-10-30 21:57:20 -0700 | [diff] [blame] | 46 | void set_preloading(bool preloading) { preloading_ = preloading; } |
Sabina Leaver | 8302e3c | 2021-03-20 16:36:05 -0700 | [diff] [blame] | 47 | |
Sabina Leaver | a0b43b4 | 2021-03-03 20:30:04 -0800 | [diff] [blame] | 48 | void SendSuperstructureGoal(); |
Ravago Jones | a7b3c82 | 2021-08-26 12:36:03 -0700 | [diff] [blame] | 49 | void ExtendIntake(); |
milind upadhyay | 5e589d7 | 2021-03-27 13:47:18 -0700 | [diff] [blame] | 50 | void RetractIntake(); |
milind upadhyay | 47a0ab3 | 2020-11-25 19:34:41 -0800 | [diff] [blame] | 51 | void SplineAuto(); |
Austin Schuh | 3653cf2 | 2021-11-12 11:54:51 -0800 | [diff] [blame] | 52 | void Fender(); |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 53 | void SendStartingPosition(const Eigen::Vector3d &start); |
Ravago Jones | a7b3c82 | 2021-08-26 12:36:03 -0700 | [diff] [blame] | 54 | void TargetAligned(); |
| 55 | void TargetOffset(); |
| 56 | void JustShoot(); |
milind upadhyay | 47a0ab3 | 2020-11-25 19:34:41 -0800 | [diff] [blame] | 57 | bool DriveFwd(); |
Ravago Jones | 1f32d62 | 2021-08-26 12:20:36 -0700 | [diff] [blame] | 58 | bool WaitForBallsShot(int num_shot); |
Austin Schuh | d0e9e06 | 2021-10-24 17:40:58 -0700 | [diff] [blame] | 59 | int Balls(); |
| 60 | bool WaitUntilAbsoluteBallsShot(int absolute_balls); |
James Kuszmaul | 5f6d1d4 | 2020-03-01 18:10:07 -0800 | [diff] [blame] | 61 | |
James Kuszmaul | 4303a5d | 2021-10-23 19:58:48 -0700 | [diff] [blame] | 62 | void MaybeSendStartingPosition(); |
| 63 | |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 64 | void Replan(); |
| 65 | |
Austin Schuh | 3653cf2 | 2021-11-12 11:54:51 -0800 | [diff] [blame] | 66 | bool practice_robot_ = false; |
| 67 | |
Sabina Leaver | a0b43b4 | 2021-03-03 20:30:04 -0800 | [diff] [blame] | 68 | double intake_goal_ = 0.0; |
| 69 | double roller_voltage_ = 0.0; |
Ravago Jones | a7b3c82 | 2021-08-26 12:36:03 -0700 | [diff] [blame] | 70 | bool shooting_ = false; |
milind-u | 0e20378 | 2021-10-30 21:57:20 -0700 | [diff] [blame] | 71 | bool preloading_ = true; |
Austin Schuh | d0e9e06 | 2021-10-24 17:40:58 -0700 | [diff] [blame] | 72 | bool shooter_tracking_ = true; |
Sabina Leaver | a0b43b4 | 2021-03-03 20:30:04 -0800 | [diff] [blame] | 73 | const float kRollerSpeedCompensation = 2.0; |
| 74 | |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 75 | aos::Sender<frc971::control_loops::drivetrain::LocalizerControl> |
James Kuszmaul | 5f6d1d4 | 2020-03-01 18:10:07 -0800 | [diff] [blame] | 76 | localizer_control_sender_; |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 77 | aos::Sender<y2020::control_loops::superstructure::Goal> |
Sabina Leaver | a0b43b4 | 2021-03-03 20:30:04 -0800 | [diff] [blame] | 78 | superstructure_goal_sender_; |
Ravago Jones | 1f32d62 | 2021-08-26 12:20:36 -0700 | [diff] [blame] | 79 | aos::Fetcher<y2020::control_loops::superstructure::Status> |
| 80 | superstructure_status_fetcher_; |
Austin Schuh | ba77b7e | 2021-10-25 21:58:54 -0700 | [diff] [blame] | 81 | aos::Fetcher<aos::JoystickState> joystick_state_fetcher_; |
| 82 | aos::Fetcher<aos::RobotState> robot_state_fetcher_; |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 83 | |
| 84 | aos::TimerHandler *replan_timer_; |
Austin Schuh | ba77b7e | 2021-10-25 21:58:54 -0700 | [diff] [blame] | 85 | aos::TimerHandler *button_poll_; |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 86 | |
Ravago Jones | a7b3c82 | 2021-08-26 12:36:03 -0700 | [diff] [blame] | 87 | std::optional<std::array<SplineHandle, 2>> target_offset_splines_; |
milind-u | 0e20378 | 2021-10-30 21:57:20 -0700 | [diff] [blame] | 88 | // Max number of splines is 5 |
| 89 | std::optional<std::array<SplineHandle, 3>> target_aligned_splines_; |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 90 | |
Austin Schuh | 3653cf2 | 2021-11-12 11:54:51 -0800 | [diff] [blame] | 91 | std::optional<std::array<SplineHandle, 1>> fender_splines_; |
| 92 | |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 93 | std::optional<SplineHandle> barrel_spline_; |
| 94 | std::optional<SplineHandle> slalom_spline_; |
| 95 | std::optional<SplineHandle> test_spline_; |
| 96 | |
James Kuszmaul | ddd2ba6 | 2020-03-08 22:17:13 -0700 | [diff] [blame] | 97 | aos::Alliance alliance_ = aos::Alliance::kInvalid; |
Ravago Jones | c2a0802 | 2021-02-06 17:40:54 -0800 | [diff] [blame] | 98 | AutonomousSplines auto_splines_; |
James Kuszmaul | 4303a5d | 2021-10-23 19:58:48 -0700 | [diff] [blame] | 99 | bool user_indicated_safe_to_reset_ = false; |
| 100 | bool sent_starting_position_ = false; |
| 101 | |
James Kuszmaul | ead4da6 | 2021-10-24 17:36:54 -0700 | [diff] [blame] | 102 | bool is_planned_ = false; |
| 103 | |
James Kuszmaul | 4303a5d | 2021-10-23 19:58:48 -0700 | [diff] [blame] | 104 | std::optional<Eigen::Vector3d> starting_position_; |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | } // namespace actors |
| 108 | } // namespace y2020 |
| 109 | |
| 110 | #endif // y2020_ACTORS_AUTONOMOUS_ACTOR_H_ |