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 | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame^] | 37 | // 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 Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 45 | // 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 Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 49 | const ::frc971::control_loops::drivetrain::DrivetrainConfig dt_config_; |
Comran Morshed | b134e77 | 2016-03-16 21:05:05 +0000 | [diff] [blame] | 50 | |
| 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 Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 70 | const ProfileParameters wrist_params, |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 71 | bool traverse_up, double roller_power); |
Comran Morshed | b134e77 | 2016-03-16 21:05:05 +0000 | [diff] [blame] | 72 | void WaitForSuperstructure(); |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 73 | void WaitForSuperstructureLow(); |
| 74 | void WaitForIntake(); |
| 75 | bool IntakeDone(); |
| 76 | bool WaitForDriveProfileDone(); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 77 | |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame^] | 78 | void FrontLongShot(); |
| 79 | void FrontMiddleShot(); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 80 | void BackLongShot(); |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 81 | void BackLongShotTwoBall(); |
| 82 | void BackLongShotLowBarTwoBall(); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 83 | void BackMiddleShot(); |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 84 | void WaitForBall(); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 85 | void TuckArm(bool arm_down, bool traverse_down); |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 86 | void OpenShooter(); |
| 87 | void CloseShooter(); |
| 88 | void CloseIfBall(); |
| 89 | bool SuperstructureProfileDone(); |
| 90 | bool SuperstructureDone(); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame^] | 91 | void TippyDrive(double goal_distance, double tip_distance, double below, |
| 92 | double above); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 93 | |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame^] | 94 | void DoFullShot(); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 95 | 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 Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 109 | void WaitForAlignedWithVision(aos::time::Time align_duration); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 110 | |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame^] | 111 | void TwoBallAuto(); |
| 112 | |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 113 | ::std::unique_ptr<actors::VisionAlignAction> vision_action_; |
Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 114 | }; |
| 115 | |
Comran Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 116 | typedef ::aos::common::actions::TypedAction<AutonomousActionQueueGroup> |
| 117 | AutonomousAction; |
Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 118 | |
| 119 | // Makes a new AutonomousActor action. |
| 120 | ::std::unique_ptr<AutonomousAction> MakeAutonomousAction( |
| 121 | const ::y2016::actors::AutonomousActionParams ¶ms); |
| 122 | |
| 123 | } // namespace actors |
| 124 | } // namespace y2016 |
| 125 | |
| 126 | #endif // Y2016_ACTORS_AUTONOMOUS_ACTOR_H_ |