Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 1 | #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 | |
| 10 | namespace frc971 { |
| 11 | namespace control_loops { |
| 12 | namespace drivetrain { |
| 13 | |
| 14 | class PolyDrivetrain { |
| 15 | public: |
| 16 | enum Gear { HIGH, LOW, SHIFTING_UP, SHIFTING_DOWN }; |
| 17 | |
Austin Schuh | 4156560 | 2016-02-28 20:10:49 -0800 | [diff] [blame^] | 18 | PolyDrivetrain(const DrivetrainConfig &dt_config, |
| 19 | StateFeedbackLoop<7, 2, 3> *kf); |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 20 | |
| 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 Schuh | 746fc6d | 2016-02-21 02:53:33 -0800 | [diff] [blame] | 28 | double shifter_position, double velocity, Gear gear); |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 29 | |
| 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 Schuh | 4156560 | 2016-02-28 20:10:49 -0800 | [diff] [blame^] | 43 | double FilterVelocity(double throttle) const; |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 44 | |
| 45 | double MaxVelocity(); |
| 46 | |
| 47 | void Update(); |
| 48 | |
| 49 | void SendMotors(::frc971::control_loops::DrivetrainQueue::Output *output); |
| 50 | |
Austin Schuh | 4156560 | 2016-02-28 20:10:49 -0800 | [diff] [blame^] | 51 | void PopulateStatus(::frc971::control_loops::DrivetrainQueue::Status *status); |
| 52 | |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 53 | private: |
Austin Schuh | 4156560 | 2016-02-28 20:10:49 -0800 | [diff] [blame^] | 54 | StateFeedbackLoop<7, 2, 3> *kf_; |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 55 | |
| 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 Schuh | 4156560 | 2016-02-28 20:10:49 -0800 | [diff] [blame^] | 72 | |
| 73 | double goal_left_velocity_ = 0.0; |
| 74 | double goal_right_velocity_ = 0.0; |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | } // namespace drivetrain |
| 78 | } // namespace control_loops |
| 79 | } // namespace frc971 |
| 80 | |
| 81 | #endif // FRC971_CONTROL_LOOPS_DRIVETRAIN_POLYDRIVETRAIN_H_ |