blob: 69e2e5aaca843bbe3b54a629691364987e93f4fc [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
49 const control_loops::drivetrain::DrivetrainConfig dt_config_;
50
51 // Initial drivetrain positions.
52 struct InitialDrivetrain {
53 double left;
54 double right;
55 };
56 InitialDrivetrain initial_drivetrain_;
57};
58
59using AutonomousAction =
60 ::aos::common::actions::TypedAction<AutonomousActionQueueGroup>;
61
62// Makes a new AutonomousActor action.
63::std::unique_ptr<AutonomousAction> MakeAutonomousAction(
64 const AutonomousActionParams &params);
65
66} // namespace autonomous
67} // namespace frc971
68
69#endif // FRC971_AUTONOMOUS_BASE_AUTONOMOUS_ACTOR_H_