blob: f26c42db236d12c48127d9979ecf3dc521ffa4fd [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"
8#include "frc971/control_loops/shooter_motor.q.h"
9#include "frc971/control_loops/shooter_motor_plant.h"
10
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
20 protected:
21 virtual void RunIteration(
22 const control_loops::ShooterLoop::Goal *goal,
23 const control_loops::ShooterLoop::Position *position,
24 ::aos::control_loops::Output *output,
25 control_loops::ShooterLoop::Status *status);
26 private:
27 // Timestep of the control loop (in seconds)
28 static constexpr double dt = 0.01;
29
30 // Maximum speed of the shooter wheel which the encoder is rated for.
31 // 10000 rpm * (2 * M_PI radians / rotation) / (60 sec / min) * 15 / 34
32 static constexpr double max_speed = 461.998919646;
33
34 // The state feedback control loop to talk to.
35 ::std::unique_ptr<StateFeedbackLoop<2, 1, 1>> loop_;
36
37 // History array and stuff for determining average velocity and whether
38 // we are ready to shoot.
39 static const int kHistoryLength = 10;
40 double history[kHistoryLength];
41 ptrdiff_t history_position_;
42 double average_velocity_;
43
44 double position_goal_;
45
46 // time_ is used for recording data so that we have a time.
47 double time_;
48
49 DISALLOW_COPY_AND_ASSIGN(ShooterMotor);
50};
51
52} // namespace control_loops
53} // namespace frc971
54
55#endif // FRC971_CONTROL_LOOPS_SHOOTER_H_