Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 1 | #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 Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 8 | |
Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 9 | #include "y2016/actors/autonomous_action.q.h" |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 10 | #include "y2016/actors/vision_align_actor.h" |
Comran Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 11 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
| 12 | #include "frc971/control_loops/drivetrain/drivetrain_config.h" |
Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 13 | |
| 14 | namespace y2016 { |
| 15 | namespace actors { |
Comran Morshed | b134e77 | 2016-03-16 21:05:05 +0000 | [diff] [blame] | 16 | using ::frc971::ProfileParameters; |
Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 17 | |
| 18 | class AutonomousActor |
| 19 | : public ::aos::common::actions::ActorBase<AutonomousActionQueueGroup> { |
| 20 | public: |
| 21 | explicit AutonomousActor(AutonomousActionQueueGroup *s); |
| 22 | |
| 23 | bool RunAction(const actors::AutonomousActionParams ¶ms) override; |
Comran Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 24 | |
| 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 Schuh | edbb64f | 2016-03-19 01:18:09 -0700 | [diff] [blame] | 31 | ::frc971::ProfileParameters linear, |
| 32 | ::frc971::ProfileParameters angular); |
Comran Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 33 | // Waits for the drive motion to finish. Returns true if it succeeded, and |
| 34 | // false if it cancels. |
| 35 | bool WaitForDriveDone(); |
| 36 | |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 37 | // 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 Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 41 | const ::frc971::control_loops::drivetrain::DrivetrainConfig dt_config_; |
Comran Morshed | b134e77 | 2016-03-16 21:05:05 +0000 | [diff] [blame] | 42 | |
| 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 Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 62 | const ProfileParameters wrist_params, |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame^] | 63 | bool traverse_up, double roller_power); |
Comran Morshed | b134e77 | 2016-03-16 21:05:05 +0000 | [diff] [blame] | 64 | void WaitForSuperstructure(); |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame^] | 65 | void WaitForSuperstructureLow(); |
| 66 | void WaitForIntake(); |
| 67 | bool IntakeDone(); |
| 68 | bool WaitForDriveProfileDone(); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 69 | |
| 70 | void BackLongShot(); |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame^] | 71 | void BackLongShotTwoBall(); |
| 72 | void BackLongShotLowBarTwoBall(); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 73 | void BackMiddleShot(); |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame^] | 74 | void WaitForBall(); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 75 | void TuckArm(bool arm_down, bool traverse_down); |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame^] | 76 | void OpenShooter(); |
| 77 | void CloseShooter(); |
| 78 | void CloseIfBall(); |
| 79 | bool SuperstructureProfileDone(); |
| 80 | bool SuperstructureDone(); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 81 | |
| 82 | void DoFullShot(bool center); |
| 83 | void LowBarDrive(); |
| 84 | // Drive to the middle spot over the middle position. Designed for the rock |
| 85 | // wall, rough terain, or ramparts. |
| 86 | void MiddleDrive(); |
| 87 | |
| 88 | void OneFromMiddleDrive(bool left); |
| 89 | void TwoFromMiddleDrive(); |
| 90 | |
| 91 | double shooter_speed_ = 0.0; |
| 92 | void SetShooterSpeed(double speed); |
| 93 | void WaitForShooterSpeed(); |
| 94 | void Shoot(); |
| 95 | |
| 96 | void AlignWithVisionGoal(); |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame^] | 97 | void WaitForAlignedWithVision(aos::time::Time align_duration); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 98 | |
| 99 | ::std::unique_ptr<actors::VisionAlignAction> vision_action_; |
Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 100 | }; |
| 101 | |
Comran Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 102 | typedef ::aos::common::actions::TypedAction<AutonomousActionQueueGroup> |
| 103 | AutonomousAction; |
Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 104 | |
| 105 | // Makes a new AutonomousActor action. |
| 106 | ::std::unique_ptr<AutonomousAction> MakeAutonomousAction( |
| 107 | const ::y2016::actors::AutonomousActionParams ¶ms); |
| 108 | |
| 109 | } // namespace actors |
| 110 | } // namespace y2016 |
| 111 | |
| 112 | #endif // Y2016_ACTORS_AUTONOMOUS_ACTOR_H_ |