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