blob: 2e2463881ed8467125431e791d2e6142e25cdacf [file] [log] [blame]
Comran Morshede68e3732016-03-12 14:12:11 +00001#ifndef Y2016_ACTORS_AUTONOMOUS_ACTOR_H_
2#define Y2016_ACTORS_AUTONOMOUS_ACTOR_H_
3
Austin Schuhf2a50ba2016-12-24 16:16:26 -08004#include <chrono>
Comran Morshede68e3732016-03-12 14:12:11 +00005#include <memory>
6
John Park33858a32018-09-28 23:05:48 -07007#include "aos/actions/actions.h"
8#include "aos/actions/actor.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -07009#include "aos/events/event_loop.h"
Philipp Schrader4bd29b12017-02-22 04:42:27 +000010#include "frc971/autonomous/base_autonomous_actor.h"
Comran Morshed435f1112016-03-12 14:20:45 +000011#include "frc971/control_loops/drivetrain/drivetrain_config.h"
Austin Schuhf2a50ba2016-12-24 16:16:26 -080012#include "y2016/actors/vision_align_actor.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -070013#include "y2016/control_loops/shooter/shooter_goal_generated.h"
14#include "y2016/control_loops/shooter/shooter_status_generated.h"
15#include "y2016/control_loops/superstructure/superstructure_goal_generated.h"
16#include "y2016/control_loops/superstructure/superstructure_status_generated.h"
17#include "y2016/queues/ball_detector_generated.h"
Comran Morshede68e3732016-03-12 14:12:11 +000018
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080019namespace y2016::actors {
Comran Morshede68e3732016-03-12 14:12:11 +000020
Philipp Schrader4bd29b12017-02-22 04:42:27 +000021class AutonomousActor : public ::frc971::autonomous::BaseAutonomousActor {
Comran Morshede68e3732016-03-12 14:12:11 +000022 public:
Austin Schuh1bf8a212019-05-26 22:13:14 -070023 explicit AutonomousActor(::aos::EventLoop *event_loop);
Comran Morshede68e3732016-03-12 14:12:11 +000024
Philipp Schrader4bd29b12017-02-22 04:42:27 +000025 bool RunAction(
Alex Perrycb7da4b2019-08-28 19:35:56 -070026 const ::frc971::autonomous::AutonomousActionParams *params) override;
Comran Morshed435f1112016-03-12 14:20:45 +000027
28 private:
Austin Schuhe4ec49c2016-04-24 19:07:15 -070029 void WaitForBallOrDriveDone();
30
31 void StealAndMoveOverBy(double distance);
Comran Morshed435f1112016-03-12 14:20:45 +000032
Comran Morshedb134e772016-03-16 21:05:05 +000033 // Internal struct holding superstructure goals sent by autonomous to the
34 // loop.
35 struct SuperstructureGoal {
36 double intake;
37 double shoulder;
38 double wrist;
39 };
40 SuperstructureGoal superstructure_goal_;
41
42 void MoveSuperstructure(double intake, double shoulder, double wrist,
Alex Perrycb7da4b2019-08-28 19:35:56 -070043 const frc971::ProfileParametersT intake_params,
44 const frc971::ProfileParametersT shoulder_params,
45 const frc971::ProfileParametersT wrist_params,
Austin Schuh23b21802016-04-03 21:18:56 -070046 bool traverse_up, double roller_power);
Comran Morshedb134e772016-03-16 21:05:05 +000047 void WaitForSuperstructure();
Austin Schuhe4ec49c2016-04-24 19:07:15 -070048 void WaitForSuperstructureProfile();
Austin Schuh23b21802016-04-03 21:18:56 -070049 void WaitForSuperstructureLow();
50 void WaitForIntake();
51 bool IntakeDone();
Austin Schuhf59b8ee2016-03-19 21:31:36 -070052
Austin Schuh3e4a5272016-04-20 20:11:00 -070053 void FrontLongShot();
54 void FrontMiddleShot();
Austin Schuhf59b8ee2016-03-19 21:31:36 -070055 void BackLongShot();
Austin Schuh23b21802016-04-03 21:18:56 -070056 void BackLongShotTwoBall();
Austin Schuhe4ec49c2016-04-24 19:07:15 -070057 void BackLongShotTwoBallFinish();
Austin Schuh23b21802016-04-03 21:18:56 -070058 void BackLongShotLowBarTwoBall();
Austin Schuhf59b8ee2016-03-19 21:31:36 -070059 void BackMiddleShot();
60 void TuckArm(bool arm_down, bool traverse_down);
Austin Schuh23b21802016-04-03 21:18:56 -070061 void OpenShooter();
62 void CloseShooter();
63 void CloseIfBall();
64 bool SuperstructureProfileDone();
65 bool SuperstructureDone();
Austin Schuh3e4a5272016-04-20 20:11:00 -070066 void TippyDrive(double goal_distance, double tip_distance, double below,
67 double above);
Austin Schuhf59b8ee2016-03-19 21:31:36 -070068
Austin Schuh3e4a5272016-04-20 20:11:00 -070069 void DoFullShot();
Austin Schuhf59b8ee2016-03-19 21:31:36 -070070 void LowBarDrive();
71 // Drive to the middle spot over the middle position. Designed for the rock
72 // wall, rough terain, or ramparts.
73 void MiddleDrive();
74
75 void OneFromMiddleDrive(bool left);
76 void TwoFromMiddleDrive();
77
78 double shooter_speed_ = 0.0;
79 void SetShooterSpeed(double speed);
80 void WaitForShooterSpeed();
81 void Shoot();
82
83 void AlignWithVisionGoal();
Austin Schuhf2a50ba2016-12-24 16:16:26 -080084 void WaitForAlignedWithVision(::std::chrono::nanoseconds align_duration);
Austin Schuhf59b8ee2016-03-19 21:31:36 -070085
Austin Schuh3e4a5272016-04-20 20:11:00 -070086 void TwoBallAuto();
87
Austin Schuh1bf8a212019-05-26 22:13:14 -070088 actors::VisionAlignActor::Factory vision_align_actor_factory_;
89 ::std::unique_ptr<::aos::common::actions::Action> vision_action_;
Austin Schuh28bde302019-05-26 22:24:33 -070090
91 ::aos::Fetcher<::y2016::vision::VisionStatus> vision_status_fetcher_;
Austin Schuh4b652c92019-05-27 13:22:27 -070092 ::aos::Fetcher<::y2016::sensors::BallDetector> ball_detector_fetcher_;
Alex Perrycb7da4b2019-08-28 19:35:56 -070093 ::aos::Sender<::y2016::control_loops::shooter::Goal> shooter_goal_sender_;
94 ::aos::Fetcher<::y2016::control_loops::shooter::Status>
Austin Schuhae023fb2019-06-29 17:11:45 -070095 shooter_status_fetcher_;
Alex Perrycb7da4b2019-08-28 19:35:56 -070096 ::aos::Fetcher<::y2016::control_loops::superstructure::Status>
Austin Schuh9481d0d2019-06-29 21:56:17 -070097 superstructure_status_fetcher_;
Alex Perrycb7da4b2019-08-28 19:35:56 -070098 ::aos::Sender<::y2016::control_loops::superstructure::Goal>
Austin Schuh9481d0d2019-06-29 21:56:17 -070099 superstructure_goal_sender_;
Comran Morshede68e3732016-03-12 14:12:11 +0000100};
101
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -0800102} // namespace y2016::actors
Comran Morshede68e3732016-03-12 14:12:11 +0000103
104#endif // Y2016_ACTORS_AUTONOMOUS_ACTOR_H_