blob: 9ee7a27b0ae7a54e82ed9ee96197170a327308d7 [file] [log] [blame]
brians343bc112013-02-10 01:53:46 +00001#ifndef FRC971_CONTROL_LOOPS_DRIVETRAIN_H_
2#define FRC971_CONTROL_LOOPS_DRIVETRAIN_H_
3
Austin Schuh2054f5f2013-10-27 14:54:10 -07004#include "Eigen/Dense"
5
6#include "aos/controls/polytope.h"
brians343bc112013-02-10 01:53:46 +00007#include "aos/common/control_loop/ControlLoop.h"
Brian Silverman718b1d72013-10-28 16:22:45 -07008#include "aos/controls/polytope.h"
James Kuszmaulf254c1a2013-03-10 16:31:26 -07009#include "frc971/control_loops/drivetrain/drivetrain.q.h"
Brian Silverman50a9d032014-02-16 17:20:57 -080010#include "aos/common/util/log_interval.h"
brians343bc112013-02-10 01:53:46 +000011
12namespace frc971 {
13namespace control_loops {
14
Austin Schuh2054f5f2013-10-27 14:54:10 -070015Eigen::Matrix<double, 2, 1> CoerceGoal(aos::controls::HPolytope<2> &region,
16 const Eigen::Matrix<double, 1, 2> &K,
17 double w,
18 const Eigen::Matrix<double, 2, 1> &R);
19
brians343bc112013-02-10 01:53:46 +000020class DrivetrainLoop
Brian Silverman10f997b2013-10-11 18:01:56 -070021 : public aos::control_loops::ControlLoop<control_loops::Drivetrain, true, false> {
brians343bc112013-02-10 01:53:46 +000022 public:
23 // Constructs a control loop which can take a Drivetrain or defaults to the
24 // drivetrain at frc971::control_loops::drivetrain
25 explicit DrivetrainLoop(
26 control_loops::Drivetrain *my_drivetrain = &control_loops::drivetrain)
Brian Silverman10f997b2013-10-11 18:01:56 -070027 : aos::control_loops::ControlLoop<control_loops::Drivetrain, true, false>(
Brian Silverman718b1d72013-10-28 16:22:45 -070028 my_drivetrain) {
29 ::aos::controls::HPolytope<0>::Init();
30 }
brians343bc112013-02-10 01:53:46 +000031
32 protected:
33 // Executes one cycle of the control loop.
34 virtual void RunIteration(
35 const control_loops::Drivetrain::Goal *goal,
36 const control_loops::Drivetrain::Position *position,
37 control_loops::Drivetrain::Output *output,
38 control_loops::Drivetrain::Status *status);
Brian Silverman50a9d032014-02-16 17:20:57 -080039
40 typedef ::aos::util::SimpleLogInterval SimpleLogInterval;
41 SimpleLogInterval no_position_ = SimpleLogInterval(
42 ::aos::time::Time::InSeconds(0.25), WARNING, "no position");
brians343bc112013-02-10 01:53:46 +000043};
44
45} // namespace control_loops
46} // namespace frc971
47
48#endif // FRC971_CONTROL_LOOPS_DRIVETRAIN_H_