blob: 59e976e9836776604fc97655ef3a8452292cb5e7 [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
James Kuszmaul61750662021-06-21 21:32:33 -07004#include "frc971/control_loops/control_loop.h"
Stephan Massaltd021f972020-01-05 20:41:23 -08005#include "aos/events/event_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"
Stephan Massaltd021f972020-01-05 20:41:23 -08008#include "y2020/constants.h"
Ravago Jones937587c2020-12-26 17:21:09 -08009#include "y2020/control_loops/superstructure/climber.h"
Sabina Davis0f31d3f2020-02-20 20:41:00 -080010#include "y2020/control_loops/superstructure/shooter/shooter.h"
Stephan Massaltd021f972020-01-05 20:41:23 -080011#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 Kuszmaulb1b2d8e2020-02-21 21:11:46 -080015#include "y2020/control_loops/superstructure/turret/aiming.h"
Stephan Massaltd021f972020-01-05 20:41:23 -080016
17namespace y2020 {
18namespace control_loops {
19namespace superstructure {
20
21class Superstructure
James Kuszmaul61750662021-06-21 21:32:33 -070022 : public ::frc971::controls::ControlLoop<Goal, Position, Status, Output> {
Stephan Massaltd021f972020-01-05 20:41:23 -080023 public:
24 explicit Superstructure(::aos::EventLoop *event_loop,
25 const ::std::string &name = "/superstructure");
26
Austin Schuh2fb23642020-02-29 15:10:51 -080027 // Terms to control the velocity gain for the friction compensation, and the
28 // voltage cap.
milind-uf70e8e12021-10-02 12:36:00 -070029 static constexpr double kTurretFrictionGain = 0.0;
Austin Schuh2fb23642020-02-29 15:10:51 -080030 static constexpr double kTurretFrictionVoltageLimit = 1.5;
milind-uf70e8e12021-10-02 12:36:00 -070031 static constexpr double kTurretDitherGain = 0.0;
Austin Schuh2fb23642020-02-29 15:10:51 -080032
Kai Tinkessfb460372020-02-08 14:05:48 -080033 using PotAndAbsoluteEncoderSubsystem =
34 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem<
35 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator,
36 ::frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus>;
Sabina Daviscf08b152020-01-31 22:12:09 -080037 using AbsoluteEncoderSubsystem =
38 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem<
39 ::frc971::zeroing::AbsoluteEncoderZeroingEstimator,
40 ::frc971::control_loops::AbsoluteEncoderProfiledJointStatus>;
Ravago Jones937587c2020-12-26 17:21:09 -080041 using AbsoluteAndAbsoluteEncoderSubsystem =
42 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem<
43 ::frc971::zeroing::AbsoluteAndAbsoluteEncoderZeroingEstimator,
44 ::frc971::control_loops::
45 AbsoluteAndAbsoluteEncoderProfiledJointStatus>;
Sabina Daviscf08b152020-01-31 22:12:09 -080046
Ravago Jones937587c2020-12-26 17:21:09 -080047 const AbsoluteAndAbsoluteEncoderSubsystem &hood() const { return hood_; }
Sabina Davis0f2d38c2020-02-08 17:01:21 -080048 const AbsoluteEncoderSubsystem &intake_joint() const { return intake_joint_; }
Kai Tinkessfb460372020-02-08 14:05:48 -080049 const PotAndAbsoluteEncoderSubsystem &turret() const { return turret_; }
Sabina Davis0f31d3f2020-02-20 20:41:00 -080050 const shooter::Shooter &shooter() const { return shooter_; }
milind upadhyayaec1aee2020-10-13 13:44:33 -070051 double robot_speed() const;
Sabina Daviscf08b152020-01-31 22:12:09 -080052
Stephan Massaltd021f972020-01-05 20:41:23 -080053 protected:
54 virtual void RunIteration(const Goal *unsafe_goal, const Position *position,
55 aos::Sender<Output>::Builder *output,
56 aos::Sender<Status>::Builder *status) override;
57
58 private:
Ravago Jones937587c2020-12-26 17:21:09 -080059 AbsoluteAndAbsoluteEncoderSubsystem hood_;
Sabina Davis0f2d38c2020-02-08 17:01:21 -080060 AbsoluteEncoderSubsystem intake_joint_;
Kai Tinkessfb460372020-02-08 14:05:48 -080061 PotAndAbsoluteEncoderSubsystem turret_;
Sabina Davis0f31d3f2020-02-20 20:41:00 -080062 shooter::Shooter shooter_;
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080063 turret::Aimer aimer_;
64
65 aos::Fetcher<frc971::control_loops::drivetrain::Status>
66 drivetrain_status_fetcher_;
James Kuszmaula53c3ac2020-02-22 19:36:01 -080067 aos::Fetcher<aos::JoystickState> joystick_state_fetcher_;
Sabina Daviscf08b152020-01-31 22:12:09 -080068
John Park0a245a02020-02-02 14:10:15 -080069 Climber climber_;
Austin Schuh78f0bfd2020-02-29 23:04:21 -080070
Austin Schuh13e55522020-02-29 23:11:17 -080071 aos::monotonic_clock::time_point shooting_start_time_ =
72 aos::monotonic_clock::min_time;
73
Stephan Massaltd021f972020-01-05 20:41:23 -080074 DISALLOW_COPY_AND_ASSIGN(Superstructure);
75};
76
77} // namespace superstructure
78} // namespace control_loops
79} // namespace y2020
80
81#endif // y2020_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_