blob: 980be2c159b5f47b0bc0890552b801a6311cf113 [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
Austin Schuh0aae9242018-03-14 19:49:44 -070047 bool WaitForDriveProfileNear(double tolerance);
Philipp Schrader4bd29b12017-02-22 04:42:27 +000048 bool WaitForDriveProfileDone();
49
Austin Schuh0aae9242018-03-14 19:49:44 -070050 bool WaitForTurnProfileNear(double tolerance);
Austin Schuh546a0382017-04-16 19:10:18 -070051 bool WaitForTurnProfileDone();
52
53 // Returns the distance left to go.
54 double DriveDistanceLeft();
55
Philipp Schrader4bd29b12017-02-22 04:42:27 +000056 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 Schuh0aae9242018-03-14 19:49:44 -070064
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 Schrader4bd29b12017-02-22 04:42:27 +000071};
72
73using AutonomousAction =
74 ::aos::common::actions::TypedAction<AutonomousActionQueueGroup>;
75
76// Makes a new AutonomousActor action.
77::std::unique_ptr<AutonomousAction> MakeAutonomousAction(
78 const AutonomousActionParams &params);
79
80} // namespace autonomous
81} // namespace frc971
82
83#endif // FRC971_AUTONOMOUS_BASE_AUTONOMOUS_ACTOR_H_