blob: 22d963d1524a1ba9db482f1248ba112d6c709c2a [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"
Austin Schuheb99d072019-05-12 21:03:38 -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.q.h"
12#include "frc971/control_loops/drivetrain/drivetrain_config.h"
Austin Schuhf2a50ba2016-12-24 16:16:26 -080013#include "y2016/actors/vision_align_actor.h"
Austin Schuh4b652c92019-05-27 13:22:27 -070014#include "y2016/queues/ball_detector.q.h"
Comran Morshede68e3732016-03-12 14:12:11 +000015
16namespace y2016 {
17namespace actors {
Comran Morshedb134e772016-03-16 21:05:05 +000018using ::frc971::ProfileParameters;
Comran Morshede68e3732016-03-12 14:12:11 +000019
Philipp Schrader4bd29b12017-02-22 04:42:27 +000020class AutonomousActor : public ::frc971::autonomous::BaseAutonomousActor {
Comran Morshede68e3732016-03-12 14:12:11 +000021 public:
Austin Schuh1bf8a212019-05-26 22:13:14 -070022 explicit AutonomousActor(::aos::EventLoop *event_loop);
Comran Morshede68e3732016-03-12 14:12:11 +000023
Philipp Schrader4bd29b12017-02-22 04:42:27 +000024 bool RunAction(
25 const ::frc971::autonomous::AutonomousActionParams &params) override;
Comran Morshed435f1112016-03-12 14:20:45 +000026
27 private:
Austin Schuhe4ec49c2016-04-24 19:07:15 -070028 void WaitForBallOrDriveDone();
29
30 void StealAndMoveOverBy(double distance);
Comran Morshed435f1112016-03-12 14:20:45 +000031
Comran Morshedb134e772016-03-16 21:05:05 +000032 // Internal struct holding superstructure goals sent by autonomous to the
33 // loop.
34 struct SuperstructureGoal {
35 double intake;
36 double shoulder;
37 double wrist;
38 };
39 SuperstructureGoal superstructure_goal_;
40
41 void MoveSuperstructure(double intake, double shoulder, double wrist,
42 const ProfileParameters intake_params,
43 const ProfileParameters shoulder_params,
Austin Schuhf59b8ee2016-03-19 21:31:36 -070044 const ProfileParameters wrist_params,
Austin Schuh23b21802016-04-03 21:18:56 -070045 bool traverse_up, double roller_power);
Comran Morshedb134e772016-03-16 21:05:05 +000046 void WaitForSuperstructure();
Austin Schuhe4ec49c2016-04-24 19:07:15 -070047 void WaitForSuperstructureProfile();
Austin Schuh23b21802016-04-03 21:18:56 -070048 void WaitForSuperstructureLow();
49 void WaitForIntake();
50 bool IntakeDone();
Austin Schuhf59b8ee2016-03-19 21:31:36 -070051
Austin Schuh3e4a5272016-04-20 20:11:00 -070052 void FrontLongShot();
53 void FrontMiddleShot();
Austin Schuhf59b8ee2016-03-19 21:31:36 -070054 void BackLongShot();
Austin Schuh23b21802016-04-03 21:18:56 -070055 void BackLongShotTwoBall();
Austin Schuhe4ec49c2016-04-24 19:07:15 -070056 void BackLongShotTwoBallFinish();
Austin Schuh23b21802016-04-03 21:18:56 -070057 void BackLongShotLowBarTwoBall();
Austin Schuhf59b8ee2016-03-19 21:31:36 -070058 void BackMiddleShot();
59 void TuckArm(bool arm_down, bool traverse_down);
Austin Schuh23b21802016-04-03 21:18:56 -070060 void OpenShooter();
61 void CloseShooter();
62 void CloseIfBall();
63 bool SuperstructureProfileDone();
64 bool SuperstructureDone();
Austin Schuh3e4a5272016-04-20 20:11:00 -070065 void TippyDrive(double goal_distance, double tip_distance, double below,
66 double above);
Austin Schuhf59b8ee2016-03-19 21:31:36 -070067
Austin Schuh3e4a5272016-04-20 20:11:00 -070068 void DoFullShot();
Austin Schuhf59b8ee2016-03-19 21:31:36 -070069 void LowBarDrive();
70 // Drive to the middle spot over the middle position. Designed for the rock
71 // wall, rough terain, or ramparts.
72 void MiddleDrive();
73
74 void OneFromMiddleDrive(bool left);
75 void TwoFromMiddleDrive();
76
77 double shooter_speed_ = 0.0;
78 void SetShooterSpeed(double speed);
79 void WaitForShooterSpeed();
80 void Shoot();
81
82 void AlignWithVisionGoal();
Austin Schuhf2a50ba2016-12-24 16:16:26 -080083 void WaitForAlignedWithVision(::std::chrono::nanoseconds align_duration);
Austin Schuhf59b8ee2016-03-19 21:31:36 -070084
Austin Schuh3e4a5272016-04-20 20:11:00 -070085 void TwoBallAuto();
86
Austin Schuh1bf8a212019-05-26 22:13:14 -070087 actors::VisionAlignActor::Factory vision_align_actor_factory_;
88 ::std::unique_ptr<::aos::common::actions::Action> vision_action_;
Austin Schuh28bde302019-05-26 22:24:33 -070089
90 ::aos::Fetcher<::y2016::vision::VisionStatus> vision_status_fetcher_;
Austin Schuh4b652c92019-05-27 13:22:27 -070091 ::aos::Fetcher<::y2016::sensors::BallDetector> ball_detector_fetcher_;
Comran Morshede68e3732016-03-12 14:12:11 +000092};
93
Comran Morshede68e3732016-03-12 14:12:11 +000094} // namespace actors
95} // namespace y2016
96
97#endif // Y2016_ACTORS_AUTONOMOUS_ACTOR_H_