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" |
James Kuszmaul | ec635d2 | 2023-08-12 18:39:24 -0700 | [diff] [blame^] | 10 | #include "frc971/zeroing/absolute_encoder.h" |
| 11 | #include "frc971/zeroing/pot_and_absolute_encoder.h" |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 12 | #include "y2023/constants.h" |
James Kuszmaul | cf451fb | 2023-03-10 20:42:36 -0800 | [diff] [blame] | 13 | #include "y2023/constants/constants_generated.h" |
milind-u | 01bbcf2 | 2023-02-20 18:00:28 -0800 | [diff] [blame] | 14 | #include "y2023/control_loops/superstructure/arm/arm.h" |
Maxwell Henderson | b392b74 | 2023-03-05 07:53:51 -0800 | [diff] [blame] | 15 | #include "y2023/control_loops/superstructure/arm/arm_trajectories_generated.h" |
Maxwell Henderson | 589cf27 | 2023-02-22 15:56:40 -0800 | [diff] [blame] | 16 | #include "y2023/control_loops/superstructure/end_effector.h" |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 17 | #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 Henderson | b392b74 | 2023-03-05 07:53:51 -0800 | [diff] [blame] | 22 | using y2023::control_loops::superstructure::arm::ArmTrajectories; |
| 23 | using y2023::control_loops::superstructure::arm::TrajectoryAndParams; |
| 24 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 25 | namespace y2023 { |
| 26 | namespace control_loops { |
| 27 | namespace superstructure { |
| 28 | |
| 29 | class 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 Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 42 | using AbsoluteEncoderSubsystem = |
| 43 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem< |
| 44 | ::frc971::zeroing::AbsoluteEncoderZeroingEstimator, |
| 45 | ::frc971::control_loops::AbsoluteEncoderProfiledJointStatus>; |
| 46 | |
Maxwell Henderson | b392b74 | 2023-03-05 07:53:51 -0800 | [diff] [blame] | 47 | 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 Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 52 | |
| 53 | double robot_velocity() const; |
| 54 | |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 55 | 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 Henderson | b392b74 | 2023-03-05 07:53:51 -0800 | [diff] [blame] | 59 | static const aos::FlatbufferVector<ArmTrajectories> GetArmTrajectories( |
| 60 | const std::string &filename) { |
| 61 | return aos::FileToFlatbuffer<arm::ArmTrajectories>(filename); |
| 62 | } |
| 63 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 64 | 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 Kuszmaul | cf451fb | 2023-03-10 20:42:36 -0800 | [diff] [blame] | 70 | // Returns the Y coordinate of a game piece given the time-of-flight reading. |
| 71 | std::optional<double> LateralOffsetForTimeOfFlight(double reading); |
| 72 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 73 | std::shared_ptr<const constants::Values> values_; |
James Kuszmaul | cf451fb | 2023-03-10 20:42:36 -0800 | [diff] [blame] | 74 | frc971::constants::ConstantsFetcher<Constants> constants_fetcher_; |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 75 | |
| 76 | aos::Fetcher<frc971::control_loops::drivetrain::Status> |
| 77 | drivetrain_status_fetcher_; |
| 78 | aos::Fetcher<aos::JoystickState> joystick_state_fetcher_; |
| 79 | |
milind-u | 01bbcf2 | 2023-02-20 18:00:28 -0800 | [diff] [blame] | 80 | arm::Arm arm_; |
Maxwell Henderson | 589cf27 | 2023-02-22 15:56:40 -0800 | [diff] [blame] | 81 | EndEffector end_effector_; |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 82 | AbsoluteEncoderSubsystem wrist_; |
milind-u | 01bbcf2 | 2023-02-20 18:00:28 -0800 | [diff] [blame] | 83 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 84 | 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_ |