blob: bcee3eadcc851f618ff1af31ed8ded196e22edf7 [file] [log] [blame]
Maxwell Hendersonad312342023-01-10 12:07:47 -08001#ifndef Y2023_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_
2#define Y2023_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_
3
4#include "aos/events/event_loop.h"
Maxwell Hendersonb392b742023-03-05 07:53:51 -08005#include "aos/json_to_flatbuffer.h"
James Kuszmaulcf451fb2023-03-10 20:42:36 -08006#include "frc971/constants/constants_sender_lib.h"
Maxwell Hendersonad312342023-01-10 12:07:47 -08007#include "frc971/control_loops/control_loop.h"
Maxwell Hendersoncef6f042023-05-26 14:38:09 -07008#include "frc971/control_loops/drivetrain/drivetrain_can_position_generated.h"
Maxwell Hendersonad312342023-01-10 12:07:47 -08009#include "frc971/control_loops/drivetrain/drivetrain_status_generated.h"
James Kuszmaulec635d22023-08-12 18:39:24 -070010#include "frc971/zeroing/absolute_encoder.h"
11#include "frc971/zeroing/pot_and_absolute_encoder.h"
Maxwell Hendersonad312342023-01-10 12:07:47 -080012#include "y2023/constants.h"
James Kuszmaulcf451fb2023-03-10 20:42:36 -080013#include "y2023/constants/constants_generated.h"
milind-u01bbcf22023-02-20 18:00:28 -080014#include "y2023/control_loops/superstructure/arm/arm.h"
Maxwell Hendersonb392b742023-03-05 07:53:51 -080015#include "y2023/control_loops/superstructure/arm/arm_trajectories_generated.h"
Maxwell Henderson589cf272023-02-22 15:56:40 -080016#include "y2023/control_loops/superstructure/end_effector.h"
Maxwell Hendersonad312342023-01-10 12:07:47 -080017#include "y2023/control_loops/superstructure/superstructure_goal_generated.h"
18#include "y2023/control_loops/superstructure/superstructure_output_generated.h"
19#include "y2023/control_loops/superstructure/superstructure_position_generated.h"
20#include "y2023/control_loops/superstructure/superstructure_status_generated.h"
21
Maxwell Hendersonb392b742023-03-05 07:53:51 -080022using y2023::control_loops::superstructure::arm::ArmTrajectories;
23using y2023::control_loops::superstructure::arm::TrajectoryAndParams;
24
Maxwell Hendersonad312342023-01-10 12:07:47 -080025namespace y2023 {
26namespace control_loops {
27namespace superstructure {
28
29class Superstructure
30 : public ::frc971::controls::ControlLoop<Goal, Position, Status, Output> {
31 public:
32 using RelativeEncoderSubsystem =
33 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem<
34 ::frc971::zeroing::RelativeEncoderZeroingEstimator,
35 ::frc971::control_loops::RelativeEncoderProfiledJointStatus>;
36
37 using PotAndAbsoluteEncoderSubsystem =
38 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem<
39 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator,
40 ::frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus>;
41
Maxwell Henderson8ca44562023-02-23 13:11:51 -080042 using AbsoluteEncoderSubsystem =
43 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem<
44 ::frc971::zeroing::AbsoluteEncoderZeroingEstimator,
45 ::frc971::control_loops::AbsoluteEncoderProfiledJointStatus>;
46
Maxwell Hendersonb392b742023-03-05 07:53:51 -080047 explicit Superstructure(
48 ::aos::EventLoop *event_loop,
49 std::shared_ptr<const constants::Values> values,
50 const aos::FlatbufferVector<ArmTrajectories> &arm_trajectories,
51 const ::std::string &name = "/superstructure");
Maxwell Hendersonad312342023-01-10 12:07:47 -080052
53 double robot_velocity() const;
54
Maxwell Henderson8ca44562023-02-23 13:11:51 -080055 inline const arm::Arm &arm() const { return arm_; }
56 inline const EndEffector &end_effector() const { return end_effector_; }
57 inline const AbsoluteEncoderSubsystem &wrist() const { return wrist_; }
58
Maxwell Hendersonb392b742023-03-05 07:53:51 -080059 static const aos::FlatbufferVector<ArmTrajectories> GetArmTrajectories(
60 const std::string &filename) {
61 return aos::FileToFlatbuffer<arm::ArmTrajectories>(filename);
62 }
63
Maxwell Hendersonad312342023-01-10 12:07:47 -080064 protected:
65 virtual void RunIteration(const Goal *unsafe_goal, const Position *position,
66 aos::Sender<Output>::Builder *output,
67 aos::Sender<Status>::Builder *status) override;
68
69 private:
James Kuszmaulcf451fb2023-03-10 20:42:36 -080070 // Returns the Y coordinate of a game piece given the time-of-flight reading.
71 std::optional<double> LateralOffsetForTimeOfFlight(double reading);
72
Maxwell Hendersonad312342023-01-10 12:07:47 -080073 std::shared_ptr<const constants::Values> values_;
James Kuszmaulcf451fb2023-03-10 20:42:36 -080074 frc971::constants::ConstantsFetcher<Constants> constants_fetcher_;
Maxwell Hendersonad312342023-01-10 12:07:47 -080075
76 aos::Fetcher<frc971::control_loops::drivetrain::Status>
77 drivetrain_status_fetcher_;
78 aos::Fetcher<aos::JoystickState> joystick_state_fetcher_;
79
milind-u01bbcf22023-02-20 18:00:28 -080080 arm::Arm arm_;
Maxwell Henderson589cf272023-02-22 15:56:40 -080081 EndEffector end_effector_;
Maxwell Henderson8ca44562023-02-23 13:11:51 -080082 AbsoluteEncoderSubsystem wrist_;
milind-u01bbcf22023-02-20 18:00:28 -080083
Maxwell Hendersonad312342023-01-10 12:07:47 -080084 aos::Alliance alliance_ = aos::Alliance::kInvalid;
85
86 DISALLOW_COPY_AND_ASSIGN(Superstructure);
87};
88
89} // namespace superstructure
90} // namespace control_loops
91} // namespace y2023
92
93#endif // Y2023_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_