blob: 4668c84f61a132367f5ae7d1a49ee4773c9bdb5e [file] [log] [blame]
Comran Morshede68e3732016-03-12 14:12:11 +00001#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 Morshed435f1112016-03-12 14:20:45 +00008
Comran Morshede68e3732016-03-12 14:12:11 +00009#include "y2016/actors/autonomous_action.q.h"
Comran Morshed435f1112016-03-12 14:20:45 +000010#include "frc971/control_loops/drivetrain/drivetrain.q.h"
11#include "frc971/control_loops/drivetrain/drivetrain_config.h"
Comran Morshede68e3732016-03-12 14:12:11 +000012
13namespace y2016 {
14namespace actors {
Comran Morshedb134e772016-03-16 21:05:05 +000015using ::frc971::ProfileParameters;
Comran Morshede68e3732016-03-12 14:12:11 +000016
17class AutonomousActor
18 : public ::aos::common::actions::ActorBase<AutonomousActionQueueGroup> {
19 public:
20 explicit AutonomousActor(AutonomousActionQueueGroup *s);
21
22 bool RunAction(const actors::AutonomousActionParams &params) override;
Comran Morshed435f1112016-03-12 14:20:45 +000023
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 Schuhedbb64f2016-03-19 01:18:09 -070030 ::frc971::ProfileParameters linear,
31 ::frc971::ProfileParameters angular);
Comran Morshed435f1112016-03-12 14:20:45 +000032 // Waits for the drive motion to finish. Returns true if it succeeded, and
33 // false if it cancels.
34 bool WaitForDriveDone();
35
Comran Morshed435f1112016-03-12 14:20:45 +000036 const ::frc971::control_loops::drivetrain::DrivetrainConfig dt_config_;
Comran Morshedb134e772016-03-16 21:05:05 +000037
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 Morshede68e3732016-03-12 14:12:11 +000060};
61
Comran Morshed435f1112016-03-12 14:20:45 +000062typedef ::aos::common::actions::TypedAction<AutonomousActionQueueGroup>
63 AutonomousAction;
Comran Morshede68e3732016-03-12 14:12:11 +000064
65// Makes a new AutonomousActor action.
66::std::unique_ptr<AutonomousAction> MakeAutonomousAction(
67 const ::y2016::actors::AutonomousActionParams &params);
68
69} // namespace actors
70} // namespace y2016
71
72#endif // Y2016_ACTORS_AUTONOMOUS_ACTOR_H_