blob: ac88cece3af1facfdd02a7406b84b82912304c65 [file] [log] [blame]
Sabina Davis4b63ae52019-01-27 16:15:25 -08001#ifndef Y2019_CONTROL_LOOPS_SUPERSTRUCTURE_COLLISION_AVOIDANCE_H_
2#define Y2019_CONTROL_LOOPS_SUPERSTRUCTURE_COLLISION_AVOIDANCE_H_
3
4#include <cmath>
Alex Perrycb7da4b2019-08-28 19:35:56 -07005
Sabina Davis4b63ae52019-01-27 16:15:25 -08006#include "frc971/constants.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -07007#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 Davis4b63ae52019-01-27 16:15:25 -080011
12namespace y2019 {
13namespace control_loops {
14namespace 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.
19class CollisionAvoidance {
20 public:
21 CollisionAvoidance();
22
23 // Reports if the superstructure is collided.
Alex Perrycb7da4b2019-08-28 19:35:56 -070024 bool IsCollided(const Status *status);
Austin Schuh9fe68f72019-08-10 19:32:03 -070025 bool IsCollided(double wrist_position, double elevator_position,
26 double intake_position, bool has_piece);
Sabina Davis4b63ae52019-01-27 16:15:25 -080027
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 Perrycb7da4b2019-08-28 19:35:56 -070031 void UpdateGoal(const Status *status, const Goal *unsafe_goal);
Sabina Davis4b63ae52019-01-27 16:15:25 -080032
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 Davis4b63ae52019-01-27 16:15:25 -080057 // Height above which we can move the wrist freely.
Austin Schuhed7f8632019-02-15 23:12:20 -080058 static constexpr double kElevatorClearHeight = 0.35;
Sabina Davis4b63ae52019-01-27 16:15:25 -080059
60 // Height above which we can move the wrist down.
Austin Schuhed7f8632019-02-15 23:12:20 -080061 static constexpr double kElevatorClearWristDownHeight = 0.25;
Sabina Davis4b63ae52019-01-27 16:15:25 -080062 // 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 Schuh2bf322b2019-04-13 23:07:40 -070066 static constexpr double kWristMaxAngle = M_PI / 2.0 + 0.15;
Austin Schuh899a49d2019-03-22 21:18:49 -070067 static constexpr double kWristMinAngle = -M_PI / 2.0 - 0.25;
Sabina Davis4b63ae52019-01-27 16:15:25 -080068
69 // Angles outside of which the intake is fully clear of the wrist.
Austin Schuhed7f8632019-02-15 23:12:20 -080070 static constexpr double kIntakeOutAngle = 0.3;
71 static constexpr double kIntakeInAngle = -1.1;
Sabina Davis4b63ae52019-01-27 16:15:25 -080072
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;
Philipp Schrader790cb542023-07-05 21:06:52 -070077 static constexpr double kWristElevatorCollisionMaxAngleWithoutObject =
78 M_PI / 6.0;
Sabina Davis4b63ae52019-01-27 16:15:25 -080079
80 // Tolerance for the elevator.
81 static constexpr double kEps = 0.02;
82 // Tolerance for the intake.
83 static constexpr double kEpsIntake = 0.05;
84 // Tolerance for the wrist.
85 static constexpr double kEpsWrist = 0.05;
86
87 private:
88 void clear_min_wrist_goal() {
89 min_wrist_goal_ = -::std::numeric_limits<double>::infinity();
90 }
91 void clear_max_wrist_goal() {
92 max_wrist_goal_ = ::std::numeric_limits<double>::infinity();
93 }
94 void clear_min_elevator_goal() {
95 min_elevator_goal_ = -::std::numeric_limits<double>::infinity();
96 }
97 void clear_min_intake_goal() {
98 min_intake_goal_ = -::std::numeric_limits<double>::infinity();
99 }
100 void clear_max_intake_goal() {
101 max_intake_goal_ = ::std::numeric_limits<double>::infinity();
102 }
103
104 double min_wrist_goal_;
105 double max_wrist_goal_;
106 double min_elevator_goal_;
107 double min_intake_goal_;
108 double max_intake_goal_;
109};
110
111} // namespace superstructure
112} // namespace control_loops
113} // namespace y2019
114
115#endif // Y2019_CONTROL_LOOPS_SUPERSTRUCTURE_COLLISION_AVOIDANCE_H_