blob: 1a9d401cfa638abf89282f6b8971eeaccdb4e6e7 [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
4#include "aos/controls/control_loop.h"
5#include "aos/events/event_loop.h"
James Kuszmaula53c3ac2020-02-22 19:36:01 -08006#include "aos/robot_state/joystick_state_generated.h"
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -08007#include "frc971/control_loops/drivetrain/drivetrain_status_generated.h"
Stephan Massaltd021f972020-01-05 20:41:23 -08008#include "y2020/constants.h"
Sabina Davis0f31d3f2020-02-20 20:41:00 -08009#include "y2020/control_loops/superstructure/shooter/shooter.h"
Stephan Massaltd021f972020-01-05 20:41:23 -080010#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 Park0a245a02020-02-02 14:10:15 -080014#include "y2020/control_loops/superstructure/climber.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
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 Schuh2fb23642020-02-29 15:10:51 -080027 // 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 Schuh78f0bfd2020-02-29 23:04:21 -080032 static constexpr double kHoodFrictionGain = 40.0;
33 static constexpr double kHoodFrictionVoltageLimit = 1.5;
34
Kai Tinkessfb460372020-02-08 14:05:48 -080035 using PotAndAbsoluteEncoderSubsystem =
36 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem<
37 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator,
38 ::frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus>;
Sabina Daviscf08b152020-01-31 22:12:09 -080039 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 Davis0f2d38c2020-02-08 17:01:21 -080045 const AbsoluteEncoderSubsystem &intake_joint() const { return intake_joint_; }
Kai Tinkessfb460372020-02-08 14:05:48 -080046 const PotAndAbsoluteEncoderSubsystem &turret() const { return turret_; }
Sabina Davis0f31d3f2020-02-20 20:41:00 -080047 const shooter::Shooter &shooter() const { return shooter_; }
Sabina Daviscf08b152020-01-31 22:12:09 -080048
Stephan Massaltd021f972020-01-05 20:41:23 -080049 protected:
50 virtual void RunIteration(const Goal *unsafe_goal, const Position *position,
51 aos::Sender<Output>::Builder *output,
52 aos::Sender<Status>::Builder *status) override;
53
54 private:
Sabina Daviscf08b152020-01-31 22:12:09 -080055 AbsoluteEncoderSubsystem hood_;
Sabina Davis0f2d38c2020-02-08 17:01:21 -080056 AbsoluteEncoderSubsystem intake_joint_;
Kai Tinkessfb460372020-02-08 14:05:48 -080057 PotAndAbsoluteEncoderSubsystem turret_;
Sabina Davis0f31d3f2020-02-20 20:41:00 -080058 shooter::Shooter shooter_;
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080059 turret::Aimer aimer_;
60
61 aos::Fetcher<frc971::control_loops::drivetrain::Status>
62 drivetrain_status_fetcher_;
James Kuszmaula53c3ac2020-02-22 19:36:01 -080063 aos::Fetcher<aos::JoystickState> joystick_state_fetcher_;
Sabina Daviscf08b152020-01-31 22:12:09 -080064
John Park0a245a02020-02-02 14:10:15 -080065 Climber climber_;
Austin Schuh78f0bfd2020-02-29 23:04:21 -080066
Austin Schuh13e55522020-02-29 23:11:17 -080067 aos::monotonic_clock::time_point shooting_start_time_ =
68 aos::monotonic_clock::min_time;
69
Austin Schuh78f0bfd2020-02-29 23:04:21 -080070 double time_ = 0.0;
71
Stephan Massaltd021f972020-01-05 20:41:23 -080072 DISALLOW_COPY_AND_ASSIGN(Superstructure);
73};
74
75} // namespace superstructure
76} // namespace control_loops
77} // namespace y2020
78
79#endif // y2020_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_