blob: 8ab6bf32b378e8f451bdc13b7b2180ffd3874245 [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
John Park33858a32018-09-28 23:05:48 -07006#include "aos/controls/control_loop.h"
Austin Schuh01a9f2a2019-05-27 13:36:30 -07007#include "aos/events/event-loop.h"
Sabina Davis8d20ca82018-02-19 13:17:45 -08008#include "frc971/control_loops/state_feedback_loop.h"
Austin Schuhcb091712018-02-21 20:01:55 -08009#include "y2018/control_loops/superstructure/arm/arm.h"
Sabina Davis8d20ca82018-02-19 13:17:45 -080010#include "y2018/control_loops/superstructure/intake/intake.h"
11#include "y2018/control_loops/superstructure/superstructure.q.h"
Austin Schuh01a9f2a2019-05-27 13:36:30 -070012#include "y2018/status_light.q.h"
Sabina Davis8d20ca82018-02-19 13:17:45 -080013
14namespace y2018 {
15namespace control_loops {
16namespace superstructure {
17
18class Superstructure
19 : public ::aos::controls::ControlLoop<control_loops::SuperstructureQueue> {
20 public:
21 explicit Superstructure(
Austin Schuh55a13dc2019-01-27 22:39:03 -080022 ::aos::EventLoop *event_loop,
23 const ::std::string &name = ".y2018.control_loops.superstructure_queue");
Sabina Davis8d20ca82018-02-19 13:17:45 -080024
25 const intake::IntakeSide &intake_left() const { return intake_left_; }
26 const intake::IntakeSide &intake_right() const { return intake_right_; }
Austin Schuhcb091712018-02-21 20:01:55 -080027 const arm::Arm &arm() const { return arm_; }
Sabina Davis8d20ca82018-02-19 13:17:45 -080028
29 protected:
30 virtual void RunIteration(
31 const control_loops::SuperstructureQueue::Goal *unsafe_goal,
32 const control_loops::SuperstructureQueue::Position *position,
33 control_loops::SuperstructureQueue::Output *output,
34 control_loops::SuperstructureQueue::Status *status) override;
35
36 private:
Austin Schuh01a9f2a2019-05-27 13:36:30 -070037 // Sends the status light message for the 3 colors provided.
38 void SendColors(float red, float green, float blue);
39
40 ::aos::Sender<::y2018::StatusLight> status_light_sender_;
41
Sabina Davis8d20ca82018-02-19 13:17:45 -080042 intake::IntakeSide intake_left_;
43 intake::IntakeSide intake_right_;
Austin Schuhcb091712018-02-21 20:01:55 -080044 arm::Arm arm_;
Sabina Davis8d20ca82018-02-19 13:17:45 -080045
Neil Balchba9cbba2018-04-06 22:26:38 -070046 // The last centering error. This is the distance that the center of the two
47 // intakes is away from 0.
48 double last_intake_center_error_ = 0.0;
49 // The last distance that the box distance lidar measured.
50 double last_box_distance_ = 0.0;
51 // State variable for the box velocity low pass filter.
52 double filtered_box_velocity_ = 0.0;
53
Austin Schuh17dd0892018-03-02 20:06:31 -080054 enum class RotationState {
55 NOT_ROTATING = 0,
56 ROTATING_LEFT = 1,
Neil Balchba9cbba2018-04-06 22:26:38 -070057 ROTATING_RIGHT = 2,
58 STUCK = 3
Austin Schuh17dd0892018-03-02 20:06:31 -080059 };
60
61 RotationState rotation_state_ = RotationState::NOT_ROTATING;
62 int rotation_count_ = 0;
Neil Balchba9cbba2018-04-06 22:26:38 -070063 int stuck_count_ = 0;
64 ::aos::monotonic_clock::time_point last_stuck_time_ =
65 ::aos::monotonic_clock::min_time;
66 ::aos::monotonic_clock::time_point last_unstuck_time_ =
67 ::aos::monotonic_clock::min_time;
Austin Schuh17dd0892018-03-02 20:06:31 -080068
Sabina Davis8d20ca82018-02-19 13:17:45 -080069 DISALLOW_COPY_AND_ASSIGN(Superstructure);
70};
71
72} // namespace superstructure
73} // namespace control_loops
74} // namespace y2018
75
76#endif // Y2018_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_