Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 1 | #ifndef Y2023_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_ |
| 2 | #define Y2023_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_ |
| 3 | |
| 4 | #include "aos/events/event_loop.h" |
Maxwell Henderson | b392b74 | 2023-03-05 07:53:51 -0800 | [diff] [blame] | 5 | #include "aos/json_to_flatbuffer.h" |
James Kuszmaul | cf451fb | 2023-03-10 20:42:36 -0800 | [diff] [blame] | 6 | #include "frc971/constants/constants_sender_lib.h" |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 7 | #include "frc971/control_loops/control_loop.h" |
Maxwell Henderson | cef6f04 | 2023-05-26 14:38:09 -0700 | [diff] [blame^] | 8 | #include "frc971/control_loops/drivetrain/drivetrain_can_position_generated.h" |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 9 | #include "frc971/control_loops/drivetrain/drivetrain_status_generated.h" |
| 10 | #include "y2023/constants.h" |
James Kuszmaul | cf451fb | 2023-03-10 20:42:36 -0800 | [diff] [blame] | 11 | #include "y2023/constants/constants_generated.h" |
milind-u | 01bbcf2 | 2023-02-20 18:00:28 -0800 | [diff] [blame] | 12 | #include "y2023/control_loops/superstructure/arm/arm.h" |
Maxwell Henderson | b392b74 | 2023-03-05 07:53:51 -0800 | [diff] [blame] | 13 | #include "y2023/control_loops/superstructure/arm/arm_trajectories_generated.h" |
Maxwell Henderson | 589cf27 | 2023-02-22 15:56:40 -0800 | [diff] [blame] | 14 | #include "y2023/control_loops/superstructure/end_effector.h" |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 15 | #include "y2023/control_loops/superstructure/superstructure_goal_generated.h" |
| 16 | #include "y2023/control_loops/superstructure/superstructure_output_generated.h" |
| 17 | #include "y2023/control_loops/superstructure/superstructure_position_generated.h" |
| 18 | #include "y2023/control_loops/superstructure/superstructure_status_generated.h" |
| 19 | |
Maxwell Henderson | b392b74 | 2023-03-05 07:53:51 -0800 | [diff] [blame] | 20 | using y2023::control_loops::superstructure::arm::ArmTrajectories; |
| 21 | using y2023::control_loops::superstructure::arm::TrajectoryAndParams; |
| 22 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 23 | namespace y2023 { |
| 24 | namespace control_loops { |
| 25 | namespace superstructure { |
| 26 | |
| 27 | class Superstructure |
| 28 | : public ::frc971::controls::ControlLoop<Goal, Position, Status, Output> { |
| 29 | public: |
| 30 | using RelativeEncoderSubsystem = |
| 31 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem< |
| 32 | ::frc971::zeroing::RelativeEncoderZeroingEstimator, |
| 33 | ::frc971::control_loops::RelativeEncoderProfiledJointStatus>; |
| 34 | |
| 35 | using PotAndAbsoluteEncoderSubsystem = |
| 36 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem< |
| 37 | ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator, |
| 38 | ::frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus>; |
| 39 | |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 40 | using AbsoluteEncoderSubsystem = |
| 41 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem< |
| 42 | ::frc971::zeroing::AbsoluteEncoderZeroingEstimator, |
| 43 | ::frc971::control_loops::AbsoluteEncoderProfiledJointStatus>; |
| 44 | |
Maxwell Henderson | b392b74 | 2023-03-05 07:53:51 -0800 | [diff] [blame] | 45 | explicit Superstructure( |
| 46 | ::aos::EventLoop *event_loop, |
| 47 | std::shared_ptr<const constants::Values> values, |
| 48 | const aos::FlatbufferVector<ArmTrajectories> &arm_trajectories, |
| 49 | const ::std::string &name = "/superstructure"); |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 50 | |
| 51 | double robot_velocity() const; |
| 52 | |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 53 | inline const arm::Arm &arm() const { return arm_; } |
| 54 | inline const EndEffector &end_effector() const { return end_effector_; } |
| 55 | inline const AbsoluteEncoderSubsystem &wrist() const { return wrist_; } |
| 56 | |
Maxwell Henderson | b392b74 | 2023-03-05 07:53:51 -0800 | [diff] [blame] | 57 | static const aos::FlatbufferVector<ArmTrajectories> GetArmTrajectories( |
| 58 | const std::string &filename) { |
| 59 | return aos::FileToFlatbuffer<arm::ArmTrajectories>(filename); |
| 60 | } |
| 61 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 62 | protected: |
| 63 | virtual void RunIteration(const Goal *unsafe_goal, const Position *position, |
| 64 | aos::Sender<Output>::Builder *output, |
| 65 | aos::Sender<Status>::Builder *status) override; |
| 66 | |
| 67 | private: |
James Kuszmaul | cf451fb | 2023-03-10 20:42:36 -0800 | [diff] [blame] | 68 | // Returns the Y coordinate of a game piece given the time-of-flight reading. |
| 69 | std::optional<double> LateralOffsetForTimeOfFlight(double reading); |
| 70 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 71 | std::shared_ptr<const constants::Values> values_; |
James Kuszmaul | cf451fb | 2023-03-10 20:42:36 -0800 | [diff] [blame] | 72 | frc971::constants::ConstantsFetcher<Constants> constants_fetcher_; |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 73 | |
| 74 | aos::Fetcher<frc971::control_loops::drivetrain::Status> |
| 75 | drivetrain_status_fetcher_; |
| 76 | aos::Fetcher<aos::JoystickState> joystick_state_fetcher_; |
| 77 | |
milind-u | 01bbcf2 | 2023-02-20 18:00:28 -0800 | [diff] [blame] | 78 | arm::Arm arm_; |
Maxwell Henderson | 589cf27 | 2023-02-22 15:56:40 -0800 | [diff] [blame] | 79 | EndEffector end_effector_; |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 80 | AbsoluteEncoderSubsystem wrist_; |
milind-u | 01bbcf2 | 2023-02-20 18:00:28 -0800 | [diff] [blame] | 81 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 82 | aos::Alliance alliance_ = aos::Alliance::kInvalid; |
| 83 | |
| 84 | DISALLOW_COPY_AND_ASSIGN(Superstructure); |
| 85 | }; |
| 86 | |
| 87 | } // namespace superstructure |
| 88 | } // namespace control_loops |
| 89 | } // namespace y2023 |
| 90 | |
| 91 | #endif // Y2023_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_ |