blob: 9a04c3c7c37261f95b33c55bb3af702a2ae94de7 [file] [log] [blame]
Comran Morshed25f81a02016-01-23 13:40:10 +00001#ifndef Y2016_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_
2#define Y2016_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_
3
4#include <memory>
5
6#include "aos/common/controls/control_loop.h"
Austin Schuh2fc10fa2016-02-08 00:44:34 -08007#include "aos/common/util/trapezoid_profile.h"
Austin Schuh10c2d112016-02-14 13:42:28 -08008#include "frc971/control_loops/state_feedback_loop.h"
Comran Morshed25f81a02016-01-23 13:40:10 +00009
Austin Schuh2fc10fa2016-02-08 00:44:34 -080010#include "frc971/zeroing/zeroing.h"
Comran Morshed25f81a02016-01-23 13:40:10 +000011#include "y2016/control_loops/superstructure/superstructure.q.h"
Austin Schuh10c2d112016-02-14 13:42:28 -080012#include "y2016/control_loops/superstructure/superstructure_controls.h"
Comran Morshed25f81a02016-01-23 13:40:10 +000013
14namespace y2016 {
15namespace control_loops {
Austin Schuh2fc10fa2016-02-08 00:44:34 -080016namespace superstructure {
17namespace testing {
18class SuperstructureTest_DisabledGoalTest_Test;
19} // namespace testing
20
Comran Morshed25f81a02016-01-23 13:40:10 +000021class Superstructure
22 : public ::aos::controls::ControlLoop<control_loops::SuperstructureQueue> {
23 public:
24 explicit Superstructure(
25 control_loops::SuperstructureQueue *my_superstructure =
26 &control_loops::superstructure_queue);
Austin Schuh2fc10fa2016-02-08 00:44:34 -080027 enum State {
28 // Waiting to receive data before doing anything.
29 UNINITIALIZED = 0,
30 // Estimating the starting location.
31 INITIALIZING = 1,
32 // Moving the intake to find an index pulse.
33 ZEROING_INTAKE = 2,
34 // Moving the arm to find an index pulse.
35 ZEROING_ARM = 3,
36 // All good!
37 RUNNING = 4,
38 // Internal error caused the superstructure to abort.
39 ESTOP = 5,
40 };
41
42 State state() const { return state_; }
Comran Morshed25f81a02016-01-23 13:40:10 +000043
44 protected:
45 virtual void RunIteration(
Austin Schuh2fc10fa2016-02-08 00:44:34 -080046 const control_loops::SuperstructureQueue::Goal *unsafe_goal,
Comran Morshed25f81a02016-01-23 13:40:10 +000047 const control_loops::SuperstructureQueue::Position *position,
Austin Schuh2fc10fa2016-02-08 00:44:34 -080048 control_loops::SuperstructureQueue::Output *output,
Comran Morshed25f81a02016-01-23 13:40:10 +000049 control_loops::SuperstructureQueue::Status *status) override;
50
51 private:
Austin Schuh2fc10fa2016-02-08 00:44:34 -080052 friend class testing::SuperstructureTest_DisabledGoalTest_Test;
53 Intake intake_;
54 Arm arm_;
55
56 State state_ = UNINITIALIZED;
57 State last_state_ = UNINITIALIZED;
58
59 // Sets state_ to the correct state given the current state of the zeroing
60 // estimators.
61 void UpdateZeroingState();
62
Comran Morshed25f81a02016-01-23 13:40:10 +000063 DISALLOW_COPY_AND_ASSIGN(Superstructure);
64};
65
Austin Schuh2fc10fa2016-02-08 00:44:34 -080066} // namespace superstructure
Comran Morshed25f81a02016-01-23 13:40:10 +000067} // namespace control_loops
68} // namespace y2016
69
70#endif // Y2016_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_