blob: f79a9939d0cc2c3c7db09ffc0adc94ff2b26acfe [file] [log] [blame]
Austin Schuh64ebab22015-11-26 13:28:30 -08001#ifndef Y2014_CONTROL_LOOPS_DRIVETRAIN_SSDRIVETRAIN_H_
2#define Y2014_CONTROL_LOOPS_DRIVETRAIN_SSDRIVETRAIN_H_
3
4#include "aos/common/controls/polytope.h"
5#include "aos/common/commonmath.h"
6#include "aos/common/logging/matrix_logging.h"
7
8#include "frc971/control_loops/state_feedback_loop.h"
9#include "frc971/control_loops/coerce_goal.h"
10#include "y2014/constants.h"
11#include "y2014/control_loops/drivetrain/drivetrain.q.h"
12
Austin Schuh6197a182015-11-28 16:04:40 -080013namespace y2014 {
Austin Schuh64ebab22015-11-26 13:28:30 -080014namespace control_loops {
Austin Schuh6197a182015-11-28 16:04:40 -080015namespace drivetrain {
Austin Schuh64ebab22015-11-26 13:28:30 -080016
17class DrivetrainMotorsSS {
18 public:
19 class LimitedDrivetrainLoop : public StateFeedbackLoop<4, 2, 2> {
20 public:
21 LimitedDrivetrainLoop(StateFeedbackLoop<4, 2, 2> &&loop);
22
23 bool output_was_capped() const {
24 return output_was_capped_;
25 }
26
27 private:
28 void CapU() override;
29
30 const ::aos::controls::HPolytope<2> U_Poly_;
31 Eigen::Matrix<double, 2, 2> T, T_inverse;
32 bool output_was_capped_ = false;;
33 };
34
35 DrivetrainMotorsSS();
36
37 void SetGoal(double left, double left_velocity, double right,
38 double right_velocity);
39
40 void SetRawPosition(double left, double right);
41
42 void SetPosition(double left, double right, double gyro);
43
44 void SetExternalMotors(double left_voltage, double right_voltage);
45
46 void Update(bool stop_motors, bool enable_control_loop);
47
48 double GetEstimatedRobotSpeed() const;
49
50 double GetEstimatedLeftEncoder() const {
51 return loop_->X_hat(0, 0);
52 }
53
54 double GetEstimatedRightEncoder() const {
55 return loop_->X_hat(2, 0);
56 }
57
58 bool OutputWasCapped() const {
59 return loop_->output_was_capped();
60 }
61
Austin Schuh6197a182015-11-28 16:04:40 -080062 void SendMotors(
63 ::frc971::control_loops::DrivetrainQueue::Output *output) const;
Austin Schuh64ebab22015-11-26 13:28:30 -080064
65 const LimitedDrivetrainLoop &loop() const { return *loop_; }
66
67 private:
68 ::std::unique_ptr<LimitedDrivetrainLoop> loop_;
69
70 double filtered_offset_;
71 double gyro_;
72 double left_goal_;
73 double right_goal_;
74 double raw_left_;
75 double raw_right_;
76};
77
Austin Schuh6197a182015-11-28 16:04:40 -080078} // namespace drivetrain
Austin Schuh64ebab22015-11-26 13:28:30 -080079} // namespace control_loops
Austin Schuh6197a182015-11-28 16:04:40 -080080} // namespace y2014
Austin Schuh64ebab22015-11-26 13:28:30 -080081
82#endif // Y2014_CONTROL_LOOPS_DRIVETRAIN_SSDRIVETRAIN_H_