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" |
Adam Snaider | 3f5c1e9 | 2017-03-24 21:06:03 -0700 | [diff] [blame] | 5 | #include "y2017/constants.h" |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 6 | #include "y2017/control_loops/superstructure/superstructure_goal_generated.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: |
Sabina Davis | 0e484f9 | 2020-02-23 17:47:53 -0800 | [diff] [blame] | 24 | void CapGoal(const char *name, Eigen::Matrix<double, 3, 1> *goal, |
| 25 | bool print) override; |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 26 | }; |
| 27 | |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 28 | class Hood { |
| 29 | public: |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 30 | Hood(); |
| 31 | double goal(int row, int col) const { |
| 32 | return profiled_subsystem_.goal(row, col); |
| 33 | } |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 34 | |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 35 | // The zeroing and operating voltages. |
Austin Schuh | 410e381 | 2017-02-21 16:44:03 -0800 | [diff] [blame] | 36 | static constexpr double kZeroingVoltage = 2.0; |
Adam Snaider | 3f5c1e9 | 2017-03-24 21:06:03 -0700 | [diff] [blame] | 37 | static constexpr double kOperatingVoltage = 12.0; |
| 38 | |
| 39 | // Constants needed when determining if the hood is in danger of breaking its |
| 40 | // own gears at the normal operating voltage. |
| 41 | static constexpr double kErrorOnPositionTillNotMoving = |
| 42 | 2.5 * (::y2017::constants::Values::kHoodEncoderIndexDifference / |
| 43 | ::y2017::constants::Values::kHoodEncoderCountsPerRevolution); |
| 44 | |
| 45 | static constexpr ::aos::monotonic_clock::duration kTimeTillNotMoving = |
| 46 | ::std::chrono::milliseconds(15); |
| 47 | static constexpr double kNotMovingVoltage = 2.0; |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 48 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 49 | flatbuffers::Offset<frc971::control_loops::IndexProfiledJointStatus> Iterate( |
| 50 | ::aos::monotonic_clock::time_point monotonic_now, |
| 51 | const double *unsafe_goal, |
| 52 | const frc971::ProfileParameters *unsafe_goal_profile_parameters, |
| 53 | const ::frc971::IndexPosition *position, double *output, |
| 54 | flatbuffers::FlatBufferBuilder *fbb); |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 55 | |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 56 | void Reset(); |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 57 | |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 58 | enum class State : int32_t { |
| 59 | UNINITIALIZED, |
| 60 | DISABLED_INITIALIZED, |
| 61 | ZEROING, |
| 62 | RUNNING, |
| 63 | ESTOP, |
| 64 | }; |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 65 | |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 66 | State state() const { return state_; } |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 67 | |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 68 | private: |
| 69 | State state_; |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 70 | |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 71 | IndexPulseProfiledSubsystem profiled_subsystem_; |
Adam Snaider | 3f5c1e9 | 2017-03-24 21:06:03 -0700 | [diff] [blame] | 72 | double last_position_ = 0; |
| 73 | ::aos::monotonic_clock::time_point last_move_time_ = |
| 74 | ::aos::monotonic_clock::min_time; |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | } // namespace hood |
| 78 | } // namespace superstructure |
| 79 | } // namespace control_loops |
| 80 | } // namespace y2017 |
| 81 | |
| 82 | #endif // Y2017_CONTROL_LOOPS_SUPERSTRUCTURE_HOOD_HOOD_H_ |