blob: ec0c9e1ace990510d7ba59efd583e45720ce8d08 [file] [log] [blame]
Sabina Davis8d20ca82018-02-19 13:17:45 -08001#ifndef Y2018_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_
2#define Y2018_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"
Austin Schuhcb091712018-02-21 20:01:55 -08008#include "y2018/control_loops/superstructure/arm/arm.h"
Sabina Davis8d20ca82018-02-19 13:17:45 -08009#include "y2018/control_loops/superstructure/intake/intake.h"
10#include "y2018/control_loops/superstructure/superstructure.q.h"
11
12namespace y2018 {
13namespace control_loops {
14namespace superstructure {
15
16class Superstructure
17 : public ::aos::controls::ControlLoop<control_loops::SuperstructureQueue> {
18 public:
19 explicit Superstructure(
20 control_loops::SuperstructureQueue *my_superstructure =
21 &control_loops::superstructure_queue);
22
23 const intake::IntakeSide &intake_left() const { return intake_left_; }
24 const intake::IntakeSide &intake_right() const { return intake_right_; }
Austin Schuhcb091712018-02-21 20:01:55 -080025 const arm::Arm &arm() const { return arm_; }
Sabina Davis8d20ca82018-02-19 13:17:45 -080026
27 protected:
28 virtual void RunIteration(
29 const control_loops::SuperstructureQueue::Goal *unsafe_goal,
30 const control_loops::SuperstructureQueue::Position *position,
31 control_loops::SuperstructureQueue::Output *output,
32 control_loops::SuperstructureQueue::Status *status) override;
33
34 private:
35 intake::IntakeSide intake_left_;
36 intake::IntakeSide intake_right_;
Austin Schuhcb091712018-02-21 20:01:55 -080037 arm::Arm arm_;
Sabina Davis8d20ca82018-02-19 13:17:45 -080038
Neil Balchba9cbba2018-04-06 22:26:38 -070039 // The last centering error. This is the distance that the center of the two
40 // intakes is away from 0.
41 double last_intake_center_error_ = 0.0;
42 // The last distance that the box distance lidar measured.
43 double last_box_distance_ = 0.0;
44 // State variable for the box velocity low pass filter.
45 double filtered_box_velocity_ = 0.0;
46
Austin Schuh17dd0892018-03-02 20:06:31 -080047 enum class RotationState {
48 NOT_ROTATING = 0,
49 ROTATING_LEFT = 1,
Neil Balchba9cbba2018-04-06 22:26:38 -070050 ROTATING_RIGHT = 2,
51 STUCK = 3
Austin Schuh17dd0892018-03-02 20:06:31 -080052 };
53
54 RotationState rotation_state_ = RotationState::NOT_ROTATING;
55 int rotation_count_ = 0;
Neil Balchba9cbba2018-04-06 22:26:38 -070056 int stuck_count_ = 0;
57 ::aos::monotonic_clock::time_point last_stuck_time_ =
58 ::aos::monotonic_clock::min_time;
59 ::aos::monotonic_clock::time_point last_unstuck_time_ =
60 ::aos::monotonic_clock::min_time;
Austin Schuh17dd0892018-03-02 20:06:31 -080061
Sabina Davis8d20ca82018-02-19 13:17:45 -080062 DISALLOW_COPY_AND_ASSIGN(Superstructure);
63};
64
65} // namespace superstructure
66} // namespace control_loops
67} // namespace y2018
68
69#endif // Y2018_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_