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" |
Comran Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 10 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
| 11 | #include "frc971/control_loops/drivetrain/drivetrain_config.h" |
Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 12 | |
| 13 | namespace y2016 { |
| 14 | namespace actors { |
Comran Morshed | b134e77 | 2016-03-16 21:05:05 +0000 | [diff] [blame] | 15 | using ::frc971::ProfileParameters; |
Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 16 | |
| 17 | class AutonomousActor |
| 18 | : public ::aos::common::actions::ActorBase<AutonomousActionQueueGroup> { |
| 19 | public: |
| 20 | explicit AutonomousActor(AutonomousActionQueueGroup *s); |
| 21 | |
| 22 | bool RunAction(const actors::AutonomousActionParams ¶ms) override; |
Comran Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 23 | |
| 24 | private: |
| 25 | void ResetDrivetrain(); |
| 26 | void InitializeEncoders(); |
| 27 | void WaitUntilDoneOrCanceled(::std::unique_ptr<aos::common::actions::Action> |
| 28 | action); |
| 29 | void StartDrive(double distance, double angle, |
Austin Schuh | edbb64f | 2016-03-19 01:18:09 -0700 | [diff] [blame] | 30 | ::frc971::ProfileParameters linear, |
| 31 | ::frc971::ProfileParameters angular); |
Comran Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 32 | // Waits for the drive motion to finish. Returns true if it succeeded, and |
| 33 | // false if it cancels. |
| 34 | bool WaitForDriveDone(); |
| 35 | |
Comran Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 36 | const ::frc971::control_loops::drivetrain::DrivetrainConfig dt_config_; |
Comran Morshed | b134e77 | 2016-03-16 21:05:05 +0000 | [diff] [blame] | 37 | |
| 38 | // Initial drivetrain positions. |
| 39 | struct InitialDrivetrain { |
| 40 | double left; |
| 41 | double right; |
| 42 | }; |
| 43 | InitialDrivetrain initial_drivetrain_; |
| 44 | |
| 45 | // Internal struct holding superstructure goals sent by autonomous to the |
| 46 | // loop. |
| 47 | struct SuperstructureGoal { |
| 48 | double intake; |
| 49 | double shoulder; |
| 50 | double wrist; |
| 51 | }; |
| 52 | SuperstructureGoal superstructure_goal_; |
| 53 | |
| 54 | void MoveSuperstructure(double intake, double shoulder, double wrist, |
| 55 | const ProfileParameters intake_params, |
| 56 | const ProfileParameters shoulder_params, |
| 57 | const ProfileParameters wrist_params, double top_rollers, |
| 58 | double bottom_rollers); |
| 59 | void WaitForSuperstructure(); |
Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
Comran Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 62 | typedef ::aos::common::actions::TypedAction<AutonomousActionQueueGroup> |
| 63 | AutonomousAction; |
Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 64 | |
| 65 | // Makes a new AutonomousActor action. |
| 66 | ::std::unique_ptr<AutonomousAction> MakeAutonomousAction( |
| 67 | const ::y2016::actors::AutonomousActionParams ¶ms); |
| 68 | |
| 69 | } // namespace actors |
| 70 | } // namespace y2016 |
| 71 | |
| 72 | #endif // Y2016_ACTORS_AUTONOMOUS_ACTOR_H_ |