controls  3.0.0
FeedbackController.h
Go to the documentation of this file.
1 #ifndef CONTROLS_CONTROLLER_FEEDBACK_CONTROLLER_H
2 #define CONTROLS_CONTROLLER_FEEDBACK_CONTROLLER_H
3 
5 
15  static constexpr double MAX_DT = 0.1;
16  static constexpr double EXPLODE_THRESHOLD = 1e4;
17  static constexpr double INTEGRAL_CLAMP = 5.0;
18  static constexpr double INTEGRAL_DECAY_FACTOR = 0.5;
19 
20 private:
21  double error_saturation_limit = 1;
22 
24  Vector18d e = Vector18d::Zero();
25 
26  Vector6d body_integral_error = Vector6d::Zero();
27  Vector6d body_pose_error = Vector6d::Zero();
28  Vector6d body_twist_error = Vector6d::Zero();
29 
31  Vector6d integral = Vector6d::Zero();
32 
39  Vector6d saved_integral = Vector6d::Zero();
40 
41  Vector6d force_i = Vector6d::Zero();
42  Vector6d force_p = Vector6d::Zero();
43  Vector6d force_d = Vector6d::Zero();
44 
45 public:
47 
49  bool saturatedOnYawXYAxis = false;
50 
53 
57  void reset() override;
58 
63 
73  Vector6d getForce(const State& goal, const State& curr, double dt) override;
74 
80  void save_integral();
81 
85  void load_integral();
86 
92  void ramp_integral(double ratio);
93 
99  Vector6d getIntegralError() const;
100 
106  Vector6d getPoseError() const;
107 
113  Vector6d getTwistError() const;
114 
120  Vector6d getIntegralForce() const;
121 
127  void setIntegral(const Vector6d& i);
128 };
129 
130 #endif // CONTROLS_CONTROLLER_FEEDBACK_CONTROLLER_H
Eigen::Matrix< double, 6, 1 > Vector6d
Definition: Types.h:29
Eigen::Matrix< double, 18, 1 > Vector18d
Definition: Types.h:30
Abstract base class for a single-responsibility force controller.
Definition: BaseControllerInterface.h:15
BaseControllerInterface()=default
PID feedback controller with anti-windup integral clamping.
Definition: FeedbackController.h:14
Vector6d getIntegralForce() const
Returns the most recently computed integral force contribution.
Definition: FeedbackController.cpp:244
Vector6d getPoseError() const
Returns the most recently computed body-frame pose error.
Definition: FeedbackController.cpp:236
void ramp_integral(double ratio)
Interpolates the integral term between its current value and the saved snapshot.
Definition: FeedbackController.cpp:226
bool saturatedOnDepthRollPitchAxis
True when the Z, Roll, or Pitch thruster axes are saturated.
Definition: FeedbackController.h:52
void setIntegral(const Vector6d &i)
Directly sets the integral accumulator.
Definition: FeedbackController.cpp:248
void reset() override
Resets all internal state including the integral term.
Definition: FeedbackController.cpp:6
Vector6d getIntegralError() const
Returns the most recently computed body-frame integral error.
Definition: FeedbackController.cpp:232
void load_integral()
Restores the integral term from the most recent saved snapshot.
Definition: FeedbackController.cpp:222
void save_integral()
Saves a snapshot of the current integral term for later restoration.
Definition: FeedbackController.cpp:203
Vector6d getTwistError() const
Returns the most recently computed body-frame twist error.
Definition: FeedbackController.cpp:240
Vector6d getForce(const State &goal, const State &curr, double dt) override
Computes the PID feedback force from the goal and current state.
Definition: FeedbackController.cpp:26
void resetAllExceptDepthIntegral()
Resets all internal state except the depth (Z) integral term.
Definition: FeedbackController.cpp:20
bool saturatedOnYawXYAxis
True when the X, Y, or Yaw thruster axes are saturated.
Definition: FeedbackController.h:49
Full kinematic state of the vehicle.
Definition: Types.h:63