blob: 15ed95d00d03e1d3aff8dab04fd74a2368f4893d [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 Schuhf59b8ee2016-03-19 21:31:36 -070037 // Waits until the profile and distance is within distance and angle of the
38 // goal. Returns true on success, and false when canceled.
39 bool WaitForDriveNear(double distance, double angle);
40
Comran Morshed435f1112016-03-12 14:20:45 +000041 const ::frc971::control_loops::drivetrain::DrivetrainConfig dt_config_;
Comran Morshedb134e772016-03-16 21:05:05 +000042
43 // Initial drivetrain positions.
44 struct InitialDrivetrain {
45 double left;
46 double right;
47 };
48 InitialDrivetrain initial_drivetrain_;
49
50 // Internal struct holding superstructure goals sent by autonomous to the
51 // loop.
52 struct SuperstructureGoal {
53 double intake;
54 double shoulder;
55 double wrist;
56 };
57 SuperstructureGoal superstructure_goal_;
58
59 void MoveSuperstructure(double intake, double shoulder, double wrist,
60 const ProfileParameters intake_params,
61 const ProfileParameters shoulder_params,
Austin Schuhf59b8ee2016-03-19 21:31:36 -070062 const ProfileParameters wrist_params,
63 bool traverse_up);
Comran Morshedb134e772016-03-16 21:05:05 +000064 void WaitForSuperstructure();
Austin Schuhf59b8ee2016-03-19 21:31:36 -070065
66 void BackLongShot();
67 void BackMiddleShot();
68 void TuckArm(bool arm_down, bool traverse_down);
69
70 void DoFullShot(bool center);
71 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();
85 void WaitForAlignedWithVision();
86
87 ::std::unique_ptr<actors::VisionAlignAction> vision_action_;
Comran Morshede68e3732016-03-12 14:12:11 +000088};
89
Comran Morshed435f1112016-03-12 14:20:45 +000090typedef ::aos::common::actions::TypedAction<AutonomousActionQueueGroup>
91 AutonomousAction;
Comran Morshede68e3732016-03-12 14:12:11 +000092
93// Makes a new AutonomousActor action.
94::std::unique_ptr<AutonomousAction> MakeAutonomousAction(
95 const ::y2016::actors::AutonomousActionParams &params);
96
97} // namespace actors
98} // namespace y2016
99
100#endif // Y2016_ACTORS_AUTONOMOUS_ACTOR_H_