blob: e872e8cec7de475b6a3a0bd347392f0a3d8f6810 [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
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080012namespace y2019::control_loops::superstructure {
Sabina Davis4b63ae52019-01-27 16:15:25 -080013
14// CollisionAvoidance computes the min and max allowable ranges for various
15// subsystems to avoid collisions. It also shoves the elevator up to let the
16// intake go in and out, and to let the wrist switch sides.
17class CollisionAvoidance {
18 public:
19 CollisionAvoidance();
20
21 // Reports if the superstructure is collided.
Alex Perrycb7da4b2019-08-28 19:35:56 -070022 bool IsCollided(const Status *status);
Austin Schuh9fe68f72019-08-10 19:32:03 -070023 bool IsCollided(double wrist_position, double elevator_position,
24 double intake_position, bool has_piece);
Sabina Davis4b63ae52019-01-27 16:15:25 -080025
26 // Checks and alters goals to make sure they're safe.
27 // TODO(austin): Either we will have a unit delay because this has to happen
28 // after the controls, or we need to be more clever about restructuring.
Alex Perrycb7da4b2019-08-28 19:35:56 -070029 void UpdateGoal(const Status *status, const Goal *unsafe_goal);
Sabina Davis4b63ae52019-01-27 16:15:25 -080030
31 // Returns the goals to give to the respective control loops in
32 // superstructure.
33 double min_wrist_goal() const { return min_wrist_goal_; }
34 double max_wrist_goal() const { return max_wrist_goal_; }
35 double min_elevator_goal() const { return min_elevator_goal_; }
36 double min_intake_goal() const { return min_intake_goal_; }
37 double max_intake_goal() const { return max_intake_goal_; }
38
39 void update_max_wrist_goal(double max_wrist_goal) {
40 max_wrist_goal_ = ::std::min(max_wrist_goal, max_wrist_goal_);
41 }
42 void update_min_wrist_goal(double min_wrist_goal) {
43 min_wrist_goal_ = ::std::max(min_wrist_goal, min_wrist_goal_);
44 }
45 void update_max_intake_goal(double max_intake_goal) {
46 max_intake_goal_ = ::std::min(max_intake_goal, max_intake_goal_);
47 }
48 void update_min_intake_goal(double min_intake_goal) {
49 min_intake_goal_ = ::std::max(min_intake_goal, min_intake_goal_);
50 }
51 void update_min_elevator_goal(double min_elevator_goal) {
52 min_elevator_goal_ = ::std::max(min_elevator_goal, min_elevator_goal_);
53 }
54
Sabina Davis4b63ae52019-01-27 16:15:25 -080055 // Height above which we can move the wrist freely.
Austin Schuhed7f8632019-02-15 23:12:20 -080056 static constexpr double kElevatorClearHeight = 0.35;
Sabina Davis4b63ae52019-01-27 16:15:25 -080057
58 // Height above which we can move the wrist down.
Austin Schuhed7f8632019-02-15 23:12:20 -080059 static constexpr double kElevatorClearWristDownHeight = 0.25;
Sabina Davis4b63ae52019-01-27 16:15:25 -080060 // Height the carriage needs to be above to move the intake.
61 static constexpr double kElevatorClearIntakeHeight = 0.4;
62
63 // Angle constraints for the wrist when below kElevatorClearDownHeight
Austin Schuh2bf322b2019-04-13 23:07:40 -070064 static constexpr double kWristMaxAngle = M_PI / 2.0 + 0.15;
Austin Schuh899a49d2019-03-22 21:18:49 -070065 static constexpr double kWristMinAngle = -M_PI / 2.0 - 0.25;
Sabina Davis4b63ae52019-01-27 16:15:25 -080066
67 // Angles outside of which the intake is fully clear of the wrist.
Austin Schuhed7f8632019-02-15 23:12:20 -080068 static constexpr double kIntakeOutAngle = 0.3;
69 static constexpr double kIntakeInAngle = -1.1;
Sabina Davis4b63ae52019-01-27 16:15:25 -080070
71 // Angles within which we will crash the wrist into the elevator if the
72 // elevator is below kElevatorClearHeight.
73 static constexpr double kWristElevatorCollisionMinAngle = -M_PI / 4.0;
74 static constexpr double kWristElevatorCollisionMaxAngle = M_PI / 4.0;
Philipp Schrader790cb542023-07-05 21:06:52 -070075 static constexpr double kWristElevatorCollisionMaxAngleWithoutObject =
76 M_PI / 6.0;
Sabina Davis4b63ae52019-01-27 16:15:25 -080077
78 // Tolerance for the elevator.
79 static constexpr double kEps = 0.02;
80 // Tolerance for the intake.
81 static constexpr double kEpsIntake = 0.05;
82 // Tolerance for the wrist.
83 static constexpr double kEpsWrist = 0.05;
84
85 private:
86 void clear_min_wrist_goal() {
87 min_wrist_goal_ = -::std::numeric_limits<double>::infinity();
88 }
89 void clear_max_wrist_goal() {
90 max_wrist_goal_ = ::std::numeric_limits<double>::infinity();
91 }
92 void clear_min_elevator_goal() {
93 min_elevator_goal_ = -::std::numeric_limits<double>::infinity();
94 }
95 void clear_min_intake_goal() {
96 min_intake_goal_ = -::std::numeric_limits<double>::infinity();
97 }
98 void clear_max_intake_goal() {
99 max_intake_goal_ = ::std::numeric_limits<double>::infinity();
100 }
101
102 double min_wrist_goal_;
103 double max_wrist_goal_;
104 double min_elevator_goal_;
105 double min_intake_goal_;
106 double max_intake_goal_;
107};
108
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -0800109} // namespace y2019::control_loops::superstructure
Sabina Davis4b63ae52019-01-27 16:15:25 -0800110
111#endif // Y2019_CONTROL_LOOPS_SUPERSTRUCTURE_COLLISION_AVOIDANCE_H_