blob: b8db4e57179183e14c2c3a59136b6f4eba2d1120 [file] [log] [blame]
Philipp Schrader4bd29b12017-02-22 04:42:27 +00001#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
12namespace frc971 {
13namespace autonomous {
14
15class 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
47 bool WaitForDriveProfileDone();
48
Austin Schuh546a0382017-04-16 19:10:18 -070049 bool WaitForTurnProfileDone();
50
51 // Returns the distance left to go.
52 double DriveDistanceLeft();
53
Philipp Schrader4bd29b12017-02-22 04:42:27 +000054 const control_loops::drivetrain::DrivetrainConfig dt_config_;
55
56 // Initial drivetrain positions.
57 struct InitialDrivetrain {
58 double left;
59 double right;
60 };
61 InitialDrivetrain initial_drivetrain_;
62};
63
64using AutonomousAction =
65 ::aos::common::actions::TypedAction<AutonomousActionQueueGroup>;
66
67// Makes a new AutonomousActor action.
68::std::unique_ptr<AutonomousAction> MakeAutonomousAction(
69 const AutonomousActionParams &params);
70
71} // namespace autonomous
72} // namespace frc971
73
74#endif // FRC971_AUTONOMOUS_BASE_AUTONOMOUS_ACTOR_H_