blob: 03afaf9a2bd0ae91b346e4c9c8f4a4aaac276c03 [file] [log] [blame]
milind-u086d7262022-01-19 20:44:18 -08001#ifndef Y2022_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_
2#define Y2022_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_
3
milind-u086d7262022-01-19 20:44:18 -08004#include "aos/events/event_loop.h"
Siddhant Kanwar0e37f592022-02-21 19:26:50 -08005#include "frc971/control_loops/control_loop.h"
Henry Speiser55aa3ba2022-02-21 23:21:12 -08006#include "frc971/control_loops/drivetrain/drivetrain_status_generated.h"
milind-u086d7262022-01-19 20:44:18 -08007#include "y2022/constants.h"
Austin Schuh39f26f62022-02-24 21:34:46 -08008#include "y2022/control_loops/superstructure/catapult/catapult.h"
Milind Upadhyay225156b2022-02-25 22:42:12 -08009#include "y2022/control_loops/superstructure/collision_avoidance.h"
Ravago Jones5da06352022-03-04 20:26:24 -080010#include "y2022/control_loops/superstructure/superstructure_can_position_generated.h"
milind-u086d7262022-01-19 20:44:18 -080011#include "y2022/control_loops/superstructure/superstructure_goal_generated.h"
12#include "y2022/control_loops/superstructure/superstructure_output_generated.h"
13#include "y2022/control_loops/superstructure/superstructure_position_generated.h"
14#include "y2022/control_loops/superstructure/superstructure_status_generated.h"
15
16namespace y2022 {
17namespace control_loops {
18namespace superstructure {
19
20class Superstructure
21 : public ::frc971::controls::ControlLoop<Goal, Position, Status, Output> {
22 public:
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080023 using RelativeEncoderSubsystem =
24 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem<
25 ::frc971::zeroing::RelativeEncoderZeroingEstimator,
26 ::frc971::control_loops::RelativeEncoderProfiledJointStatus>;
27
Henry Speiser55aa3ba2022-02-21 23:21:12 -080028 using PotAndAbsoluteEncoderSubsystem =
29 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem<
30 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator,
31 ::frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus>;
32
Milind Upadhyay47e0d032022-03-05 23:06:25 -080033 static constexpr double kTurretGoalThreshold = 0.05;
34 static constexpr double kCatapultGoalThreshold = 0.05;
Ravago Jones5da06352022-03-04 20:26:24 -080035 // potentiometer will be more noisy
36 static constexpr double kFlipperGoalThreshold = 0.05;
37
milind-u086d7262022-01-19 20:44:18 -080038 explicit Superstructure(::aos::EventLoop *event_loop,
Milind Upadhyay225156b2022-02-25 22:42:12 -080039 std::shared_ptr<const constants::Values> values,
milind-u086d7262022-01-19 20:44:18 -080040 const ::std::string &name = "/superstructure");
41
Henry Speiser55aa3ba2022-02-21 23:21:12 -080042 inline const PotAndAbsoluteEncoderSubsystem &intake_front() const {
43 return intake_front_;
44 }
45 inline const PotAndAbsoluteEncoderSubsystem &intake_back() const {
46 return intake_back_;
47 }
48 inline const PotAndAbsoluteEncoderSubsystem &turret() const {
49 return turret_;
50 }
51 inline const RelativeEncoderSubsystem &climber() const { return climber_; }
52
53 double robot_velocity() const;
54
milind-u086d7262022-01-19 20:44:18 -080055 protected:
56 virtual void RunIteration(const Goal *unsafe_goal, const Position *position,
57 aos::Sender<Output>::Builder *output,
58 aos::Sender<Status>::Builder *status) override;
59
60 private:
Austin Schuh39f26f62022-02-24 21:34:46 -080061 std::shared_ptr<const constants::Values> values_;
62
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080063 RelativeEncoderSubsystem climber_;
Henry Speiser55aa3ba2022-02-21 23:21:12 -080064 PotAndAbsoluteEncoderSubsystem intake_front_;
65 PotAndAbsoluteEncoderSubsystem intake_back_;
66 PotAndAbsoluteEncoderSubsystem turret_;
Ravago Jones5da06352022-03-04 20:26:24 -080067 catapult::Catapult catapult_;
Henry Speiser55aa3ba2022-02-21 23:21:12 -080068
Milind Upadhyay225156b2022-02-25 22:42:12 -080069 CollisionAvoidance collision_avoidance_;
70
Henry Speiser55aa3ba2022-02-21 23:21:12 -080071 aos::Fetcher<frc971::control_loops::drivetrain::Status>
72 drivetrain_status_fetcher_;
Ravago Jones5da06352022-03-04 20:26:24 -080073 aos::Fetcher<CANPosition> can_position_fetcher_;
74
75 int prev_shot_count_ = 0;
76
77 bool flippers_open_ = false;
78 bool reseating_in_catapult_ = false;
79 bool fire_ = false;
80
81 aos::monotonic_clock::time_point intake_beambreak_timer_ =
82 aos::monotonic_clock::min_time;
83 aos::monotonic_clock::time_point transferring_timer_ =
84 aos::monotonic_clock::min_time;
85 aos::monotonic_clock::time_point loading_timer_ =
86 aos::monotonic_clock::min_time;
87 aos::monotonic_clock::time_point flipper_opening_start_time_ =
88 aos::monotonic_clock::min_time;
89 SuperstructureState state_ = SuperstructureState::IDLE;
90 IntakeState intake_state_ = IntakeState::NO_BALL;
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080091
milind-u086d7262022-01-19 20:44:18 -080092 DISALLOW_COPY_AND_ASSIGN(Superstructure);
milind-u086d7262022-01-19 20:44:18 -080093};
94
95} // namespace superstructure
96} // namespace control_loops
97} // namespace y2022
98
99#endif // Y2022_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_