blob: 7947f7ab0df892670cd71fc2d2c90b8715c51afe [file] [log] [blame]
James Kuszmaulcdd033e2013-03-02 15:10:43 -08001#ifndef FRC971_CONTROL_LOOPS_SHOOTER_H_
2#define FRC971_CONTROL_LOOPS_SHOOTER_H_
3
4#include <memory>
5
6#include "aos/common/control_loop/ControlLoop.h"
7#include "frc971/control_loops/state_feedback_loop.h"
Austin Schuhc682d612013-03-03 14:32:52 -08008#include "frc971/control_loops/shooter/shooter_motor.q.h"
9#include "frc971/control_loops/shooter/shooter_motor_plant.h"
James Kuszmaulcdd033e2013-03-02 15:10:43 -080010
11namespace frc971 {
12namespace control_loops {
13
14class ShooterMotor
15 : public aos::control_loops::ControlLoop<control_loops::ShooterLoop> {
16 public:
17 explicit ShooterMotor(
18 control_loops::ShooterLoop *my_shooter = &control_loops::shooter);
19
Austin Schuh0e38a5d2013-03-03 03:53:35 -080020 // Control loop time step.
21 static const double dt;
22
23 // Maximum speed of the shooter wheel which the encoder is rated for in
24 // rad/sec.
25 static const double kMaxSpeed;
26
James Kuszmaulcdd033e2013-03-02 15:10:43 -080027 protected:
28 virtual void RunIteration(
29 const control_loops::ShooterLoop::Goal *goal,
30 const control_loops::ShooterLoop::Position *position,
31 ::aos::control_loops::Output *output,
32 control_loops::ShooterLoop::Status *status);
Austin Schuh0e38a5d2013-03-03 03:53:35 -080033
James Kuszmaulcdd033e2013-03-02 15:10:43 -080034 private:
James Kuszmaulcdd033e2013-03-02 15:10:43 -080035 // The state feedback control loop to talk to.
36 ::std::unique_ptr<StateFeedbackLoop<2, 1, 1>> loop_;
37
38 // History array and stuff for determining average velocity and whether
39 // we are ready to shoot.
Austin Schuh0e38a5d2013-03-03 03:53:35 -080040 static const int kHistoryLength = 5;
41 double history_[kHistoryLength];
James Kuszmaulcdd033e2013-03-02 15:10:43 -080042 ptrdiff_t history_position_;
43 double average_velocity_;
44
45 double position_goal_;
Austin Schuh0e38a5d2013-03-03 03:53:35 -080046 double last_position_;
James Kuszmaulcdd033e2013-03-02 15:10:43 -080047
Brian Silverman7ffb1382013-09-29 16:55:12 -070048 // For making sure it keeps spinning if we're shooting.
49 double last_velocity_goal_;
50
James Kuszmaulcdd033e2013-03-02 15:10:43 -080051 DISALLOW_COPY_AND_ASSIGN(ShooterMotor);
52};
53
54} // namespace control_loops
55} // namespace frc971
56
57#endif // FRC971_CONTROL_LOOPS_SHOOTER_H_