blob: 4b3d48883b7cc85a6a8dd9d4a4e464e4288667e8 [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"
Ariv Diggic892e922023-10-21 15:52:06 -070012#include "y2023_bot3/control_loops/superstructure/end_effector.h"
Ariv Diggi0af59c02023-10-07 13:15:39 -070013#include "y2023_bot3/control_loops/superstructure/superstructure_goal_generated.h"
14#include "y2023_bot3/control_loops/superstructure/superstructure_output_generated.h"
15#include "y2023_bot3/control_loops/superstructure/superstructure_position_generated.h"
16#include "y2023_bot3/control_loops/superstructure/superstructure_status_generated.h"
17
18namespace y2023_bot3 {
19namespace control_loops {
20namespace superstructure {
21
22class Superstructure
23 : public ::frc971::controls::ControlLoop<Goal, Position, Status, Output> {
24 public:
25 explicit Superstructure(::aos::EventLoop *event_loop,
26 std::shared_ptr<const constants::Values> values,
27 const ::std::string &name = "/superstructure");
28
29 double robot_velocity() const;
30
Ariv Diggic892e922023-10-21 15:52:06 -070031 inline const EndEffector &end_effector() const { return end_effector_; }
32
Ariv Diggi0af59c02023-10-07 13:15:39 -070033 protected:
34 virtual void RunIteration(const Goal *unsafe_goal, const Position *position,
35 aos::Sender<Output>::Builder *output,
36 aos::Sender<Status>::Builder *status) override;
37
38 private:
39 // Returns the Y coordinate of a game piece given the time-of-flight reading.
40 std::optional<double> LateralOffsetForTimeOfFlight(double reading);
41
42 std::shared_ptr<const constants::Values> values_;
43 frc971::constants::ConstantsFetcher<Constants> constants_fetcher_;
44
Ariv Diggic892e922023-10-21 15:52:06 -070045 EndEffector end_effector_;
46
Ariv Diggi0af59c02023-10-07 13:15:39 -070047 aos::Alliance alliance_ = aos::Alliance::kInvalid;
48
49 DISALLOW_COPY_AND_ASSIGN(Superstructure);
50};
51
52} // namespace superstructure
53} // namespace control_loops
54} // namespace y2023_bot3
55
56#endif // Y2023_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_