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 | |
Austin Schuh | f2a50ba | 2016-12-24 16:16:26 -0800 | [diff] [blame^] | 4 | #include <chrono> |
Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 5 | #include <memory> |
| 6 | |
Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 7 | #include "aos/common/actions/actions.h" |
Austin Schuh | f2a50ba | 2016-12-24 16:16:26 -0800 | [diff] [blame^] | 8 | #include "aos/common/actions/actor.h" |
Comran Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 9 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
| 10 | #include "frc971/control_loops/drivetrain/drivetrain_config.h" |
Austin Schuh | f2a50ba | 2016-12-24 16:16:26 -0800 | [diff] [blame^] | 11 | #include "y2016/actors/autonomous_action.q.h" |
| 12 | #include "y2016/actors/vision_align_actor.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(); |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 36 | void WaitForBallOrDriveDone(); |
| 37 | |
| 38 | void StealAndMoveOverBy(double distance); |
Comran Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 39 | |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 40 | // 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 Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 48 | // 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 Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 52 | const ::frc971::control_loops::drivetrain::DrivetrainConfig dt_config_; |
Comran Morshed | b134e77 | 2016-03-16 21:05:05 +0000 | [diff] [blame] | 53 | |
| 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 Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 73 | const ProfileParameters wrist_params, |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 74 | bool traverse_up, double roller_power); |
Comran Morshed | b134e77 | 2016-03-16 21:05:05 +0000 | [diff] [blame] | 75 | void WaitForSuperstructure(); |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 76 | void WaitForSuperstructureProfile(); |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 77 | void WaitForSuperstructureLow(); |
| 78 | void WaitForIntake(); |
| 79 | bool IntakeDone(); |
| 80 | bool WaitForDriveProfileDone(); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 81 | |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 82 | void FrontLongShot(); |
| 83 | void FrontMiddleShot(); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 84 | void BackLongShot(); |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 85 | void BackLongShotTwoBall(); |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 86 | void BackLongShotTwoBallFinish(); |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 87 | void BackLongShotLowBarTwoBall(); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 88 | void BackMiddleShot(); |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 89 | void WaitForBall(); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 90 | void TuckArm(bool arm_down, bool traverse_down); |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 91 | void OpenShooter(); |
| 92 | void CloseShooter(); |
| 93 | void CloseIfBall(); |
| 94 | bool SuperstructureProfileDone(); |
| 95 | bool SuperstructureDone(); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 96 | void TippyDrive(double goal_distance, double tip_distance, double below, |
| 97 | double above); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 98 | |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 99 | void DoFullShot(); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 100 | 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 Schuh | f2a50ba | 2016-12-24 16:16:26 -0800 | [diff] [blame^] | 114 | void WaitForAlignedWithVision(::std::chrono::nanoseconds align_duration); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 115 | |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 116 | void TwoBallAuto(); |
| 117 | |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 118 | ::std::unique_ptr<actors::VisionAlignAction> vision_action_; |
Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 119 | }; |
| 120 | |
Comran Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 121 | typedef ::aos::common::actions::TypedAction<AutonomousActionQueueGroup> |
| 122 | AutonomousAction; |
Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 123 | |
| 124 | // Makes a new AutonomousActor action. |
| 125 | ::std::unique_ptr<AutonomousAction> MakeAutonomousAction( |
| 126 | const ::y2016::actors::AutonomousActionParams ¶ms); |
| 127 | |
| 128 | } // namespace actors |
| 129 | } // namespace y2016 |
| 130 | |
| 131 | #endif // Y2016_ACTORS_AUTONOMOUS_ACTOR_H_ |