blob: 0354bb5d1c78cbf31fb37d32b8e4a93e3f21169d [file] [log] [blame]
Comran Morshed2a97bc82016-01-16 17:27:01 +00001#ifndef Y2016_CONTROL_LOOPS_SHOOTER_SHOOTER_H_
2#define Y2016_CONTROL_LOOPS_SHOOTER_SHOOTER_H_
3
4#include <memory>
5
6#include "aos/common/controls/control_loop.h"
7#include "frc971/control_loops/state_feedback_loop.h"
8
Austin Schuh09c2b0b2016-02-13 15:53:16 -08009#include "y2016/control_loops/shooter/shooter_integral_plant.h"
Comran Morshed2a97bc82016-01-16 17:27:01 +000010#include "y2016/control_loops/shooter/shooter.q.h"
11
12namespace y2016 {
13namespace control_loops {
Austin Schuh09c2b0b2016-02-13 15:53:16 -080014namespace shooter {
Comran Morshed2a97bc82016-01-16 17:27:01 +000015
Comran Morshedcde50322016-01-18 15:10:36 +000016namespace {
Austin Schuh09c2b0b2016-02-13 15:53:16 -080017constexpr double kTolerance = 10.0;
Comran Morshedcde50322016-01-18 15:10:36 +000018} // namespace
19
Comran Morshedcde50322016-01-18 15:10:36 +000020class ShooterSide {
Comran Morshed2a97bc82016-01-16 17:27:01 +000021 public:
Comran Morshedcde50322016-01-18 15:10:36 +000022 ShooterSide();
Comran Morshed2a97bc82016-01-16 17:27:01 +000023
Austin Schuh09c2b0b2016-02-13 15:53:16 -080024 // Sets the velocity goal in radians/sec
25 void set_goal(double angular_velocity_goal);
26 // Sets the current encoder position in radians
27 void set_position(double current_position);
28
29 // Populates the status structure.
30 void SetStatus(ShooterSideStatus *status);
31
32 // Returns the control loop calculated voltage.
33 double voltage() const;
34
35 // Executes the control loop for a cycle.
36 void Update(bool disabled);
Comran Morshed2a97bc82016-01-16 17:27:01 +000037
38 private:
Austin Schuh09c2b0b2016-02-13 15:53:16 -080039 // The current sensor measurement.
40 Eigen::Matrix<double, 1, 1> Y_;
41 // The control loop.
42 ::std::unique_ptr<StateFeedbackLoop<3, 1, 1>> loop_;
Comran Morshedcde50322016-01-18 15:10:36 +000043
44 // History array for calculating a filtered angular velocity.
Austin Schuh09c2b0b2016-02-13 15:53:16 -080045 static constexpr int kHistoryLength = 10;
46 ::std::array<double, kHistoryLength> history_;
Comran Morshed2a97bc82016-01-16 17:27:01 +000047 ptrdiff_t history_position_;
Comran Morshed2a97bc82016-01-16 17:27:01 +000048
Comran Morshedcde50322016-01-18 15:10:36 +000049 DISALLOW_COPY_AND_ASSIGN(ShooterSide);
50};
Comran Morshed2a97bc82016-01-16 17:27:01 +000051
Austin Schuh09c2b0b2016-02-13 15:53:16 -080052class Shooter : public ::aos::controls::ControlLoop<ShooterQueue> {
Comran Morshedcde50322016-01-18 15:10:36 +000053 public:
Austin Schuh09c2b0b2016-02-13 15:53:16 -080054 explicit Shooter(
55 ShooterQueue *shooter_queue = &control_loops::shooter::shooter_queue);
Comran Morshedcde50322016-01-18 15:10:36 +000056
57 protected:
Austin Schuh09c2b0b2016-02-13 15:53:16 -080058 void RunIteration(const ShooterQueue::Goal *goal,
59 const ShooterQueue::Position *position,
60 ShooterQueue::Output *output,
61 ShooterQueue::Status *status) override;
Comran Morshedcde50322016-01-18 15:10:36 +000062
63 private:
64 ShooterSide left_, right_;
Comran Morshed2a97bc82016-01-16 17:27:01 +000065
66 DISALLOW_COPY_AND_ASSIGN(Shooter);
67};
68
Austin Schuh09c2b0b2016-02-13 15:53:16 -080069} // namespace shooter
Comran Morshed2a97bc82016-01-16 17:27:01 +000070} // namespace control_loops
71} // namespace y2016
72
73#endif // Y2016_CONTROL_LOOPS_SHOOTER_SHOOTER_H_