Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 1 | #ifndef Y2017_CONTROL_LOOPS_SUPERSTRUCTURE_HOOD_HOOD_H_ |
| 2 | #define Y2017_CONTROL_LOOPS_SUPERSTRUCTURE_HOOD_HOOD_H_ |
| 3 | |
| 4 | #include "frc971/control_loops/profiled_subsystem.h" |
| 5 | #include "y2017/control_loops/superstructure/superstructure.q.h" |
Adam Snaider | 3f5c1e9 | 2017-03-24 21:06:03 -0700 | [diff] [blame^] | 6 | #include "y2017/constants.h" |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 7 | |
| 8 | namespace y2017 { |
| 9 | namespace control_loops { |
| 10 | namespace superstructure { |
| 11 | namespace hood { |
| 12 | |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 13 | // Profiled subsystem class with significantly relaxed limits while zeroing. We |
| 14 | // need relaxed limits, because if you start at the top of the range, you need |
| 15 | // to go to -range, and if you start at the bottom of the range, you need to go |
| 16 | // to +range. The standard subsystem doesn't support that. |
| 17 | class IndexPulseProfiledSubsystem |
| 18 | : public ::frc971::control_loops::SingleDOFProfiledSubsystem< |
| 19 | ::frc971::zeroing::PulseIndexZeroingEstimator> { |
| 20 | public: |
| 21 | IndexPulseProfiledSubsystem(); |
| 22 | |
| 23 | private: |
| 24 | void CapGoal(const char *name, Eigen::Matrix<double, 3, 1> *goal) override; |
| 25 | }; |
| 26 | |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 27 | class Hood { |
| 28 | public: |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 29 | Hood(); |
| 30 | double goal(int row, int col) const { |
| 31 | return profiled_subsystem_.goal(row, col); |
| 32 | } |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 33 | |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 34 | // The zeroing and operating voltages. |
Austin Schuh | 410e381 | 2017-02-21 16:44:03 -0800 | [diff] [blame] | 35 | static constexpr double kZeroingVoltage = 2.0; |
Adam Snaider | 3f5c1e9 | 2017-03-24 21:06:03 -0700 | [diff] [blame^] | 36 | static constexpr double kOperatingVoltage = 12.0; |
| 37 | |
| 38 | // Constants needed when determining if the hood is in danger of breaking its |
| 39 | // own gears at the normal operating voltage. |
| 40 | static constexpr double kErrorOnPositionTillNotMoving = |
| 41 | 2.5 * (::y2017::constants::Values::kHoodEncoderIndexDifference / |
| 42 | ::y2017::constants::Values::kHoodEncoderCountsPerRevolution); |
| 43 | |
| 44 | static constexpr ::aos::monotonic_clock::duration kTimeTillNotMoving = |
| 45 | ::std::chrono::milliseconds(15); |
| 46 | static constexpr double kNotMovingVoltage = 2.0; |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 47 | |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 48 | void Iterate(const control_loops::HoodGoal *unsafe_goal, |
| 49 | const ::frc971::IndexPosition *position, double *output, |
| 50 | ::frc971::control_loops::IndexProfiledJointStatus *status); |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 51 | |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 52 | void Reset(); |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 53 | |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 54 | enum class State : int32_t { |
| 55 | UNINITIALIZED, |
| 56 | DISABLED_INITIALIZED, |
| 57 | ZEROING, |
| 58 | RUNNING, |
| 59 | ESTOP, |
| 60 | }; |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 61 | |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 62 | State state() const { return state_; } |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 63 | |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 64 | private: |
| 65 | State state_; |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 66 | |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 67 | IndexPulseProfiledSubsystem profiled_subsystem_; |
Adam Snaider | 3f5c1e9 | 2017-03-24 21:06:03 -0700 | [diff] [blame^] | 68 | double last_position_ = 0; |
| 69 | ::aos::monotonic_clock::time_point last_move_time_ = |
| 70 | ::aos::monotonic_clock::min_time; |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | } // namespace hood |
| 74 | } // namespace superstructure |
| 75 | } // namespace control_loops |
| 76 | } // namespace y2017 |
| 77 | |
| 78 | #endif // Y2017_CONTROL_LOOPS_SUPERSTRUCTURE_HOOD_HOOD_H_ |