brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 1 | #ifndef FRC971_CONTROL_LOOPS_DRIVETRAIN_H_ |
| 2 | #define FRC971_CONTROL_LOOPS_DRIVETRAIN_H_ |
| 3 | |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 4 | #include "Eigen/Dense" |
| 5 | |
| 6 | #include "aos/controls/polytope.h" |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 7 | #include "aos/common/control_loop/ControlLoop.h" |
Brian Silverman | 718b1d7 | 2013-10-28 16:22:45 -0700 | [diff] [blame] | 8 | #include "aos/controls/polytope.h" |
James Kuszmaul | f254c1a | 2013-03-10 16:31:26 -0700 | [diff] [blame] | 9 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
Brian Silverman | 50a9d03 | 2014-02-16 17:20:57 -0800 | [diff] [blame^] | 10 | #include "aos/common/util/log_interval.h" |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 11 | |
| 12 | namespace frc971 { |
| 13 | namespace control_loops { |
| 14 | |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 15 | Eigen::Matrix<double, 2, 1> CoerceGoal(aos::controls::HPolytope<2> ®ion, |
| 16 | const Eigen::Matrix<double, 1, 2> &K, |
| 17 | double w, |
| 18 | const Eigen::Matrix<double, 2, 1> &R); |
| 19 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 20 | class DrivetrainLoop |
Brian Silverman | 10f997b | 2013-10-11 18:01:56 -0700 | [diff] [blame] | 21 | : public aos::control_loops::ControlLoop<control_loops::Drivetrain, true, false> { |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 22 | 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 Silverman | 10f997b | 2013-10-11 18:01:56 -0700 | [diff] [blame] | 27 | : aos::control_loops::ControlLoop<control_loops::Drivetrain, true, false>( |
Brian Silverman | 718b1d7 | 2013-10-28 16:22:45 -0700 | [diff] [blame] | 28 | my_drivetrain) { |
| 29 | ::aos::controls::HPolytope<0>::Init(); |
| 30 | } |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 31 | |
| 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 Silverman | 50a9d03 | 2014-02-16 17:20:57 -0800 | [diff] [blame^] | 39 | |
| 40 | typedef ::aos::util::SimpleLogInterval SimpleLogInterval; |
| 41 | SimpleLogInterval no_position_ = SimpleLogInterval( |
| 42 | ::aos::time::Time::InSeconds(0.25), WARNING, "no position"); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | } // namespace control_loops |
| 46 | } // namespace frc971 |
| 47 | |
| 48 | #endif // FRC971_CONTROL_LOOPS_DRIVETRAIN_H_ |