blob: 338864e728aba19aed5df8081328fc15b0c40755 [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;
Tyler Chatowd180b252019-02-23 22:00:20 -080077 static constexpr double kWristElevatorCollisionMaxAngleWithoutObject = M_PI / 6.0;
Sabina Davis4b63ae52019-01-27 16:15:25 -080078
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_