blob: 6a3fa4d10e9fa360ee0c353eb1173374e7280185 [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
9#include "y2016/control_loops/shooter/shooter_plant.h"
10#include "y2016/control_loops/shooter/shooter.q.h"
11
12namespace y2016 {
13namespace control_loops {
14
Comran Morshedcde50322016-01-18 15:10:36 +000015namespace {
16// TODO(constants): Update.
17const double kTolerance = 10.0;
18const double kMaxSpeed = 10000.0 * (2.0 * M_PI) / 60.0 * 15.0 / 34.0;
19const double kAngularVelocityWeightScalar = 0.35;
20} // namespace
21
22struct ShooterStatus {
23 double avg_angular_velocity;
24 bool ready;
25};
26
27class ShooterSide {
Comran Morshed2a97bc82016-01-16 17:27:01 +000028 public:
Comran Morshedcde50322016-01-18 15:10:36 +000029 ShooterSide();
Comran Morshed2a97bc82016-01-16 17:27:01 +000030
Comran Morshedcde50322016-01-18 15:10:36 +000031 void SetGoal(double angular_velocity_goal);
32 void EstimatePositionTimestep();
33 void SetPosition(double current_position);
34 const ShooterStatus GetStatus();
35 double GetOutput();
36 void UpdateLoop(bool output_is_null);
Comran Morshed2a97bc82016-01-16 17:27:01 +000037
38 private:
Comran Morshed2a97bc82016-01-16 17:27:01 +000039 ::std::unique_ptr<StateFeedbackLoop<2, 1, 1>> loop_;
40
Comran Morshedcde50322016-01-18 15:10:36 +000041 double current_position_ = 0.0;
42 double position_goal_ = 0.0;
43 double angular_velocity_goal_ = 0.0;
44
45 // History array for calculating a filtered angular velocity.
Comran Morshed2a97bc82016-01-16 17:27:01 +000046 static const int kHistoryLength = 5;
47 double history_[kHistoryLength];
48 ptrdiff_t history_position_;
Comran Morshed2a97bc82016-01-16 17:27:01 +000049
Comran Morshedcde50322016-01-18 15:10:36 +000050 DISALLOW_COPY_AND_ASSIGN(ShooterSide);
51};
Comran Morshed2a97bc82016-01-16 17:27:01 +000052
Comran Morshedcde50322016-01-18 15:10:36 +000053class Shooter
54 : public ::aos::controls::ControlLoop<control_loops::ShooterQueue> {
55 public:
56 explicit Shooter(control_loops::ShooterQueue *shooter_queue =
57 &control_loops::shooter_queue);
58
59 protected:
60 void RunIteration(const control_loops::ShooterQueue::Goal *goal,
61 const control_loops::ShooterQueue::Position *position,
62 control_loops::ShooterQueue::Output *output,
63 control_loops::ShooterQueue::Status *status) override;
64
65 private:
66 ShooterSide left_, right_;
Comran Morshed2a97bc82016-01-16 17:27:01 +000067
68 DISALLOW_COPY_AND_ASSIGN(Shooter);
69};
70
71} // namespace control_loops
72} // namespace y2016
73
74#endif // Y2016_CONTROL_LOOPS_SHOOTER_SHOOTER_H_