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