blob: 46c8a78a0e740c2c228c4b9aa2fb43baa9ce85be [file] [log] [blame]
Maxwell Henderson64f37452023-03-11 13:39:21 -08001#ifndef Y2023_AUTONOMOUS_AUTONOMOUS_ACTOR_H_
2#define Y2023_AUTONOMOUS_AUTONOMOUS_ACTOR_H_
Maxwell Hendersonad312342023-01-10 12:07:47 -08003
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 Kuszmaul713c5ce2023-03-04 18:23:24 -08009#include "frc971/control_loops/drivetrain/localizer_generated.h"
10#include "y2023/autonomous/auto_splines.h"
Maxwell Henderson64f37452023-03-11 13:39:21 -080011#include "y2023/control_loops/superstructure/superstructure_goal_generated.h"
12#include "y2023/control_loops/superstructure/superstructure_status_generated.h"
Maxwell Hendersonad312342023-01-10 12:07:47 -080013
14namespace y2023 {
Maxwell Henderson64f37452023-03-11 13:39:21 -080015namespace autonomous {
Maxwell Hendersonad312342023-01-10 12:07:47 -080016
17class AutonomousActor : public ::frc971::autonomous::BaseAutonomousActor {
18 public:
19 explicit AutonomousActor(::aos::EventLoop *event_loop);
20
21 bool RunAction(
22 const ::frc971::autonomous::AutonomousActionParams *params) override;
23
24 private:
Maxwell Henderson64f37452023-03-11 13:39:21 -080025 void set_arm_goal_position(uint32_t requested_arm_goal_position) {
26 arm_goal_position_ = requested_arm_goal_position;
27 }
28
29 void set_roller_goal(
30 control_loops::superstructure::RollerGoal requested_roller_goal) {
31 roller_goal_ = requested_roller_goal;
32 }
33
34 void set_wrist_goal(double requested_wrist_goal) {
35 wrist_goal_ = requested_wrist_goal;
36 }
37
38 void set_preloaded(bool preloaded) { preloaded_ = preloaded; }
39
40 void SendSuperstructureGoal();
41 void HighCubeScore();
42 void MidCubeScore();
43 void MidConeScore();
Maxwell Henderson3d0beaf2023-03-23 11:32:44 -070044 void Neutral();
Maxwell Henderson64f37452023-03-11 13:39:21 -080045 void PickupCube();
46 void Spit();
Maxwell Henderson3d0beaf2023-03-23 11:32:44 -070047 void StopSpitting();
Maxwell Henderson64f37452023-03-11 13:39:21 -080048 void IntakeCube();
Maxwell Henderson3d0beaf2023-03-23 11:32:44 -070049 void Balance();
Maxwell Henderson64f37452023-03-11 13:39:21 -080050
Maxwell Henderson3d0beaf2023-03-23 11:32:44 -070051 [[nodiscard]] bool WaitForArmGoal(double distance_to_go = 0.01);
Maxwell Henderson64f37452023-03-11 13:39:21 -080052
53 [[nodiscard]] bool WaitForPreloaded();
54
Maxwell Hendersonad312342023-01-10 12:07:47 -080055 void Reset();
James Kuszmaul713c5ce2023-03-04 18:23:24 -080056
57 void SendStartingPosition(const Eigen::Vector3d &start);
58 void MaybeSendStartingPosition();
59 void SplineAuto();
Maxwell Henderson64f37452023-03-11 13:39:21 -080060 void ChargedUp();
James Kuszmaul713c5ce2023-03-04 18:23:24 -080061 void Replan();
62
63 aos::Sender<frc971::control_loops::drivetrain::LocalizerControl>
64 localizer_control_sender_;
65 aos::Fetcher<aos::JoystickState> joystick_state_fetcher_;
66 aos::Fetcher<aos::RobotState> robot_state_fetcher_;
67
Maxwell Henderson3d0beaf2023-03-23 11:32:44 -070068 double wrist_goal_;
Maxwell Henderson64f37452023-03-11 13:39:21 -080069 control_loops::superstructure::RollerGoal roller_goal_ =
70 control_loops::superstructure::RollerGoal::IDLE;
71
James Kuszmaul713c5ce2023-03-04 18:23:24 -080072 aos::TimerHandler *replan_timer_;
73 aos::TimerHandler *button_poll_;
74
James Kuszmaul713c5ce2023-03-04 18:23:24 -080075 aos::Alliance alliance_ = aos::Alliance::kInvalid;
76 AutonomousSplines auto_splines_;
77 bool user_indicated_safe_to_reset_ = false;
78 bool sent_starting_position_ = false;
79
80 bool is_planned_ = false;
81
82 std::optional<Eigen::Vector3d> starting_position_;
Maxwell Henderson64f37452023-03-11 13:39:21 -080083
84 uint32_t arm_goal_position_;
85 bool preloaded_ = false;
86
87 aos::Sender<control_loops::superstructure::Goal> superstructure_goal_sender_;
88 aos::Fetcher<y2023::control_loops::superstructure::Status>
89 superstructure_status_fetcher_;
90
91 std::optional<SplineHandle> test_spline_;
Maxwell Henderson3d0beaf2023-03-23 11:32:44 -070092 std::optional<std::array<SplineHandle, 4>> charged_up_splines_;
Maxwell Henderson64f37452023-03-11 13:39:21 -080093
94 // List of arm angles from arm::PointsList
95 const ::std::vector<::Eigen::Matrix<double, 3, 1>> points_;
Maxwell Hendersonad312342023-01-10 12:07:47 -080096};
97
Maxwell Henderson64f37452023-03-11 13:39:21 -080098} // namespace autonomous
Maxwell Hendersonad312342023-01-10 12:07:47 -080099} // namespace y2023
100
Maxwell Henderson64f37452023-03-11 13:39:21 -0800101#endif // Y2023_AUTONOMOUS_AUTONOMOUS_ACTOR_H_