blob: 1ba7eeee30fb333be73902712fc693df4deb4a9e [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
18 PolyDrivetrain(const DrivetrainConfig &dt_config);
19
20 int controller_index() const { return loop_->controller_index(); }
21
22 bool IsInGear(Gear gear) { return gear == LOW || gear == HIGH; }
23
24 // Computes the speed of the motor given the hall effect position and the
25 // speed of the robot.
26 double MotorSpeed(const constants::ShifterHallEffect &hall_effect,
27 double shifter_position, double velocity);
28
29 // Computes the states of the shifters for the left and right drivetrain sides
30 // given a requested state.
31 void UpdateGears(Gear requested_gear);
32
33 // Computes the next state of a shifter given the current state and the
34 // requested state.
35 Gear UpdateSingleGear(Gear requested_gear, Gear current_gear);
36
37 void SetGoal(double wheel, double throttle, bool quickturn, bool highgear);
38
39 void SetPosition(
40 const ::frc971::control_loops::DrivetrainQueue::Position *position);
41
42 double FilterVelocity(double throttle);
43
44 double MaxVelocity();
45
46 void Update();
47
48 void SendMotors(::frc971::control_loops::DrivetrainQueue::Output *output);
49
50 private:
51 StateFeedbackLoop<7, 2, 3> kf_;
52
53 const ::aos::controls::HPolytope<2> U_Poly_;
54
55 ::std::unique_ptr<StateFeedbackLoop<2, 2, 2>> loop_;
56
57 const double ttrust_;
58 double wheel_;
59 double throttle_;
60 bool quickturn_;
61 int stale_count_;
62 double position_time_delta_;
63 Gear left_gear_;
64 Gear right_gear_;
65 ::frc971::control_loops::DrivetrainQueue::Position last_position_;
66 ::frc971::control_loops::DrivetrainQueue::Position position_;
67 int counter_;
68 DrivetrainConfig dt_config_;
69};
70
71} // namespace drivetrain
72} // namespace control_loops
73} // namespace frc971
74
75#endif // FRC971_CONTROL_LOOPS_DRIVETRAIN_POLYDRIVETRAIN_H_