Sabina Davis | 4b63ae5 | 2019-01-27 16:15:25 -0800 | [diff] [blame] | 1 | #ifndef Y2019_CONTROL_LOOPS_SUPERSTRUCTURE_COLLISION_AVOIDANCE_H_ |
| 2 | #define Y2019_CONTROL_LOOPS_SUPERSTRUCTURE_COLLISION_AVOIDANCE_H_ |
| 3 | |
| 4 | #include <cmath> |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 5 | |
Sabina Davis | 4b63ae5 | 2019-01-27 16:15:25 -0800 | [diff] [blame] | 6 | #include "frc971/constants.h" |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 7 | #include "frc971/control_loops/control_loops_generated.h" |
| 8 | #include "frc971/control_loops/profiled_subsystem_generated.h" |
| 9 | #include "y2019/control_loops/superstructure/superstructure_goal_generated.h" |
| 10 | #include "y2019/control_loops/superstructure/superstructure_status_generated.h" |
Sabina Davis | 4b63ae5 | 2019-01-27 16:15:25 -0800 | [diff] [blame] | 11 | |
| 12 | namespace y2019 { |
| 13 | namespace control_loops { |
| 14 | namespace superstructure { |
| 15 | |
| 16 | // CollisionAvoidance computes the min and max allowable ranges for various |
| 17 | // subsystems to avoid collisions. It also shoves the elevator up to let the |
| 18 | // intake go in and out, and to let the wrist switch sides. |
| 19 | class CollisionAvoidance { |
| 20 | public: |
| 21 | CollisionAvoidance(); |
| 22 | |
| 23 | // Reports if the superstructure is collided. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 24 | bool IsCollided(const Status *status); |
Austin Schuh | 9fe68f7 | 2019-08-10 19:32:03 -0700 | [diff] [blame] | 25 | bool IsCollided(double wrist_position, double elevator_position, |
| 26 | double intake_position, bool has_piece); |
Sabina Davis | 4b63ae5 | 2019-01-27 16:15:25 -0800 | [diff] [blame] | 27 | |
| 28 | // Checks and alters goals to make sure they're safe. |
| 29 | // TODO(austin): Either we will have a unit delay because this has to happen |
| 30 | // after the controls, or we need to be more clever about restructuring. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 31 | void UpdateGoal(const Status *status, const Goal *unsafe_goal); |
Sabina Davis | 4b63ae5 | 2019-01-27 16:15:25 -0800 | [diff] [blame] | 32 | |
| 33 | // Returns the goals to give to the respective control loops in |
| 34 | // superstructure. |
| 35 | double min_wrist_goal() const { return min_wrist_goal_; } |
| 36 | double max_wrist_goal() const { return max_wrist_goal_; } |
| 37 | double min_elevator_goal() const { return min_elevator_goal_; } |
| 38 | double min_intake_goal() const { return min_intake_goal_; } |
| 39 | double max_intake_goal() const { return max_intake_goal_; } |
| 40 | |
| 41 | void update_max_wrist_goal(double max_wrist_goal) { |
| 42 | max_wrist_goal_ = ::std::min(max_wrist_goal, max_wrist_goal_); |
| 43 | } |
| 44 | void update_min_wrist_goal(double min_wrist_goal) { |
| 45 | min_wrist_goal_ = ::std::max(min_wrist_goal, min_wrist_goal_); |
| 46 | } |
| 47 | void update_max_intake_goal(double max_intake_goal) { |
| 48 | max_intake_goal_ = ::std::min(max_intake_goal, max_intake_goal_); |
| 49 | } |
| 50 | void update_min_intake_goal(double min_intake_goal) { |
| 51 | min_intake_goal_ = ::std::max(min_intake_goal, min_intake_goal_); |
| 52 | } |
| 53 | void update_min_elevator_goal(double min_elevator_goal) { |
| 54 | min_elevator_goal_ = ::std::max(min_elevator_goal, min_elevator_goal_); |
| 55 | } |
| 56 | |
Sabina Davis | 4b63ae5 | 2019-01-27 16:15:25 -0800 | [diff] [blame] | 57 | // Height above which we can move the wrist freely. |
Austin Schuh | ed7f863 | 2019-02-15 23:12:20 -0800 | [diff] [blame] | 58 | static constexpr double kElevatorClearHeight = 0.35; |
Sabina Davis | 4b63ae5 | 2019-01-27 16:15:25 -0800 | [diff] [blame] | 59 | |
| 60 | // Height above which we can move the wrist down. |
Austin Schuh | ed7f863 | 2019-02-15 23:12:20 -0800 | [diff] [blame] | 61 | static constexpr double kElevatorClearWristDownHeight = 0.25; |
Sabina Davis | 4b63ae5 | 2019-01-27 16:15:25 -0800 | [diff] [blame] | 62 | // Height the carriage needs to be above to move the intake. |
| 63 | static constexpr double kElevatorClearIntakeHeight = 0.4; |
| 64 | |
| 65 | // Angle constraints for the wrist when below kElevatorClearDownHeight |
Austin Schuh | 2bf322b | 2019-04-13 23:07:40 -0700 | [diff] [blame] | 66 | static constexpr double kWristMaxAngle = M_PI / 2.0 + 0.15; |
Austin Schuh | 899a49d | 2019-03-22 21:18:49 -0700 | [diff] [blame] | 67 | static constexpr double kWristMinAngle = -M_PI / 2.0 - 0.25; |
Sabina Davis | 4b63ae5 | 2019-01-27 16:15:25 -0800 | [diff] [blame] | 68 | |
| 69 | // Angles outside of which the intake is fully clear of the wrist. |
Austin Schuh | ed7f863 | 2019-02-15 23:12:20 -0800 | [diff] [blame] | 70 | static constexpr double kIntakeOutAngle = 0.3; |
| 71 | static constexpr double kIntakeInAngle = -1.1; |
Sabina Davis | 4b63ae5 | 2019-01-27 16:15:25 -0800 | [diff] [blame] | 72 | |
| 73 | // Angles within which we will crash the wrist into the elevator if the |
| 74 | // elevator is below kElevatorClearHeight. |
| 75 | static constexpr double kWristElevatorCollisionMinAngle = -M_PI / 4.0; |
| 76 | static constexpr double kWristElevatorCollisionMaxAngle = M_PI / 4.0; |
Tyler Chatow | d180b25 | 2019-02-23 22:00:20 -0800 | [diff] [blame] | 77 | static constexpr double kWristElevatorCollisionMaxAngleWithoutObject = M_PI / 6.0; |
Sabina Davis | 4b63ae5 | 2019-01-27 16:15:25 -0800 | [diff] [blame] | 78 | |
| 79 | // Tolerance for the elevator. |
| 80 | static constexpr double kEps = 0.02; |
| 81 | // Tolerance for the intake. |
| 82 | static constexpr double kEpsIntake = 0.05; |
| 83 | // Tolerance for the wrist. |
| 84 | static constexpr double kEpsWrist = 0.05; |
| 85 | |
| 86 | private: |
| 87 | void clear_min_wrist_goal() { |
| 88 | min_wrist_goal_ = -::std::numeric_limits<double>::infinity(); |
| 89 | } |
| 90 | void clear_max_wrist_goal() { |
| 91 | max_wrist_goal_ = ::std::numeric_limits<double>::infinity(); |
| 92 | } |
| 93 | void clear_min_elevator_goal() { |
| 94 | min_elevator_goal_ = -::std::numeric_limits<double>::infinity(); |
| 95 | } |
| 96 | void clear_min_intake_goal() { |
| 97 | min_intake_goal_ = -::std::numeric_limits<double>::infinity(); |
| 98 | } |
| 99 | void clear_max_intake_goal() { |
| 100 | max_intake_goal_ = ::std::numeric_limits<double>::infinity(); |
| 101 | } |
| 102 | |
| 103 | double min_wrist_goal_; |
| 104 | double max_wrist_goal_; |
| 105 | double min_elevator_goal_; |
| 106 | double min_intake_goal_; |
| 107 | double max_intake_goal_; |
| 108 | }; |
| 109 | |
| 110 | } // namespace superstructure |
| 111 | } // namespace control_loops |
| 112 | } // namespace y2019 |
| 113 | |
| 114 | #endif // Y2019_CONTROL_LOOPS_SUPERSTRUCTURE_COLLISION_AVOIDANCE_H_ |