blob: 0c8b2c06540b037effe8dc1c077cb6eac309b51b [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"
Maxwell Hendersonad312342023-01-10 12:07:47 -08006#include "frc971/control_loops/control_loop.h"
7#include "frc971/control_loops/drivetrain/drivetrain_status_generated.h"
8#include "y2023/constants.h"
milind-u738832d2023-02-24 19:55:54 -08009#include "y2023/control_loops/drivetrain/drivetrain_can_position_generated.h"
milind-u01bbcf22023-02-20 18:00:28 -080010#include "y2023/control_loops/superstructure/arm/arm.h"
Maxwell Hendersonb392b742023-03-05 07:53:51 -080011#include "y2023/control_loops/superstructure/arm/arm_trajectories_generated.h"
Maxwell Henderson589cf272023-02-22 15:56:40 -080012#include "y2023/control_loops/superstructure/end_effector.h"
Maxwell Hendersonad312342023-01-10 12:07:47 -080013#include "y2023/control_loops/superstructure/superstructure_goal_generated.h"
14#include "y2023/control_loops/superstructure/superstructure_output_generated.h"
15#include "y2023/control_loops/superstructure/superstructure_position_generated.h"
16#include "y2023/control_loops/superstructure/superstructure_status_generated.h"
17
Maxwell Hendersonb392b742023-03-05 07:53:51 -080018using y2023::control_loops::superstructure::arm::ArmTrajectories;
19using y2023::control_loops::superstructure::arm::TrajectoryAndParams;
20
Maxwell Hendersonad312342023-01-10 12:07:47 -080021namespace y2023 {
22namespace control_loops {
23namespace superstructure {
24
25class Superstructure
26 : public ::frc971::controls::ControlLoop<Goal, Position, Status, Output> {
27 public:
28 using RelativeEncoderSubsystem =
29 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem<
30 ::frc971::zeroing::RelativeEncoderZeroingEstimator,
31 ::frc971::control_loops::RelativeEncoderProfiledJointStatus>;
32
33 using PotAndAbsoluteEncoderSubsystem =
34 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem<
35 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator,
36 ::frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus>;
37
Maxwell Henderson8ca44562023-02-23 13:11:51 -080038 using AbsoluteEncoderSubsystem =
39 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem<
40 ::frc971::zeroing::AbsoluteEncoderZeroingEstimator,
41 ::frc971::control_loops::AbsoluteEncoderProfiledJointStatus>;
42
Maxwell Hendersonb392b742023-03-05 07:53:51 -080043 explicit Superstructure(
44 ::aos::EventLoop *event_loop,
45 std::shared_ptr<const constants::Values> values,
46 const aos::FlatbufferVector<ArmTrajectories> &arm_trajectories,
47 const ::std::string &name = "/superstructure");
Maxwell Hendersonad312342023-01-10 12:07:47 -080048
49 double robot_velocity() const;
50
Maxwell Henderson8ca44562023-02-23 13:11:51 -080051 inline const arm::Arm &arm() const { return arm_; }
52 inline const EndEffector &end_effector() const { return end_effector_; }
53 inline const AbsoluteEncoderSubsystem &wrist() const { return wrist_; }
54
Maxwell Hendersonb392b742023-03-05 07:53:51 -080055 static const aos::FlatbufferVector<ArmTrajectories> GetArmTrajectories(
56 const std::string &filename) {
57 return aos::FileToFlatbuffer<arm::ArmTrajectories>(filename);
58 }
59
Maxwell Hendersonad312342023-01-10 12:07:47 -080060 protected:
61 virtual void RunIteration(const Goal *unsafe_goal, const Position *position,
62 aos::Sender<Output>::Builder *output,
63 aos::Sender<Status>::Builder *status) override;
64
65 private:
66 std::shared_ptr<const constants::Values> values_;
67
68 aos::Fetcher<frc971::control_loops::drivetrain::Status>
69 drivetrain_status_fetcher_;
70 aos::Fetcher<aos::JoystickState> joystick_state_fetcher_;
71
milind-u01bbcf22023-02-20 18:00:28 -080072 arm::Arm arm_;
Maxwell Henderson589cf272023-02-22 15:56:40 -080073 EndEffector end_effector_;
Maxwell Henderson8ca44562023-02-23 13:11:51 -080074 AbsoluteEncoderSubsystem wrist_;
milind-u01bbcf22023-02-20 18:00:28 -080075
Maxwell Hendersonad312342023-01-10 12:07:47 -080076 aos::Alliance alliance_ = aos::Alliance::kInvalid;
77
78 DISALLOW_COPY_AND_ASSIGN(Superstructure);
79};
80
81} // namespace superstructure
82} // namespace control_loops
83} // namespace y2023
84
85#endif // Y2023_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_