blob: 6fcbca719072eab8a46878251c190c18868426a7 [file] [log] [blame]
Brian Silvermanc71537c2016-01-01 13:43:14 -08001#ifndef Y2014_CONTROL_LOOPS_DRIVETRAIN_H_
2#define Y2014_CONTROL_LOOPS_DRIVETRAIN_H_
3
4#include "Eigen/Dense"
5
6#include "aos/common/controls/polytope.h"
7#include "aos/common/controls/control_loop.h"
8#include "aos/common/controls/polytope.h"
9#include "y2012/control_loops/drivetrain/drivetrain.q.h"
10#include "y2012/control_loops/drivetrain/polydrivetrain.h"
11#include "y2012/control_loops/drivetrain/ssdrivetrain.h"
12#include "aos/common/util/log_interval.h"
13
14namespace y2012 {
15namespace control_loops {
16namespace drivetrain {
17
18class DrivetrainLoop : public aos::controls::ControlLoop<
19 ::y2012::control_loops::DrivetrainQueue> {
20 public:
21 // Constructs a control loop which can take a Drivetrain or defaults to the
22 // drivetrain at y2012::control_loops::drivetrain
23 explicit DrivetrainLoop(
24 ::y2012::control_loops::DrivetrainQueue *my_drivetrain =
25 &::y2012::control_loops::drivetrain_queue);
26
27 protected:
28 // Executes one cycle of the control loop.
29 virtual void RunIteration(
30 const ::y2012::control_loops::DrivetrainQueue::Goal *goal,
31 const ::y2012::control_loops::DrivetrainQueue::Position *position,
32 ::y2012::control_loops::DrivetrainQueue::Output *output,
33 ::y2012::control_loops::DrivetrainQueue::Status *status);
34
35 typedef ::aos::util::SimpleLogInterval SimpleLogInterval;
36 SimpleLogInterval no_position_ = SimpleLogInterval(
37 ::aos::time::Time::InSeconds(0.25), WARNING, "no position");
38 double last_gyro_heading_ = 0.0;
39 double last_gyro_rate_ = 0.0;
40
41 PolyDrivetrain dt_openloop_;
42 DrivetrainMotorsSS dt_closedloop_;
43 StateFeedbackLoop<7, 2, 3> kf_;
44
45 double last_left_voltage_ = 0;
46 double last_right_voltage_ = 0;
47
48 double integrated_kf_heading_ = 0;
49};
50
51} // namespace drivetrain
52} // namespace control_loops
53} // namespace y2012
54
55#endif // Y2014_CONTROL_LOOPS_DRIVETRAIN_H_