blob: 689e76f76d0c627f454efed795c02c410058b2e4 [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
6#include "frc971/control_loops/drivetrain/drivetrain.q.h"
7#include "frc971/control_loops/state_feedback_loop.h"
8#include "frc971/control_loops/drivetrain/drivetrain_config.h"
9
10namespace frc971 {
11namespace control_loops {
12namespace drivetrain {
13
14class PolyDrivetrain {
15 public:
16 enum Gear { HIGH, LOW, SHIFTING_UP, SHIFTING_DOWN };
17
Austin Schuh41565602016-02-28 20:10:49 -080018 PolyDrivetrain(const DrivetrainConfig &dt_config,
19 StateFeedbackLoop<7, 2, 3> *kf);
Comran Morshed5323ecb2015-12-26 20:50:55 +000020
21 int controller_index() const { return loop_->controller_index(); }
22
23 bool IsInGear(Gear gear) { return gear == LOW || gear == HIGH; }
24
25 // Computes the speed of the motor given the hall effect position and the
26 // speed of the robot.
27 double MotorSpeed(const constants::ShifterHallEffect &hall_effect,
Austin Schuh746fc6d2016-02-21 02:53:33 -080028 double shifter_position, double velocity, Gear gear);
Comran Morshed5323ecb2015-12-26 20:50:55 +000029
30 // Computes the states of the shifters for the left and right drivetrain sides
31 // given a requested state.
32 void UpdateGears(Gear requested_gear);
33
34 // Computes the next state of a shifter given the current state and the
35 // requested state.
36 Gear UpdateSingleGear(Gear requested_gear, Gear current_gear);
37
38 void SetGoal(double wheel, double throttle, bool quickturn, bool highgear);
39
40 void SetPosition(
41 const ::frc971::control_loops::DrivetrainQueue::Position *position);
42
Austin Schuh41565602016-02-28 20:10:49 -080043 double FilterVelocity(double throttle) const;
Comran Morshed5323ecb2015-12-26 20:50:55 +000044
45 double MaxVelocity();
46
47 void Update();
48
49 void SendMotors(::frc971::control_loops::DrivetrainQueue::Output *output);
50
Austin Schuh41565602016-02-28 20:10:49 -080051 void PopulateStatus(::frc971::control_loops::DrivetrainQueue::Status *status);
52
Comran Morshed5323ecb2015-12-26 20:50:55 +000053 private:
Austin Schuh41565602016-02-28 20:10:49 -080054 StateFeedbackLoop<7, 2, 3> *kf_;
Comran Morshed5323ecb2015-12-26 20:50:55 +000055
56 const ::aos::controls::HPolytope<2> U_Poly_;
57
58 ::std::unique_ptr<StateFeedbackLoop<2, 2, 2>> loop_;
59
60 const double ttrust_;
61 double wheel_;
62 double throttle_;
63 bool quickturn_;
64 int stale_count_;
65 double position_time_delta_;
66 Gear left_gear_;
67 Gear right_gear_;
68 ::frc971::control_loops::DrivetrainQueue::Position last_position_;
69 ::frc971::control_loops::DrivetrainQueue::Position position_;
70 int counter_;
71 DrivetrainConfig dt_config_;
Austin Schuh41565602016-02-28 20:10:49 -080072
73 double goal_left_velocity_ = 0.0;
74 double goal_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_