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 | |
| 4 | #include "aos/controls/control_loop.h" |
| 5 | #include "aos/events/event_loop.h" |
James Kuszmaul | a53c3ac | 2020-02-22 19:36:01 -0800 | [diff] [blame] | 6 | #include "aos/robot_state/joystick_state_generated.h" |
James Kuszmaul | b1b2d8e | 2020-02-21 21:11:46 -0800 | [diff] [blame] | 7 | #include "frc971/control_loops/drivetrain/drivetrain_status_generated.h" |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 8 | #include "y2020/constants.h" |
Sabina Davis | 0f31d3f | 2020-02-20 20:41:00 -0800 | [diff] [blame] | 9 | #include "y2020/control_loops/superstructure/shooter/shooter.h" |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 10 | #include "y2020/control_loops/superstructure/superstructure_goal_generated.h" |
| 11 | #include "y2020/control_loops/superstructure/superstructure_output_generated.h" |
| 12 | #include "y2020/control_loops/superstructure/superstructure_position_generated.h" |
| 13 | #include "y2020/control_loops/superstructure/superstructure_status_generated.h" |
John Park | 0a245a0 | 2020-02-02 14:10:15 -0800 | [diff] [blame] | 14 | #include "y2020/control_loops/superstructure/climber.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 |
| 22 | : public ::aos::controls::ControlLoop<Goal, Position, Status, Output> { |
| 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. |
| 29 | static constexpr double kTurretFrictionGain = 10.0; |
| 30 | static constexpr double kTurretFrictionVoltageLimit = 1.5; |
| 31 | |
Austin Schuh | 78f0bfd | 2020-02-29 23:04:21 -0800 | [diff] [blame] | 32 | static constexpr double kHoodFrictionGain = 40.0; |
| 33 | static constexpr double kHoodFrictionVoltageLimit = 1.5; |
| 34 | |
Kai Tinkess | fb46037 | 2020-02-08 14:05:48 -0800 | [diff] [blame] | 35 | using PotAndAbsoluteEncoderSubsystem = |
| 36 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem< |
| 37 | ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator, |
| 38 | ::frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus>; |
Sabina Davis | cf08b15 | 2020-01-31 22:12:09 -0800 | [diff] [blame] | 39 | using AbsoluteEncoderSubsystem = |
| 40 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem< |
| 41 | ::frc971::zeroing::AbsoluteEncoderZeroingEstimator, |
| 42 | ::frc971::control_loops::AbsoluteEncoderProfiledJointStatus>; |
| 43 | |
| 44 | const AbsoluteEncoderSubsystem &hood() const { return hood_; } |
Sabina Davis | 0f2d38c | 2020-02-08 17:01:21 -0800 | [diff] [blame] | 45 | const AbsoluteEncoderSubsystem &intake_joint() const { return intake_joint_; } |
Kai Tinkess | fb46037 | 2020-02-08 14:05:48 -0800 | [diff] [blame] | 46 | const PotAndAbsoluteEncoderSubsystem &turret() const { return turret_; } |
Sabina Davis | 0f31d3f | 2020-02-20 20:41:00 -0800 | [diff] [blame] | 47 | const shooter::Shooter &shooter() const { return shooter_; } |
milind upadhyay | aec1aee | 2020-10-13 13:44:33 -0700 | [diff] [blame^] | 48 | double robot_speed() const; |
Sabina Davis | cf08b15 | 2020-01-31 22:12:09 -0800 | [diff] [blame] | 49 | |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 50 | protected: |
| 51 | virtual void RunIteration(const Goal *unsafe_goal, const Position *position, |
| 52 | aos::Sender<Output>::Builder *output, |
| 53 | aos::Sender<Status>::Builder *status) override; |
| 54 | |
| 55 | private: |
Sabina Davis | cf08b15 | 2020-01-31 22:12:09 -0800 | [diff] [blame] | 56 | AbsoluteEncoderSubsystem hood_; |
Sabina Davis | 0f2d38c | 2020-02-08 17:01:21 -0800 | [diff] [blame] | 57 | AbsoluteEncoderSubsystem intake_joint_; |
Kai Tinkess | fb46037 | 2020-02-08 14:05:48 -0800 | [diff] [blame] | 58 | PotAndAbsoluteEncoderSubsystem turret_; |
Sabina Davis | 0f31d3f | 2020-02-20 20:41:00 -0800 | [diff] [blame] | 59 | shooter::Shooter shooter_; |
James Kuszmaul | b1b2d8e | 2020-02-21 21:11:46 -0800 | [diff] [blame] | 60 | turret::Aimer aimer_; |
| 61 | |
| 62 | aos::Fetcher<frc971::control_loops::drivetrain::Status> |
| 63 | drivetrain_status_fetcher_; |
James Kuszmaul | a53c3ac | 2020-02-22 19:36:01 -0800 | [diff] [blame] | 64 | aos::Fetcher<aos::JoystickState> joystick_state_fetcher_; |
Sabina Davis | cf08b15 | 2020-01-31 22:12:09 -0800 | [diff] [blame] | 65 | |
John Park | 0a245a0 | 2020-02-02 14:10:15 -0800 | [diff] [blame] | 66 | Climber climber_; |
Austin Schuh | 78f0bfd | 2020-02-29 23:04:21 -0800 | [diff] [blame] | 67 | |
Austin Schuh | 13e5552 | 2020-02-29 23:11:17 -0800 | [diff] [blame] | 68 | aos::monotonic_clock::time_point shooting_start_time_ = |
| 69 | aos::monotonic_clock::min_time; |
| 70 | |
Austin Schuh | 78f0bfd | 2020-02-29 23:04:21 -0800 | [diff] [blame] | 71 | double time_ = 0.0; |
| 72 | |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 73 | DISALLOW_COPY_AND_ASSIGN(Superstructure); |
| 74 | }; |
| 75 | |
| 76 | } // namespace superstructure |
| 77 | } // namespace control_loops |
| 78 | } // namespace y2020 |
| 79 | |
| 80 | #endif // y2020_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_ |