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: |
| 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 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 48 | flatbuffers::Offset<frc971::control_loops::IndexProfiledJointStatus> Iterate( |
| 49 | ::aos::monotonic_clock::time_point monotonic_now, |
| 50 | const double *unsafe_goal, |
| 51 | const frc971::ProfileParameters *unsafe_goal_profile_parameters, |
| 52 | const ::frc971::IndexPosition *position, double *output, |
| 53 | flatbuffers::FlatBufferBuilder *fbb); |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 54 | |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 55 | void Reset(); |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 56 | |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 57 | enum class State : int32_t { |
| 58 | UNINITIALIZED, |
| 59 | DISABLED_INITIALIZED, |
| 60 | ZEROING, |
| 61 | RUNNING, |
| 62 | ESTOP, |
| 63 | }; |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 64 | |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 65 | State state() const { return 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 | private: |
| 68 | State state_; |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 69 | |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 70 | IndexPulseProfiledSubsystem profiled_subsystem_; |
Adam Snaider | 3f5c1e9 | 2017-03-24 21:06:03 -0700 | [diff] [blame] | 71 | double last_position_ = 0; |
| 72 | ::aos::monotonic_clock::time_point last_move_time_ = |
| 73 | ::aos::monotonic_clock::min_time; |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | } // namespace hood |
| 77 | } // namespace superstructure |
| 78 | } // namespace control_loops |
| 79 | } // namespace y2017 |
| 80 | |
| 81 | #endif // Y2017_CONTROL_LOOPS_SUPERSTRUCTURE_HOOD_HOOD_H_ |