blob: d0cd0db2fec089a7b7a4271817b46c55175bdeae [file] [log] [blame]
Ariv Diggi0af59c02023-10-07 13:15:39 -07001#ifndef Y2023_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_
2#define Y2023_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_
3
4#include "aos/events/event_loop.h"
5#include "aos/json_to_flatbuffer.h"
6#include "frc971/constants/constants_sender_lib.h"
7#include "frc971/control_loops/control_loop.h"
8#include "frc971/control_loops/drivetrain/drivetrain_can_position_generated.h"
9#include "frc971/control_loops/drivetrain/drivetrain_status_generated.h"
10#include "y2023_bot3/constants.h"
11#include "y2023_bot3/constants/constants_generated.h"
12#include "y2023_bot3/control_loops/superstructure/superstructure_goal_generated.h"
13#include "y2023_bot3/control_loops/superstructure/superstructure_output_generated.h"
14#include "y2023_bot3/control_loops/superstructure/superstructure_position_generated.h"
15#include "y2023_bot3/control_loops/superstructure/superstructure_status_generated.h"
16
17namespace y2023_bot3 {
18namespace control_loops {
19namespace superstructure {
20
21class Superstructure
22 : public ::frc971::controls::ControlLoop<Goal, Position, Status, Output> {
23 public:
Maxwell Henderson43684fa2023-11-06 11:08:06 -080024 using PotAndAbsoluteEncoderSubsystem =
25 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem<
26 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator,
27 ::frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus>;
28
Ariv Diggi0af59c02023-10-07 13:15:39 -070029 explicit Superstructure(::aos::EventLoop *event_loop,
30 std::shared_ptr<const constants::Values> values,
31 const ::std::string &name = "/superstructure");
32
33 double robot_velocity() const;
34
35 protected:
36 virtual void RunIteration(const Goal *unsafe_goal, const Position *position,
37 aos::Sender<Output>::Builder *output,
38 aos::Sender<Status>::Builder *status) override;
39
40 private:
41 // Returns the Y coordinate of a game piece given the time-of-flight reading.
42 std::optional<double> LateralOffsetForTimeOfFlight(double reading);
43
44 std::shared_ptr<const constants::Values> values_;
Ariv Diggic892e922023-10-21 15:52:06 -070045
Ariv Diggi0af59c02023-10-07 13:15:39 -070046 aos::Alliance alliance_ = aos::Alliance::kInvalid;
Ariv Diggi0af59c02023-10-07 13:15:39 -070047 DISALLOW_COPY_AND_ASSIGN(Superstructure);
48};
49
50} // namespace superstructure
51} // namespace control_loops
52} // namespace y2023_bot3
53
54#endif // Y2023_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_