Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 1 | #ifndef y2020_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_ |
| 2 | #define y2020_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_ |
| 3 | |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 4 | #include "aos/events/event_loop.h" |
Ravago Jones | ac850da | 2021-10-13 20:38:29 -0700 | [diff] [blame] | 5 | #include "frc971/control_loops/control_loop.h" |
James Kuszmaul | b1b2d8e | 2020-02-21 21:11:46 -0800 | [diff] [blame] | 6 | #include "frc971/control_loops/drivetrain/drivetrain_status_generated.h" |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 7 | #include "frc971/input/joystick_state_generated.h" |
James Kuszmaul | ec635d2 | 2023-08-12 18:39:24 -0700 | [diff] [blame] | 8 | #include "frc971/zeroing/absolute_and_absolute_encoder.h" |
| 9 | #include "frc971/zeroing/absolute_encoder.h" |
| 10 | #include "frc971/zeroing/pot_and_absolute_encoder.h" |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 11 | #include "y2020/constants.h" |
milind-u | d53408e | 2021-10-21 19:43:58 -0700 | [diff] [blame] | 12 | #include "y2020/control_loops/superstructure/hood/hood_encoder_zeroing_estimator.h" |
Sabina Davis | 0f31d3f | 2020-02-20 20:41:00 -0800 | [diff] [blame] | 13 | #include "y2020/control_loops/superstructure/shooter/shooter.h" |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 14 | #include "y2020/control_loops/superstructure/superstructure_goal_generated.h" |
| 15 | #include "y2020/control_loops/superstructure/superstructure_output_generated.h" |
| 16 | #include "y2020/control_loops/superstructure/superstructure_position_generated.h" |
| 17 | #include "y2020/control_loops/superstructure/superstructure_status_generated.h" |
James Kuszmaul | b1b2d8e | 2020-02-21 21:11:46 -0800 | [diff] [blame] | 18 | #include "y2020/control_loops/superstructure/turret/aiming.h" |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 19 | |
| 20 | namespace y2020 { |
| 21 | namespace control_loops { |
| 22 | namespace superstructure { |
| 23 | |
| 24 | class Superstructure |
James Kuszmaul | 6175066 | 2021-06-21 21:32:33 -0700 | [diff] [blame] | 25 | : public ::frc971::controls::ControlLoop<Goal, Position, Status, Output> { |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 26 | public: |
| 27 | explicit Superstructure(::aos::EventLoop *event_loop, |
| 28 | const ::std::string &name = "/superstructure"); |
| 29 | |
Austin Schuh | 2fb2364 | 2020-02-29 15:10:51 -0800 | [diff] [blame] | 30 | // Terms to control the velocity gain for the friction compensation, and the |
| 31 | // voltage cap. |
milind-u | f70e8e1 | 2021-10-02 12:36:00 -0700 | [diff] [blame] | 32 | static constexpr double kTurretFrictionGain = 0.0; |
Austin Schuh | 2fb2364 | 2020-02-29 15:10:51 -0800 | [diff] [blame] | 33 | static constexpr double kTurretFrictionVoltageLimit = 1.5; |
milind-u | f70e8e1 | 2021-10-02 12:36:00 -0700 | [diff] [blame] | 34 | static constexpr double kTurretDitherGain = 0.0; |
Ravago Jones | ac850da | 2021-10-13 20:38:29 -0700 | [diff] [blame] | 35 | static constexpr std::chrono::milliseconds kPreloadingTimeout = |
Austin Schuh | df240b4 | 2021-10-13 21:33:43 -0700 | [diff] [blame] | 36 | std::chrono::seconds(2); |
Ravago Jones | ac850da | 2021-10-13 20:38:29 -0700 | [diff] [blame] | 37 | static constexpr std::chrono::milliseconds kPreloadingBackpowerDuration = |
Austin Schuh | 6a92a2b | 2021-10-29 23:07:15 -0700 | [diff] [blame] | 38 | std::chrono::milliseconds(55); |
Austin Schuh | 2fb2364 | 2020-02-29 15:10:51 -0800 | [diff] [blame] | 39 | |
Kai Tinkess | fb46037 | 2020-02-08 14:05:48 -0800 | [diff] [blame] | 40 | using PotAndAbsoluteEncoderSubsystem = |
| 41 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem< |
| 42 | ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator, |
| 43 | ::frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus>; |
Sabina Davis | cf08b15 | 2020-01-31 22:12:09 -0800 | [diff] [blame] | 44 | using AbsoluteEncoderSubsystem = |
| 45 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem< |
| 46 | ::frc971::zeroing::AbsoluteEncoderZeroingEstimator, |
| 47 | ::frc971::control_loops::AbsoluteEncoderProfiledJointStatus>; |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 48 | using AbsoluteAndAbsoluteEncoderSubsystem = |
| 49 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem< |
milind-u | d53408e | 2021-10-21 19:43:58 -0700 | [diff] [blame] | 50 | hood::HoodEncoderZeroingEstimator, |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 51 | ::frc971::control_loops:: |
milind-u | d53408e | 2021-10-21 19:43:58 -0700 | [diff] [blame] | 52 | AbsoluteAndAbsoluteEncoderProfiledJointStatus, |
| 53 | frc971::zeroing::AbsoluteAndAbsoluteEncoderZeroingEstimator>; |
Sabina Davis | cf08b15 | 2020-01-31 22:12:09 -0800 | [diff] [blame] | 54 | |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 55 | const AbsoluteAndAbsoluteEncoderSubsystem &hood() const { return hood_; } |
Sabina Davis | 0f2d38c | 2020-02-08 17:01:21 -0800 | [diff] [blame] | 56 | const AbsoluteEncoderSubsystem &intake_joint() const { return intake_joint_; } |
Kai Tinkess | fb46037 | 2020-02-08 14:05:48 -0800 | [diff] [blame] | 57 | const PotAndAbsoluteEncoderSubsystem &turret() const { return turret_; } |
Sabina Davis | 0f31d3f | 2020-02-20 20:41:00 -0800 | [diff] [blame] | 58 | const shooter::Shooter &shooter() const { return shooter_; } |
milind upadhyay | aec1aee | 2020-10-13 13:44:33 -0700 | [diff] [blame] | 59 | double robot_speed() const; |
Sabina Davis | cf08b15 | 2020-01-31 22:12:09 -0800 | [diff] [blame] | 60 | |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 61 | protected: |
| 62 | virtual void RunIteration(const Goal *unsafe_goal, const Position *position, |
| 63 | aos::Sender<Output>::Builder *output, |
| 64 | aos::Sender<Status>::Builder *status) override; |
| 65 | |
| 66 | private: |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 67 | AbsoluteAndAbsoluteEncoderSubsystem hood_; |
Sabina Davis | 0f2d38c | 2020-02-08 17:01:21 -0800 | [diff] [blame] | 68 | AbsoluteEncoderSubsystem intake_joint_; |
Kai Tinkess | fb46037 | 2020-02-08 14:05:48 -0800 | [diff] [blame] | 69 | PotAndAbsoluteEncoderSubsystem turret_; |
Sabina Davis | 0f31d3f | 2020-02-20 20:41:00 -0800 | [diff] [blame] | 70 | shooter::Shooter shooter_; |
James Kuszmaul | b1b2d8e | 2020-02-21 21:11:46 -0800 | [diff] [blame] | 71 | turret::Aimer aimer_; |
| 72 | |
| 73 | aos::Fetcher<frc971::control_loops::drivetrain::Status> |
| 74 | drivetrain_status_fetcher_; |
James Kuszmaul | a53c3ac | 2020-02-22 19:36:01 -0800 | [diff] [blame] | 75 | aos::Fetcher<aos::JoystickState> joystick_state_fetcher_; |
Sabina Davis | cf08b15 | 2020-01-31 22:12:09 -0800 | [diff] [blame] | 76 | |
Austin Schuh | 13e5552 | 2020-02-29 23:11:17 -0800 | [diff] [blame] | 77 | aos::monotonic_clock::time_point shooting_start_time_ = |
| 78 | aos::monotonic_clock::min_time; |
Ravago Jones | ac850da | 2021-10-13 20:38:29 -0700 | [diff] [blame] | 79 | aos::monotonic_clock::time_point preloading_timeout_ = |
| 80 | aos::monotonic_clock::min_time; |
| 81 | aos::monotonic_clock::time_point preloading_backpower_timeout_ = |
| 82 | aos::monotonic_clock::min_time; |
Austin Schuh | 13e5552 | 2020-02-29 23:11:17 -0800 | [diff] [blame] | 83 | |
Austin Schuh | 01d81c3 | 2021-11-06 22:59:56 -0700 | [diff] [blame] | 84 | bool has_turret_ = true; |
| 85 | |
milind | 1f1dca3 | 2021-07-03 13:50:07 -0700 | [diff] [blame] | 86 | aos::SendFailureCounter status_failure_counter_; |
| 87 | |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 88 | DISALLOW_COPY_AND_ASSIGN(Superstructure); |
| 89 | }; |
| 90 | |
| 91 | } // namespace superstructure |
| 92 | } // namespace control_loops |
| 93 | } // namespace y2020 |
| 94 | |
| 95 | #endif // y2020_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_ |