blob: 4da9522dd42eb864c8a46986eb6129e34fd58bb9 [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();
36
Austin Schuh3e4a5272016-04-20 20:11:00 -070037 // Returns true if the drive has finished.
38 bool IsDriveDone();
39 // Waits until the robot is pitched up above the specified angle, or the move
40 // finishes. Returns true on success, and false if it cancels.
41 bool WaitForAboveAngle(double angle);
42 bool WaitForBelowAngle(double angle);
43 bool WaitForMaxBy(double angle);
44
Austin Schuhf59b8ee2016-03-19 21:31:36 -070045 // Waits until the profile and distance is within distance and angle of the
46 // goal. Returns true on success, and false when canceled.
47 bool WaitForDriveNear(double distance, double angle);
48
Comran Morshed435f1112016-03-12 14:20:45 +000049 const ::frc971::control_loops::drivetrain::DrivetrainConfig dt_config_;
Comran Morshedb134e772016-03-16 21:05:05 +000050
51 // Initial drivetrain positions.
52 struct InitialDrivetrain {
53 double left;
54 double right;
55 };
56 InitialDrivetrain initial_drivetrain_;
57
58 // Internal struct holding superstructure goals sent by autonomous to the
59 // loop.
60 struct SuperstructureGoal {
61 double intake;
62 double shoulder;
63 double wrist;
64 };
65 SuperstructureGoal superstructure_goal_;
66
67 void MoveSuperstructure(double intake, double shoulder, double wrist,
68 const ProfileParameters intake_params,
69 const ProfileParameters shoulder_params,
Austin Schuhf59b8ee2016-03-19 21:31:36 -070070 const ProfileParameters wrist_params,
Austin Schuh23b21802016-04-03 21:18:56 -070071 bool traverse_up, double roller_power);
Comran Morshedb134e772016-03-16 21:05:05 +000072 void WaitForSuperstructure();
Austin Schuh23b21802016-04-03 21:18:56 -070073 void WaitForSuperstructureLow();
74 void WaitForIntake();
75 bool IntakeDone();
76 bool WaitForDriveProfileDone();
Austin Schuhf59b8ee2016-03-19 21:31:36 -070077
Austin Schuh3e4a5272016-04-20 20:11:00 -070078 void FrontLongShot();
79 void FrontMiddleShot();
Austin Schuhf59b8ee2016-03-19 21:31:36 -070080 void BackLongShot();
Austin Schuh23b21802016-04-03 21:18:56 -070081 void BackLongShotTwoBall();
82 void BackLongShotLowBarTwoBall();
Austin Schuhf59b8ee2016-03-19 21:31:36 -070083 void BackMiddleShot();
Austin Schuh23b21802016-04-03 21:18:56 -070084 void WaitForBall();
Austin Schuhf59b8ee2016-03-19 21:31:36 -070085 void TuckArm(bool arm_down, bool traverse_down);
Austin Schuh23b21802016-04-03 21:18:56 -070086 void OpenShooter();
87 void CloseShooter();
88 void CloseIfBall();
89 bool SuperstructureProfileDone();
90 bool SuperstructureDone();
Austin Schuh3e4a5272016-04-20 20:11:00 -070091 void TippyDrive(double goal_distance, double tip_distance, double below,
92 double above);
Austin Schuhf59b8ee2016-03-19 21:31:36 -070093
Austin Schuh3e4a5272016-04-20 20:11:00 -070094 void DoFullShot();
Austin Schuhf59b8ee2016-03-19 21:31:36 -070095 void LowBarDrive();
96 // Drive to the middle spot over the middle position. Designed for the rock
97 // wall, rough terain, or ramparts.
98 void MiddleDrive();
99
100 void OneFromMiddleDrive(bool left);
101 void TwoFromMiddleDrive();
102
103 double shooter_speed_ = 0.0;
104 void SetShooterSpeed(double speed);
105 void WaitForShooterSpeed();
106 void Shoot();
107
108 void AlignWithVisionGoal();
Austin Schuh23b21802016-04-03 21:18:56 -0700109 void WaitForAlignedWithVision(aos::time::Time align_duration);
Austin Schuhf59b8ee2016-03-19 21:31:36 -0700110
Austin Schuh3e4a5272016-04-20 20:11:00 -0700111 void TwoBallAuto();
112
Austin Schuhf59b8ee2016-03-19 21:31:36 -0700113 ::std::unique_ptr<actors::VisionAlignAction> vision_action_;
Comran Morshede68e3732016-03-12 14:12:11 +0000114};
115
Comran Morshed435f1112016-03-12 14:20:45 +0000116typedef ::aos::common::actions::TypedAction<AutonomousActionQueueGroup>
117 AutonomousAction;
Comran Morshede68e3732016-03-12 14:12:11 +0000118
119// Makes a new AutonomousActor action.
120::std::unique_ptr<AutonomousAction> MakeAutonomousAction(
121 const ::y2016::actors::AutonomousActionParams &params);
122
123} // namespace actors
124} // namespace y2016
125
126#endif // Y2016_ACTORS_AUTONOMOUS_ACTOR_H_