blob: 036f0f8f0dc73289919020bdb272facae2ae2317 [file] [log] [blame]
Austin Schuh87c10632017-02-05 19:02:17 -08001#ifndef Y2017_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_
2#define Y2017_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_
3
4#include <memory>
5
6#include "aos/common/controls/control_loop.h"
7#include "frc971/control_loops/state_feedback_loop.h"
8#include "y2017/control_loops/superstructure/hood/hood.h"
9#include "y2017/control_loops/superstructure/superstructure.q.h"
10
11namespace y2017 {
12namespace control_loops {
13namespace superstructure {
14
15class Superstructure
16 : public ::aos::controls::ControlLoop<control_loops::SuperstructureQueue> {
17 public:
18 explicit Superstructure(
19 control_loops::SuperstructureQueue *my_superstructure =
20 &control_loops::superstructure_queue);
21
22 enum State {
23 // Wait for all the filters to be ready before starting the initialization
24 // process.
25 UNINITIALIZED = 0,
26
27 // We now are ready to decide how to zero. Decide what to do once we are
28 // enabled.
29 DISABLED_INITIALIZED = 1,
30
31 ZEROING = 2,
32 // Run with full power.
33 RUNNING = 3,
34 // Internal error caused the superstructure to abort.
35 ESTOP = 4,
36 };
37
38 bool IsRunning() const { return state_ == RUNNING; }
39
40 State state() const { return state_; }
41
42 // Returns the value to move the joint to such that it will stay below
43 // reference_angle starting at current_angle, but move at least move_distance
44 static double MoveButKeepBelow(double reference_angle, double current_angle,
45 double move_distance);
46 // Returns the value to move the joint to such that it will stay above
47 // reference_angle starting at current_angle, but move at least move_distance
48 static double MoveButKeepAbove(double reference_angle, double current_angle,
49 double move_distance);
50
51 protected:
52 virtual void RunIteration(
53 const control_loops::SuperstructureQueue::Goal *unsafe_goal,
54 const control_loops::SuperstructureQueue::Position *position,
55 control_loops::SuperstructureQueue::Output *output,
56 control_loops::SuperstructureQueue::Status *status) override;
57
58 private:
59 hood::Hood hood_;
60
61 State state_ = UNINITIALIZED;
62
63 DISALLOW_COPY_AND_ASSIGN(Superstructure);
64};
65
66} // namespace superstructure
67} // namespace control_loops
68} // namespace y2017
69
70#endif // Y2017_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_