blob: 8d7baaafb6de24f4a61d4a5348db35985c9d3684 [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 Schuhae023fb2019-06-29 17:11:45 -070014#include "y2016/control_loops/shooter/shooter.q.h"
Austin Schuh9481d0d2019-06-29 21:56:17 -070015#include "y2016/control_loops/superstructure/superstructure.q.h"
Austin Schuh4b652c92019-05-27 13:22:27 -070016#include "y2016/queues/ball_detector.q.h"
Comran Morshede68e3732016-03-12 14:12:11 +000017
18namespace y2016 {
19namespace actors {
Comran Morshedb134e772016-03-16 21:05:05 +000020using ::frc971::ProfileParameters;
Comran Morshede68e3732016-03-12 14:12:11 +000021
Philipp Schrader4bd29b12017-02-22 04:42:27 +000022class AutonomousActor : public ::frc971::autonomous::BaseAutonomousActor {
Comran Morshede68e3732016-03-12 14:12:11 +000023 public:
Austin Schuh1bf8a212019-05-26 22:13:14 -070024 explicit AutonomousActor(::aos::EventLoop *event_loop);
Comran Morshede68e3732016-03-12 14:12:11 +000025
Philipp Schrader4bd29b12017-02-22 04:42:27 +000026 bool RunAction(
27 const ::frc971::autonomous::AutonomousActionParams &params) override;
Comran Morshed435f1112016-03-12 14:20:45 +000028
29 private:
Austin Schuhe4ec49c2016-04-24 19:07:15 -070030 void WaitForBallOrDriveDone();
31
32 void StealAndMoveOverBy(double distance);
Comran Morshed435f1112016-03-12 14:20:45 +000033
Comran Morshedb134e772016-03-16 21:05:05 +000034 // Internal struct holding superstructure goals sent by autonomous to the
35 // loop.
36 struct SuperstructureGoal {
37 double intake;
38 double shoulder;
39 double wrist;
40 };
41 SuperstructureGoal superstructure_goal_;
42
43 void MoveSuperstructure(double intake, double shoulder, double wrist,
44 const ProfileParameters intake_params,
45 const ProfileParameters shoulder_params,
Austin Schuhf59b8ee2016-03-19 21:31:36 -070046 const ProfileParameters wrist_params,
Austin Schuh23b21802016-04-03 21:18:56 -070047 bool traverse_up, double roller_power);
Comran Morshedb134e772016-03-16 21:05:05 +000048 void WaitForSuperstructure();
Austin Schuhe4ec49c2016-04-24 19:07:15 -070049 void WaitForSuperstructureProfile();
Austin Schuh23b21802016-04-03 21:18:56 -070050 void WaitForSuperstructureLow();
51 void WaitForIntake();
52 bool IntakeDone();
Austin Schuhf59b8ee2016-03-19 21:31:36 -070053
Austin Schuh3e4a5272016-04-20 20:11:00 -070054 void FrontLongShot();
55 void FrontMiddleShot();
Austin Schuhf59b8ee2016-03-19 21:31:36 -070056 void BackLongShot();
Austin Schuh23b21802016-04-03 21:18:56 -070057 void BackLongShotTwoBall();
Austin Schuhe4ec49c2016-04-24 19:07:15 -070058 void BackLongShotTwoBallFinish();
Austin Schuh23b21802016-04-03 21:18:56 -070059 void BackLongShotLowBarTwoBall();
Austin Schuhf59b8ee2016-03-19 21:31:36 -070060 void BackMiddleShot();
61 void TuckArm(bool arm_down, bool traverse_down);
Austin Schuh23b21802016-04-03 21:18:56 -070062 void OpenShooter();
63 void CloseShooter();
64 void CloseIfBall();
65 bool SuperstructureProfileDone();
66 bool SuperstructureDone();
Austin Schuh3e4a5272016-04-20 20:11:00 -070067 void TippyDrive(double goal_distance, double tip_distance, double below,
68 double above);
Austin Schuhf59b8ee2016-03-19 21:31:36 -070069
Austin Schuh3e4a5272016-04-20 20:11:00 -070070 void DoFullShot();
Austin Schuhf59b8ee2016-03-19 21:31:36 -070071 void LowBarDrive();
72 // Drive to the middle spot over the middle position. Designed for the rock
73 // wall, rough terain, or ramparts.
74 void MiddleDrive();
75
76 void OneFromMiddleDrive(bool left);
77 void TwoFromMiddleDrive();
78
79 double shooter_speed_ = 0.0;
80 void SetShooterSpeed(double speed);
81 void WaitForShooterSpeed();
82 void Shoot();
83
84 void AlignWithVisionGoal();
Austin Schuhf2a50ba2016-12-24 16:16:26 -080085 void WaitForAlignedWithVision(::std::chrono::nanoseconds align_duration);
Austin Schuhf59b8ee2016-03-19 21:31:36 -070086
Austin Schuh3e4a5272016-04-20 20:11:00 -070087 void TwoBallAuto();
88
Austin Schuh1bf8a212019-05-26 22:13:14 -070089 actors::VisionAlignActor::Factory vision_align_actor_factory_;
90 ::std::unique_ptr<::aos::common::actions::Action> vision_action_;
Austin Schuh28bde302019-05-26 22:24:33 -070091
92 ::aos::Fetcher<::y2016::vision::VisionStatus> vision_status_fetcher_;
Austin Schuh4b652c92019-05-27 13:22:27 -070093 ::aos::Fetcher<::y2016::sensors::BallDetector> ball_detector_fetcher_;
Austin Schuhae023fb2019-06-29 17:11:45 -070094 ::aos::Sender<::y2016::control_loops::shooter::ShooterQueue::Goal>
95 shooter_goal_sender_;
96 ::aos::Fetcher<::y2016::control_loops::shooter::ShooterQueue::Status>
97 shooter_status_fetcher_;
Austin Schuh9481d0d2019-06-29 21:56:17 -070098 ::aos::Fetcher<::y2016::control_loops::SuperstructureQueue::Status>
99 superstructure_status_fetcher_;
100 ::aos::Sender<::y2016::control_loops::SuperstructureQueue::Goal>
101 superstructure_goal_sender_;
Comran Morshede68e3732016-03-12 14:12:11 +0000102};
103
Comran Morshede68e3732016-03-12 14:12:11 +0000104} // namespace actors
105} // namespace y2016
106
107#endif // Y2016_ACTORS_AUTONOMOUS_ACTOR_H_