blob: 7feb45d9a75d53752c217067f44ea0c7f7338413 [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>
5#include "aos/controls/control_loops.q.h"
6#include "frc971/constants.h"
7#include "y2019/control_loops/superstructure/superstructure.q.h"
8
9namespace y2019 {
10namespace control_loops {
11namespace superstructure {
12
13// CollisionAvoidance computes the min and max allowable ranges for various
14// subsystems to avoid collisions. It also shoves the elevator up to let the
15// intake go in and out, and to let the wrist switch sides.
16class CollisionAvoidance {
17 public:
18 CollisionAvoidance();
19
20 // Reports if the superstructure is collided.
21 bool IsCollided(const SuperstructureQueue::Status *status);
Austin Schuh9fe68f72019-08-10 19:32:03 -070022 bool IsCollided(double wrist_position, double elevator_position,
23 double intake_position, bool has_piece);
Sabina Davis4b63ae52019-01-27 16:15:25 -080024
25 // Checks and alters goals to make sure they're safe.
26 // TODO(austin): Either we will have a unit delay because this has to happen
27 // after the controls, or we need to be more clever about restructuring.
28 void UpdateGoal(const SuperstructureQueue::Status *status,
29 const SuperstructureQueue::Goal *unsafe_goal);
30
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;
Tyler Chatowd180b252019-02-23 22:00:20 -080075 static constexpr double kWristElevatorCollisionMaxAngleWithoutObject = M_PI / 6.0;
Sabina Davis4b63ae52019-01-27 16:15:25 -080076
77 // Tolerance for the elevator.
78 static constexpr double kEps = 0.02;
79 // Tolerance for the intake.
80 static constexpr double kEpsIntake = 0.05;
81 // Tolerance for the wrist.
82 static constexpr double kEpsWrist = 0.05;
83
84 private:
85 void clear_min_wrist_goal() {
86 min_wrist_goal_ = -::std::numeric_limits<double>::infinity();
87 }
88 void clear_max_wrist_goal() {
89 max_wrist_goal_ = ::std::numeric_limits<double>::infinity();
90 }
91 void clear_min_elevator_goal() {
92 min_elevator_goal_ = -::std::numeric_limits<double>::infinity();
93 }
94 void clear_min_intake_goal() {
95 min_intake_goal_ = -::std::numeric_limits<double>::infinity();
96 }
97 void clear_max_intake_goal() {
98 max_intake_goal_ = ::std::numeric_limits<double>::infinity();
99 }
100
101 double min_wrist_goal_;
102 double max_wrist_goal_;
103 double min_elevator_goal_;
104 double min_intake_goal_;
105 double max_intake_goal_;
106};
107
108} // namespace superstructure
109} // namespace control_loops
110} // namespace y2019
111
112#endif // Y2019_CONTROL_LOOPS_SUPERSTRUCTURE_COLLISION_AVOIDANCE_H_