Comran Morshed | 25f81a0 | 2016-01-23 13:40:10 +0000 | [diff] [blame] | 1 | #ifndef Y2016_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_ |
| 2 | #define Y2016_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_ |
| 3 | |
| 4 | #include <memory> |
| 5 | |
| 6 | #include "aos/common/controls/control_loop.h" |
Austin Schuh | 2fc10fa | 2016-02-08 00:44:34 -0800 | [diff] [blame] | 7 | #include "aos/common/util/trapezoid_profile.h" |
Austin Schuh | 10c2d11 | 2016-02-14 13:42:28 -0800 | [diff] [blame] | 8 | #include "frc971/control_loops/state_feedback_loop.h" |
Comran Morshed | 25f81a0 | 2016-01-23 13:40:10 +0000 | [diff] [blame] | 9 | |
Austin Schuh | 2fc10fa | 2016-02-08 00:44:34 -0800 | [diff] [blame] | 10 | #include "frc971/zeroing/zeroing.h" |
Comran Morshed | 25f81a0 | 2016-01-23 13:40:10 +0000 | [diff] [blame] | 11 | #include "y2016/control_loops/superstructure/superstructure.q.h" |
Austin Schuh | 10c2d11 | 2016-02-14 13:42:28 -0800 | [diff] [blame] | 12 | #include "y2016/control_loops/superstructure/superstructure_controls.h" |
Comran Morshed | 25f81a0 | 2016-01-23 13:40:10 +0000 | [diff] [blame] | 13 | |
| 14 | namespace y2016 { |
| 15 | namespace control_loops { |
Austin Schuh | 2fc10fa | 2016-02-08 00:44:34 -0800 | [diff] [blame] | 16 | namespace superstructure { |
| 17 | namespace testing { |
| 18 | class SuperstructureTest_DisabledGoalTest_Test; |
| 19 | } // namespace testing |
| 20 | |
Comran Morshed | 25f81a0 | 2016-01-23 13:40:10 +0000 | [diff] [blame] | 21 | class Superstructure |
| 22 | : public ::aos::controls::ControlLoop<control_loops::SuperstructureQueue> { |
| 23 | public: |
| 24 | explicit Superstructure( |
| 25 | control_loops::SuperstructureQueue *my_superstructure = |
| 26 | &control_loops::superstructure_queue); |
Adam Snaider | 0677972 | 2016-02-14 15:26:22 -0800 | [diff] [blame] | 27 | |
| 28 | // This is the angle above which we will do a HIGH_ARM_ZERO, and below which |
| 29 | // we will do a LOW_ARM_ZERO. |
| 30 | static constexpr double kShoulderMiddleAngle = M_PI / 4.0; |
| 31 | // This is the large scale movement tolerance. |
| 32 | static constexpr double kLooseTolerance = 0.05; |
| 33 | |
| 34 | // This is the small scale movement tolerance. |
| 35 | static constexpr double kTightTolerance = 0.01; |
| 36 | |
| 37 | // This is the angle such that the intake will clear the arm when the shooter |
| 38 | // is level. |
| 39 | static constexpr double kIntakeUpperClear = 1.1; |
| 40 | // This is the angle such that the intake will clear the arm when the shooter |
| 41 | // is at almost any position. |
| 42 | static constexpr double kIntakeLowerClear = 0.5; |
| 43 | |
| 44 | // This is the angle that the shoulder will go to when doing the |
| 45 | // HIGH_ARM_ZERO. |
| 46 | static constexpr double kShoulderUpAngle = M_PI / 2.0; |
| 47 | |
| 48 | // This is the angle that the shoulder will go down to when landing in the |
| 49 | // bellypan. |
| 50 | static constexpr double kShoulderLanded = -0.02; |
| 51 | |
| 52 | // This is the angle below which we consider the wrist close enough to level |
| 53 | // that we should move it to level before doing anything. |
| 54 | static constexpr double kWristAlmostLevel = 0.10; |
| 55 | |
| 56 | // This is the angle that the shoulder will go down to when raising up before |
| 57 | // leveling the shooter for calibration. |
| 58 | static constexpr double kShoulderWristClearAngle = 0.6; |
| 59 | |
Austin Schuh | 2fc10fa | 2016-02-08 00:44:34 -0800 | [diff] [blame] | 60 | enum State { |
Adam Snaider | 0677972 | 2016-02-14 15:26:22 -0800 | [diff] [blame] | 61 | // Wait for all the filters to be ready before starting the initialization |
| 62 | // process. |
Austin Schuh | 2fc10fa | 2016-02-08 00:44:34 -0800 | [diff] [blame] | 63 | UNINITIALIZED = 0, |
Adam Snaider | 0677972 | 2016-02-14 15:26:22 -0800 | [diff] [blame] | 64 | |
| 65 | // We now are ready to decide how to zero. Decide what to do once we are |
| 66 | // enabled. |
| 67 | DISABLED_INITIALIZED = 1, |
| 68 | |
| 69 | // Lift the arm up out of the way. |
| 70 | HIGH_ARM_ZERO_LIFT_ARM = 2, |
| 71 | |
| 72 | HIGH_ARM_ZERO_LEVEL_SHOOTER = 3, |
| 73 | |
| 74 | HIGH_ARM_ZERO_MOVE_INTAKE_OUT = 4, |
| 75 | |
| 76 | HIGH_ARM_ZERO_LOWER_ARM = 6, |
| 77 | |
| 78 | LOW_ARM_ZERO_LOWER_INTAKE = 7, |
| 79 | LOW_ARM_ZERO_MAYBE_LEVEL_SHOOTER = 8, |
| 80 | LOW_ARM_ZERO_LIFT_SHOULDER = 9, |
| 81 | LOW_ARM_ZERO_LEVEL_SHOOTER = 11, |
| 82 | // Run, but limit power to zeroing voltages. |
| 83 | SLOW_RUNNING = 12, |
| 84 | // Run with full power. |
| 85 | RUNNING = 13, |
Austin Schuh | 2fc10fa | 2016-02-08 00:44:34 -0800 | [diff] [blame] | 86 | // Internal error caused the superstructure to abort. |
Adam Snaider | 0677972 | 2016-02-14 15:26:22 -0800 | [diff] [blame] | 87 | ESTOP = 14, |
Austin Schuh | 2fc10fa | 2016-02-08 00:44:34 -0800 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | State state() const { return state_; } |
Comran Morshed | 25f81a0 | 2016-01-23 13:40:10 +0000 | [diff] [blame] | 91 | |
Adam Snaider | 0677972 | 2016-02-14 15:26:22 -0800 | [diff] [blame] | 92 | // Returns the value to move the joint to such that it will stay below |
| 93 | // reference_angle starting at current_angle, but move at least move_distance |
| 94 | static double MoveButKeepBelow(double reference_angle, double current_angle, |
| 95 | double move_distance); |
| 96 | // Returns the value to move the joint to such that it will stay above |
| 97 | // reference_angle starting at current_angle, but move at least move_distance |
| 98 | static double MoveButKeepAbove(double reference_angle, double current_angle, |
| 99 | double move_distance); |
| 100 | |
Comran Morshed | 25f81a0 | 2016-01-23 13:40:10 +0000 | [diff] [blame] | 101 | protected: |
| 102 | virtual void RunIteration( |
Austin Schuh | 2fc10fa | 2016-02-08 00:44:34 -0800 | [diff] [blame] | 103 | const control_loops::SuperstructureQueue::Goal *unsafe_goal, |
Comran Morshed | 25f81a0 | 2016-01-23 13:40:10 +0000 | [diff] [blame] | 104 | const control_loops::SuperstructureQueue::Position *position, |
Austin Schuh | 2fc10fa | 2016-02-08 00:44:34 -0800 | [diff] [blame] | 105 | control_loops::SuperstructureQueue::Output *output, |
Comran Morshed | 25f81a0 | 2016-01-23 13:40:10 +0000 | [diff] [blame] | 106 | control_loops::SuperstructureQueue::Status *status) override; |
| 107 | |
| 108 | private: |
Austin Schuh | 2fc10fa | 2016-02-08 00:44:34 -0800 | [diff] [blame] | 109 | friend class testing::SuperstructureTest_DisabledGoalTest_Test; |
| 110 | Intake intake_; |
| 111 | Arm arm_; |
| 112 | |
| 113 | State state_ = UNINITIALIZED; |
| 114 | State last_state_ = UNINITIALIZED; |
| 115 | |
Adam Snaider | 0677972 | 2016-02-14 15:26:22 -0800 | [diff] [blame] | 116 | // Returns true if the profile has finished, and the joint is within the |
| 117 | // specified tolerance. |
| 118 | bool IsArmNear(double tolerance); |
| 119 | bool IsArmNear(double shoulder_tolerance, double wrist_tolerance); |
| 120 | bool IsIntakeNear(double tolerance); |
Austin Schuh | 2fc10fa | 2016-02-08 00:44:34 -0800 | [diff] [blame] | 121 | |
Comran Morshed | 25f81a0 | 2016-01-23 13:40:10 +0000 | [diff] [blame] | 122 | DISALLOW_COPY_AND_ASSIGN(Superstructure); |
| 123 | }; |
| 124 | |
Austin Schuh | 2fc10fa | 2016-02-08 00:44:34 -0800 | [diff] [blame] | 125 | } // namespace superstructure |
Comran Morshed | 25f81a0 | 2016-01-23 13:40:10 +0000 | [diff] [blame] | 126 | } // namespace control_loops |
| 127 | } // namespace y2016 |
| 128 | |
| 129 | #endif // Y2016_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_ |