blob: 9a26731c8b3850ad9d41139e3127dbdfc25983d5 [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
4#include <memory>
5
6#include "aos/common/actions/actor.h"
7#include "aos/common/actions/actions.h"
Comran Morshed435f1112016-03-12 14:20:45 +00008
Comran Morshede68e3732016-03-12 14:12:11 +00009#include "y2016/actors/autonomous_action.q.h"
Austin Schuhf59b8ee2016-03-19 21:31:36 -070010#include "y2016/actors/vision_align_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"
Comran Morshede68e3732016-03-12 14:12:11 +000013
14namespace y2016 {
15namespace actors {
Comran Morshedb134e772016-03-16 21:05:05 +000016using ::frc971::ProfileParameters;
Comran Morshede68e3732016-03-12 14:12:11 +000017
18class AutonomousActor
19 : public ::aos::common::actions::ActorBase<AutonomousActionQueueGroup> {
20 public:
21 explicit AutonomousActor(AutonomousActionQueueGroup *s);
22
23 bool RunAction(const actors::AutonomousActionParams &params) override;
Comran Morshed435f1112016-03-12 14:20:45 +000024
25 private:
26 void ResetDrivetrain();
27 void InitializeEncoders();
28 void WaitUntilDoneOrCanceled(::std::unique_ptr<aos::common::actions::Action>
29 action);
30 void StartDrive(double distance, double angle,
Austin Schuhedbb64f2016-03-19 01:18:09 -070031 ::frc971::ProfileParameters linear,
32 ::frc971::ProfileParameters angular);
Comran Morshed435f1112016-03-12 14:20:45 +000033 // Waits for the drive motion to finish. Returns true if it succeeded, and
34 // false if it cancels.
35 bool WaitForDriveDone();
Austin Schuhe4ec49c2016-04-24 19:07:15 -070036 void WaitForBallOrDriveDone();
37
38 void StealAndMoveOverBy(double distance);
Comran Morshed435f1112016-03-12 14:20:45 +000039
Austin Schuh3e4a5272016-04-20 20:11:00 -070040 // Returns true if the drive has finished.
41 bool IsDriveDone();
42 // Waits until the robot is pitched up above the specified angle, or the move
43 // finishes. Returns true on success, and false if it cancels.
44 bool WaitForAboveAngle(double angle);
45 bool WaitForBelowAngle(double angle);
46 bool WaitForMaxBy(double angle);
47
Austin Schuhf59b8ee2016-03-19 21:31:36 -070048 // Waits until the profile and distance is within distance and angle of the
49 // goal. Returns true on success, and false when canceled.
50 bool WaitForDriveNear(double distance, double angle);
51
Comran Morshed435f1112016-03-12 14:20:45 +000052 const ::frc971::control_loops::drivetrain::DrivetrainConfig dt_config_;
Comran Morshedb134e772016-03-16 21:05:05 +000053
54 // Initial drivetrain positions.
55 struct InitialDrivetrain {
56 double left;
57 double right;
58 };
59 InitialDrivetrain initial_drivetrain_;
60
61 // Internal struct holding superstructure goals sent by autonomous to the
62 // loop.
63 struct SuperstructureGoal {
64 double intake;
65 double shoulder;
66 double wrist;
67 };
68 SuperstructureGoal superstructure_goal_;
69
70 void MoveSuperstructure(double intake, double shoulder, double wrist,
71 const ProfileParameters intake_params,
72 const ProfileParameters shoulder_params,
Austin Schuhf59b8ee2016-03-19 21:31:36 -070073 const ProfileParameters wrist_params,
Austin Schuh23b21802016-04-03 21:18:56 -070074 bool traverse_up, double roller_power);
Comran Morshedb134e772016-03-16 21:05:05 +000075 void WaitForSuperstructure();
Austin Schuhe4ec49c2016-04-24 19:07:15 -070076 void WaitForSuperstructureProfile();
Austin Schuh23b21802016-04-03 21:18:56 -070077 void WaitForSuperstructureLow();
78 void WaitForIntake();
79 bool IntakeDone();
80 bool WaitForDriveProfileDone();
Austin Schuhf59b8ee2016-03-19 21:31:36 -070081
Austin Schuh3e4a5272016-04-20 20:11:00 -070082 void FrontLongShot();
83 void FrontMiddleShot();
Austin Schuhf59b8ee2016-03-19 21:31:36 -070084 void BackLongShot();
Austin Schuh23b21802016-04-03 21:18:56 -070085 void BackLongShotTwoBall();
Austin Schuhe4ec49c2016-04-24 19:07:15 -070086 void BackLongShotTwoBallFinish();
Austin Schuh23b21802016-04-03 21:18:56 -070087 void BackLongShotLowBarTwoBall();
Austin Schuhf59b8ee2016-03-19 21:31:36 -070088 void BackMiddleShot();
Austin Schuh23b21802016-04-03 21:18:56 -070089 void WaitForBall();
Austin Schuhf59b8ee2016-03-19 21:31:36 -070090 void TuckArm(bool arm_down, bool traverse_down);
Austin Schuh23b21802016-04-03 21:18:56 -070091 void OpenShooter();
92 void CloseShooter();
93 void CloseIfBall();
94 bool SuperstructureProfileDone();
95 bool SuperstructureDone();
Austin Schuh3e4a5272016-04-20 20:11:00 -070096 void TippyDrive(double goal_distance, double tip_distance, double below,
97 double above);
Austin Schuhf59b8ee2016-03-19 21:31:36 -070098
Austin Schuh3e4a5272016-04-20 20:11:00 -070099 void DoFullShot();
Austin Schuhf59b8ee2016-03-19 21:31:36 -0700100 void LowBarDrive();
101 // Drive to the middle spot over the middle position. Designed for the rock
102 // wall, rough terain, or ramparts.
103 void MiddleDrive();
104
105 void OneFromMiddleDrive(bool left);
106 void TwoFromMiddleDrive();
107
108 double shooter_speed_ = 0.0;
109 void SetShooterSpeed(double speed);
110 void WaitForShooterSpeed();
111 void Shoot();
112
113 void AlignWithVisionGoal();
Austin Schuh23b21802016-04-03 21:18:56 -0700114 void WaitForAlignedWithVision(aos::time::Time align_duration);
Austin Schuhf59b8ee2016-03-19 21:31:36 -0700115
Austin Schuh3e4a5272016-04-20 20:11:00 -0700116 void TwoBallAuto();
117
Austin Schuhf59b8ee2016-03-19 21:31:36 -0700118 ::std::unique_ptr<actors::VisionAlignAction> vision_action_;
Comran Morshede68e3732016-03-12 14:12:11 +0000119};
120
Comran Morshed435f1112016-03-12 14:20:45 +0000121typedef ::aos::common::actions::TypedAction<AutonomousActionQueueGroup>
122 AutonomousAction;
Comran Morshede68e3732016-03-12 14:12:11 +0000123
124// Makes a new AutonomousActor action.
125::std::unique_ptr<AutonomousAction> MakeAutonomousAction(
126 const ::y2016::actors::AutonomousActionParams &params);
127
128} // namespace actors
129} // namespace y2016
130
131#endif // Y2016_ACTORS_AUTONOMOUS_ACTOR_H_