blob: 070b7eb11298f5c02ea53d2b98d3b9a01360287d [file] [log] [blame]
Comran Morshed5323ecb2015-12-26 20:50:55 +00001#ifndef FRC971_CONTROL_LOOPS_DRIVETRAIN_POLYDRIVETRAIN_H_
2#define FRC971_CONTROL_LOOPS_DRIVETRAIN_POLYDRIVETRAIN_H_
3
4#include "aos/common/controls/polytope.h"
5
Austin Schuh093535c2016-03-05 23:21:00 -08006#include "frc971/control_loops/drivetrain/gear.h"
Comran Morshed5323ecb2015-12-26 20:50:55 +00007#include "frc971/control_loops/drivetrain/drivetrain.q.h"
8#include "frc971/control_loops/state_feedback_loop.h"
9#include "frc971/control_loops/drivetrain/drivetrain_config.h"
10
11namespace frc971 {
12namespace control_loops {
13namespace drivetrain {
14
15class PolyDrivetrain {
16 public:
Austin Schuh41565602016-02-28 20:10:49 -080017 PolyDrivetrain(const DrivetrainConfig &dt_config,
18 StateFeedbackLoop<7, 2, 3> *kf);
Comran Morshed5323ecb2015-12-26 20:50:55 +000019
Austin Schuhc5fceb82017-02-25 16:24:12 -080020 int controller_index() const { return loop_->index(); }
Comran Morshed5323ecb2015-12-26 20:50:55 +000021
Comran Morshed5323ecb2015-12-26 20:50:55 +000022 // Computes the speed of the motor given the hall effect position and the
23 // speed of the robot.
24 double MotorSpeed(const constants::ShifterHallEffect &hall_effect,
Austin Schuh746fc6d2016-02-21 02:53:33 -080025 double shifter_position, double velocity, Gear gear);
Comran Morshed5323ecb2015-12-26 20:50:55 +000026
Austin Schuh093535c2016-03-05 23:21:00 -080027 void SetGoal(const ::frc971::control_loops::DrivetrainQueue::Goal &goal);
Comran Morshed5323ecb2015-12-26 20:50:55 +000028
29 void SetPosition(
Austin Schuh093535c2016-03-05 23:21:00 -080030 const ::frc971::control_loops::DrivetrainQueue::Position *position,
31 Gear left_gear, Gear right_gear);
Comran Morshed5323ecb2015-12-26 20:50:55 +000032
Austin Schuh41565602016-02-28 20:10:49 -080033 double FilterVelocity(double throttle) const;
Comran Morshed5323ecb2015-12-26 20:50:55 +000034
35 double MaxVelocity();
36
37 void Update();
38
Austin Schuh093535c2016-03-05 23:21:00 -080039 void SetOutput(::frc971::control_loops::DrivetrainQueue::Output *output);
Comran Morshed5323ecb2015-12-26 20:50:55 +000040
Austin Schuh41565602016-02-28 20:10:49 -080041 void PopulateStatus(::frc971::control_loops::DrivetrainQueue::Status *status);
42
Austin Schuh093535c2016-03-05 23:21:00 -080043 // Computes the next state of a shifter given the current state and the
44 // requested state.
45 Gear UpdateSingleGear(Gear requested_gear, Gear current_gear);
46
Comran Morshed5323ecb2015-12-26 20:50:55 +000047 private:
Austin Schuh41565602016-02-28 20:10:49 -080048 StateFeedbackLoop<7, 2, 3> *kf_;
Comran Morshed5323ecb2015-12-26 20:50:55 +000049
Austin Schuhc7a0a3d2016-10-15 16:22:47 -070050 const ::aos::controls::HVPolytope<2, 4, 4> U_Poly_;
Comran Morshed5323ecb2015-12-26 20:50:55 +000051
52 ::std::unique_ptr<StateFeedbackLoop<2, 2, 2>> loop_;
53
54 const double ttrust_;
55 double wheel_;
56 double throttle_;
57 bool quickturn_;
Austin Schuh093535c2016-03-05 23:21:00 -080058
Comran Morshed5323ecb2015-12-26 20:50:55 +000059 Gear left_gear_;
60 Gear right_gear_;
Austin Schuh093535c2016-03-05 23:21:00 -080061
Comran Morshed5323ecb2015-12-26 20:50:55 +000062 ::frc971::control_loops::DrivetrainQueue::Position last_position_;
63 ::frc971::control_loops::DrivetrainQueue::Position position_;
64 int counter_;
65 DrivetrainConfig dt_config_;
Austin Schuh41565602016-02-28 20:10:49 -080066
67 double goal_left_velocity_ = 0.0;
68 double goal_right_velocity_ = 0.0;
Kyle Stachowicz2f3c20f2017-07-13 16:04:05 -070069
70 // Stored from the last iteration, for logging shifting logic.
71 double left_motor_speed_ = 0.0;
72 double right_motor_speed_ = 0.0;
73 double current_left_velocity_ = 0.0;
74 double current_right_velocity_ = 0.0;
Comran Morshed5323ecb2015-12-26 20:50:55 +000075};
76
77} // namespace drivetrain
78} // namespace control_loops
79} // namespace frc971
80
81#endif // FRC971_CONTROL_LOOPS_DRIVETRAIN_POLYDRIVETRAIN_H_