blob: bceb643c94cd62b432606ef06c35aad294649842 [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"
Austin Schuh300f2f62019-05-27 13:49:23 -070013#include "y2018/vision/vision.q.h"
Sabina Davis8d20ca82018-02-19 13:17:45 -080014
15namespace y2018 {
16namespace control_loops {
17namespace superstructure {
18
19class Superstructure
20 : public ::aos::controls::ControlLoop<control_loops::SuperstructureQueue> {
21 public:
22 explicit Superstructure(
Austin Schuh55a13dc2019-01-27 22:39:03 -080023 ::aos::EventLoop *event_loop,
24 const ::std::string &name = ".y2018.control_loops.superstructure_queue");
Sabina Davis8d20ca82018-02-19 13:17:45 -080025
26 const intake::IntakeSide &intake_left() const { return intake_left_; }
27 const intake::IntakeSide &intake_right() const { return intake_right_; }
Austin Schuhcb091712018-02-21 20:01:55 -080028 const arm::Arm &arm() const { return arm_; }
Sabina Davis8d20ca82018-02-19 13:17:45 -080029
30 protected:
31 virtual void RunIteration(
32 const control_loops::SuperstructureQueue::Goal *unsafe_goal,
33 const control_loops::SuperstructureQueue::Position *position,
34 control_loops::SuperstructureQueue::Output *output,
35 control_loops::SuperstructureQueue::Status *status) override;
36
37 private:
Austin Schuh01a9f2a2019-05-27 13:36:30 -070038 // Sends the status light message for the 3 colors provided.
39 void SendColors(float red, float green, float blue);
40
41 ::aos::Sender<::y2018::StatusLight> status_light_sender_;
Austin Schuh300f2f62019-05-27 13:49:23 -070042 ::aos::Fetcher<::y2018::vision::VisionStatus> vision_status_fetcher_;
Austin Schuh01a9f2a2019-05-27 13:36:30 -070043
Sabina Davis8d20ca82018-02-19 13:17:45 -080044 intake::IntakeSide intake_left_;
45 intake::IntakeSide intake_right_;
Austin Schuhcb091712018-02-21 20:01:55 -080046 arm::Arm arm_;
Sabina Davis8d20ca82018-02-19 13:17:45 -080047
Neil Balchba9cbba2018-04-06 22:26:38 -070048 // The last centering error. This is the distance that the center of the two
49 // intakes is away from 0.
50 double last_intake_center_error_ = 0.0;
51 // The last distance that the box distance lidar measured.
52 double last_box_distance_ = 0.0;
53 // State variable for the box velocity low pass filter.
54 double filtered_box_velocity_ = 0.0;
55
Austin Schuh17dd0892018-03-02 20:06:31 -080056 enum class RotationState {
57 NOT_ROTATING = 0,
58 ROTATING_LEFT = 1,
Neil Balchba9cbba2018-04-06 22:26:38 -070059 ROTATING_RIGHT = 2,
60 STUCK = 3
Austin Schuh17dd0892018-03-02 20:06:31 -080061 };
62
63 RotationState rotation_state_ = RotationState::NOT_ROTATING;
64 int rotation_count_ = 0;
Neil Balchba9cbba2018-04-06 22:26:38 -070065 int stuck_count_ = 0;
66 ::aos::monotonic_clock::time_point last_stuck_time_ =
67 ::aos::monotonic_clock::min_time;
68 ::aos::monotonic_clock::time_point last_unstuck_time_ =
69 ::aos::monotonic_clock::min_time;
Austin Schuh17dd0892018-03-02 20:06:31 -080070
Sabina Davis8d20ca82018-02-19 13:17:45 -080071 DISALLOW_COPY_AND_ASSIGN(Superstructure);
72};
73
74} // namespace superstructure
75} // namespace control_loops
76} // namespace y2018
77
78#endif // Y2018_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_