blob: ff387704926fef69f6bd8d8fc44b182dcaee5927 [file] [log] [blame]
Stephan Massaltd021f972020-01-05 20:41:23 -08001#ifndef y2020_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_
2#define y2020_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_
3
Stephan Massaltd021f972020-01-05 20:41:23 -08004#include "aos/events/event_loop.h"
Ravago Jonesac850da2021-10-13 20:38:29 -07005#include "frc971/control_loops/control_loop.h"
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -08006#include "frc971/control_loops/drivetrain/drivetrain_status_generated.h"
James Kuszmaul7077d342021-06-09 20:23:58 -07007#include "frc971/input/joystick_state_generated.h"
James Kuszmaulec635d22023-08-12 18:39:24 -07008#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 Massaltd021f972020-01-05 20:41:23 -080011#include "y2020/constants.h"
milind-ud53408e2021-10-21 19:43:58 -070012#include "y2020/control_loops/superstructure/hood/hood_encoder_zeroing_estimator.h"
Sabina Davis0f31d3f2020-02-20 20:41:00 -080013#include "y2020/control_loops/superstructure/shooter/shooter.h"
Stephan Massaltd021f972020-01-05 20:41:23 -080014#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 Kuszmaulb1b2d8e2020-02-21 21:11:46 -080018#include "y2020/control_loops/superstructure/turret/aiming.h"
Stephan Massaltd021f972020-01-05 20:41:23 -080019
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080020namespace y2020::control_loops::superstructure {
Stephan Massaltd021f972020-01-05 20:41:23 -080021
22class Superstructure
James Kuszmaul61750662021-06-21 21:32:33 -070023 : public ::frc971::controls::ControlLoop<Goal, Position, Status, Output> {
Stephan Massaltd021f972020-01-05 20:41:23 -080024 public:
25 explicit Superstructure(::aos::EventLoop *event_loop,
26 const ::std::string &name = "/superstructure");
27
Austin Schuh2fb23642020-02-29 15:10:51 -080028 // Terms to control the velocity gain for the friction compensation, and the
29 // voltage cap.
milind-uf70e8e12021-10-02 12:36:00 -070030 static constexpr double kTurretFrictionGain = 0.0;
Austin Schuh2fb23642020-02-29 15:10:51 -080031 static constexpr double kTurretFrictionVoltageLimit = 1.5;
milind-uf70e8e12021-10-02 12:36:00 -070032 static constexpr double kTurretDitherGain = 0.0;
Ravago Jonesac850da2021-10-13 20:38:29 -070033 static constexpr std::chrono::milliseconds kPreloadingTimeout =
Austin Schuhdf240b42021-10-13 21:33:43 -070034 std::chrono::seconds(2);
Ravago Jonesac850da2021-10-13 20:38:29 -070035 static constexpr std::chrono::milliseconds kPreloadingBackpowerDuration =
Austin Schuh6a92a2b2021-10-29 23:07:15 -070036 std::chrono::milliseconds(55);
Austin Schuh2fb23642020-02-29 15:10:51 -080037
Kai Tinkessfb460372020-02-08 14:05:48 -080038 using PotAndAbsoluteEncoderSubsystem =
39 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem<
40 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator,
41 ::frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus>;
Sabina Daviscf08b152020-01-31 22:12:09 -080042 using AbsoluteEncoderSubsystem =
43 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem<
44 ::frc971::zeroing::AbsoluteEncoderZeroingEstimator,
45 ::frc971::control_loops::AbsoluteEncoderProfiledJointStatus>;
Ravago Jones937587c2020-12-26 17:21:09 -080046 using AbsoluteAndAbsoluteEncoderSubsystem =
47 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem<
milind-ud53408e2021-10-21 19:43:58 -070048 hood::HoodEncoderZeroingEstimator,
Ravago Jones937587c2020-12-26 17:21:09 -080049 ::frc971::control_loops::
milind-ud53408e2021-10-21 19:43:58 -070050 AbsoluteAndAbsoluteEncoderProfiledJointStatus,
51 frc971::zeroing::AbsoluteAndAbsoluteEncoderZeroingEstimator>;
Sabina Daviscf08b152020-01-31 22:12:09 -080052
Ravago Jones937587c2020-12-26 17:21:09 -080053 const AbsoluteAndAbsoluteEncoderSubsystem &hood() const { return hood_; }
Sabina Davis0f2d38c2020-02-08 17:01:21 -080054 const AbsoluteEncoderSubsystem &intake_joint() const { return intake_joint_; }
Kai Tinkessfb460372020-02-08 14:05:48 -080055 const PotAndAbsoluteEncoderSubsystem &turret() const { return turret_; }
Sabina Davis0f31d3f2020-02-20 20:41:00 -080056 const shooter::Shooter &shooter() const { return shooter_; }
milind upadhyayaec1aee2020-10-13 13:44:33 -070057 double robot_speed() const;
Sabina Daviscf08b152020-01-31 22:12:09 -080058
Stephan Massaltd021f972020-01-05 20:41:23 -080059 protected:
60 virtual void RunIteration(const Goal *unsafe_goal, const Position *position,
61 aos::Sender<Output>::Builder *output,
62 aos::Sender<Status>::Builder *status) override;
63
64 private:
Ravago Jones937587c2020-12-26 17:21:09 -080065 AbsoluteAndAbsoluteEncoderSubsystem hood_;
Sabina Davis0f2d38c2020-02-08 17:01:21 -080066 AbsoluteEncoderSubsystem intake_joint_;
Kai Tinkessfb460372020-02-08 14:05:48 -080067 PotAndAbsoluteEncoderSubsystem turret_;
Sabina Davis0f31d3f2020-02-20 20:41:00 -080068 shooter::Shooter shooter_;
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080069 turret::Aimer aimer_;
70
71 aos::Fetcher<frc971::control_loops::drivetrain::Status>
72 drivetrain_status_fetcher_;
James Kuszmaula53c3ac2020-02-22 19:36:01 -080073 aos::Fetcher<aos::JoystickState> joystick_state_fetcher_;
Sabina Daviscf08b152020-01-31 22:12:09 -080074
Austin Schuh13e55522020-02-29 23:11:17 -080075 aos::monotonic_clock::time_point shooting_start_time_ =
76 aos::monotonic_clock::min_time;
Ravago Jonesac850da2021-10-13 20:38:29 -070077 aos::monotonic_clock::time_point preloading_timeout_ =
78 aos::monotonic_clock::min_time;
79 aos::monotonic_clock::time_point preloading_backpower_timeout_ =
80 aos::monotonic_clock::min_time;
Austin Schuh13e55522020-02-29 23:11:17 -080081
Austin Schuh01d81c32021-11-06 22:59:56 -070082 bool has_turret_ = true;
83
milind1f1dca32021-07-03 13:50:07 -070084 aos::SendFailureCounter status_failure_counter_;
85
Stephan Massaltd021f972020-01-05 20:41:23 -080086 DISALLOW_COPY_AND_ASSIGN(Superstructure);
87};
88
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080089} // namespace y2020::control_loops::superstructure
Stephan Massaltd021f972020-01-05 20:41:23 -080090
91#endif // y2020_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_