Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 1 | #ifndef FRC971_AUTONOMOUS_BASE_AUTONOMOUS_ACTOR_H_ |
| 2 | #define FRC971_AUTONOMOUS_BASE_AUTONOMOUS_ACTOR_H_ |
| 3 | |
| 4 | #include <memory> |
| 5 | |
| 6 | #include "aos/common/actions/actions.h" |
| 7 | #include "aos/common/actions/actor.h" |
| 8 | #include "frc971/autonomous/auto.q.h" |
| 9 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
| 10 | #include "frc971/control_loops/drivetrain/drivetrain_config.h" |
| 11 | |
| 12 | namespace frc971 { |
| 13 | namespace autonomous { |
| 14 | |
| 15 | class BaseAutonomousActor |
| 16 | : public ::aos::common::actions::ActorBase<AutonomousActionQueueGroup> { |
| 17 | public: |
| 18 | explicit BaseAutonomousActor( |
| 19 | AutonomousActionQueueGroup *s, |
| 20 | const control_loops::drivetrain::DrivetrainConfig dt_config); |
| 21 | |
| 22 | protected: |
| 23 | void ResetDrivetrain(); |
| 24 | void InitializeEncoders(); |
| 25 | void StartDrive(double distance, double angle, ProfileParameters linear, |
| 26 | ProfileParameters angular); |
| 27 | |
| 28 | void WaitUntilDoneOrCanceled( |
| 29 | ::std::unique_ptr<aos::common::actions::Action> action); |
| 30 | // Waits for the drive motion to finish. Returns true if it succeeded, and |
| 31 | // false if it cancels. |
| 32 | bool WaitForDriveDone(); |
| 33 | |
| 34 | // Returns true if the drive has finished. |
| 35 | bool IsDriveDone(); |
| 36 | |
| 37 | // Waits until the robot is pitched up above the specified angle, or the move |
| 38 | // finishes. Returns true on success, and false if it cancels. |
| 39 | bool WaitForAboveAngle(double angle); |
| 40 | bool WaitForBelowAngle(double angle); |
| 41 | bool WaitForMaxBy(double angle); |
| 42 | |
| 43 | // Waits until the profile and distance is within distance and angle of the |
| 44 | // goal. Returns true on success, and false when canceled. |
| 45 | bool WaitForDriveNear(double distance, double angle); |
| 46 | |
Austin Schuh | 0aae924 | 2018-03-14 19:49:44 -0700 | [diff] [blame^] | 47 | bool WaitForDriveProfileNear(double tolerance); |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 48 | bool WaitForDriveProfileDone(); |
| 49 | |
Austin Schuh | 0aae924 | 2018-03-14 19:49:44 -0700 | [diff] [blame^] | 50 | bool WaitForTurnProfileNear(double tolerance); |
Austin Schuh | 546a038 | 2017-04-16 19:10:18 -0700 | [diff] [blame] | 51 | bool WaitForTurnProfileDone(); |
| 52 | |
| 53 | // Returns the distance left to go. |
| 54 | double DriveDistanceLeft(); |
| 55 | |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 56 | const control_loops::drivetrain::DrivetrainConfig dt_config_; |
| 57 | |
| 58 | // Initial drivetrain positions. |
| 59 | struct InitialDrivetrain { |
| 60 | double left; |
| 61 | double right; |
| 62 | }; |
| 63 | InitialDrivetrain initial_drivetrain_; |
Austin Schuh | 0aae924 | 2018-03-14 19:49:44 -0700 | [diff] [blame^] | 64 | |
| 65 | void set_max_drivetrain_voltage(double max_drivetrain_voltage) { |
| 66 | max_drivetrain_voltage_ = max_drivetrain_voltage; |
| 67 | } |
| 68 | |
| 69 | private: |
| 70 | double max_drivetrain_voltage_ = 12.0; |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | using AutonomousAction = |
| 74 | ::aos::common::actions::TypedAction<AutonomousActionQueueGroup>; |
| 75 | |
| 76 | // Makes a new AutonomousActor action. |
| 77 | ::std::unique_ptr<AutonomousAction> MakeAutonomousAction( |
| 78 | const AutonomousActionParams ¶ms); |
| 79 | |
| 80 | } // namespace autonomous |
| 81 | } // namespace frc971 |
| 82 | |
| 83 | #endif // FRC971_AUTONOMOUS_BASE_AUTONOMOUS_ACTOR_H_ |