blob: 1100b86dd3bef89c2f85db204d528ccbe3a7aba8 [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"
8#include "frc971/control_loops/drivetrain/drivetrain_status_generated.h"
9#include "y2023/constants.h"
James Kuszmaulcf451fb2023-03-10 20:42:36 -080010#include "y2023/constants/constants_generated.h"
milind-u738832d2023-02-24 19:55:54 -080011#include "y2023/control_loops/drivetrain/drivetrain_can_position_generated.h"
milind-u01bbcf22023-02-20 18:00:28 -080012#include "y2023/control_loops/superstructure/arm/arm.h"
Maxwell Hendersonb392b742023-03-05 07:53:51 -080013#include "y2023/control_loops/superstructure/arm/arm_trajectories_generated.h"
Maxwell Henderson589cf272023-02-22 15:56:40 -080014#include "y2023/control_loops/superstructure/end_effector.h"
Maxwell Hendersonad312342023-01-10 12:07:47 -080015#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 Hendersonb392b742023-03-05 07:53:51 -080020using y2023::control_loops::superstructure::arm::ArmTrajectories;
21using y2023::control_loops::superstructure::arm::TrajectoryAndParams;
22
Maxwell Hendersonad312342023-01-10 12:07:47 -080023namespace y2023 {
24namespace control_loops {
25namespace superstructure {
26
27class 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 Henderson8ca44562023-02-23 13:11:51 -080040 using AbsoluteEncoderSubsystem =
41 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem<
42 ::frc971::zeroing::AbsoluteEncoderZeroingEstimator,
43 ::frc971::control_loops::AbsoluteEncoderProfiledJointStatus>;
44
Maxwell Hendersonb392b742023-03-05 07:53:51 -080045 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 Hendersonad312342023-01-10 12:07:47 -080050
51 double robot_velocity() const;
52
Maxwell Henderson8ca44562023-02-23 13:11:51 -080053 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 Hendersonb392b742023-03-05 07:53:51 -080057 static const aos::FlatbufferVector<ArmTrajectories> GetArmTrajectories(
58 const std::string &filename) {
59 return aos::FileToFlatbuffer<arm::ArmTrajectories>(filename);
60 }
61
Maxwell Hendersonad312342023-01-10 12:07:47 -080062 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 Kuszmaulcf451fb2023-03-10 20:42:36 -080068 // Returns the Y coordinate of a game piece given the time-of-flight reading.
69 std::optional<double> LateralOffsetForTimeOfFlight(double reading);
70
Maxwell Hendersonad312342023-01-10 12:07:47 -080071 std::shared_ptr<const constants::Values> values_;
James Kuszmaulcf451fb2023-03-10 20:42:36 -080072 frc971::constants::ConstantsFetcher<Constants> constants_fetcher_;
Maxwell Hendersonad312342023-01-10 12:07:47 -080073
74 aos::Fetcher<frc971::control_loops::drivetrain::Status>
75 drivetrain_status_fetcher_;
76 aos::Fetcher<aos::JoystickState> joystick_state_fetcher_;
77
milind-u01bbcf22023-02-20 18:00:28 -080078 arm::Arm arm_;
Maxwell Henderson589cf272023-02-22 15:56:40 -080079 EndEffector end_effector_;
Maxwell Henderson8ca44562023-02-23 13:11:51 -080080 AbsoluteEncoderSubsystem wrist_;
milind-u01bbcf22023-02-20 18:00:28 -080081
Maxwell Hendersonad312342023-01-10 12:07:47 -080082 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_