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