Adam Snaider | 79900c2 | 2017-02-08 20:23:15 -0800 | [diff] [blame] | 1 | #ifndef Y2017_CONTROL_LOOPS_SUPERSTRUCTURE_INTAKE_INTAKE_H_ |
| 2 | #define Y2017_CONTROL_LOOPS_SUPERSTRUCTURE_INTAKE_INTAKE_H_ |
| 3 | |
| 4 | #include "frc971/control_loops/profiled_subsystem.h" |
Austin Schuh | d5ccb86 | 2017-03-11 22:06:36 -0800 | [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" |
Adam Snaider | 79900c2 | 2017-02-08 20:23:15 -0800 | [diff] [blame] | 7 | |
| 8 | namespace y2017 { |
| 9 | namespace control_loops { |
| 10 | namespace superstructure { |
| 11 | namespace intake { |
| 12 | |
| 13 | class Intake { |
| 14 | public: |
Ojas Upadhye | 3abe886 | 2017-02-11 17:06:53 -0800 | [diff] [blame] | 15 | Intake(); |
| 16 | double goal(int row, int col) const { |
| 17 | return profiled_subsystem_.goal(row, col); |
| 18 | } |
Adam Snaider | 79900c2 | 2017-02-08 20:23:15 -0800 | [diff] [blame] | 19 | |
Austin Schuh | d5ccb86 | 2017-03-11 22:06:36 -0800 | [diff] [blame] | 20 | // Sets the minimum position we'll allow the intake to be at. This forces the |
| 21 | // intake to stay out far enough to avoid collisions. |
| 22 | void set_min_position(double min_position) { min_position_ = min_position; } |
| 23 | |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 24 | // Moves min_position_ to a position which won't affect any other goal |
| 25 | // requests. |
Austin Schuh | d5ccb86 | 2017-03-11 22:06:36 -0800 | [diff] [blame] | 26 | void clear_min_position() { |
| 27 | min_position_ = constants::Values::kIntakeRange.lower_hard; |
| 28 | } |
| 29 | |
| 30 | double position() const { return profiled_subsystem_.position(); } |
| 31 | |
Ojas Upadhye | 3abe886 | 2017-02-11 17:06:53 -0800 | [diff] [blame] | 32 | // The zeroing and operating voltages. |
| 33 | static constexpr double kZeroingVoltage = 2.5; |
| 34 | static constexpr double kOperatingVoltage = 12.0; |
Adam Snaider | 79900c2 | 2017-02-08 20:23:15 -0800 | [diff] [blame] | 35 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 36 | flatbuffers::Offset< |
| 37 | ::frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus> |
| 38 | Iterate(const IntakeGoal *unsafe_goal, |
| 39 | const ::frc971::PotAndAbsolutePosition *position, double *output, |
| 40 | flatbuffers::FlatBufferBuilder *fbb); |
Adam Snaider | 79900c2 | 2017-02-08 20:23:15 -0800 | [diff] [blame] | 41 | |
Ojas Upadhye | 3abe886 | 2017-02-11 17:06:53 -0800 | [diff] [blame] | 42 | void Reset(); |
Adam Snaider | 79900c2 | 2017-02-08 20:23:15 -0800 | [diff] [blame] | 43 | |
Ojas Upadhye | 3abe886 | 2017-02-11 17:06:53 -0800 | [diff] [blame] | 44 | enum class State : int32_t { |
| 45 | UNINITIALIZED, |
| 46 | DISABLED_INITIALIZED, |
| 47 | ZEROING, |
| 48 | RUNNING, |
| 49 | ESTOP, |
| 50 | }; |
Adam Snaider | 79900c2 | 2017-02-08 20:23:15 -0800 | [diff] [blame] | 51 | |
Ojas Upadhye | 3abe886 | 2017-02-11 17:06:53 -0800 | [diff] [blame] | 52 | State state() const { return state_; } |
Adam Snaider | 79900c2 | 2017-02-08 20:23:15 -0800 | [diff] [blame] | 53 | |
Ojas Upadhye | 3abe886 | 2017-02-11 17:06:53 -0800 | [diff] [blame] | 54 | private: |
Austin Schuh | d5ccb86 | 2017-03-11 22:06:36 -0800 | [diff] [blame] | 55 | State state_ = State::UNINITIALIZED; |
| 56 | double min_position_; |
| 57 | |
| 58 | // The number of times in a row we've been asked to disable. |
| 59 | int disable_count_ = 0; |
Adam Snaider | 79900c2 | 2017-02-08 20:23:15 -0800 | [diff] [blame] | 60 | |
Ojas Upadhye | 3abe886 | 2017-02-11 17:06:53 -0800 | [diff] [blame] | 61 | ::frc971::control_loops::SingleDOFProfiledSubsystem< |
Austin Schuh | 72db9a1 | 2019-01-21 18:02:51 -0800 | [diff] [blame] | 62 | ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator> |
| 63 | profiled_subsystem_; |
Adam Snaider | 79900c2 | 2017-02-08 20:23:15 -0800 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | } // namespace intake |
| 67 | } // namespace superstructure |
| 68 | } // namespace control_loops |
| 69 | } // namespace y2017 |
| 70 | |
| 71 | #endif // Y2017_CONTROL_LOOPS_SUPERSTRUCTURE_INTAKE_INTAKE_H_ |