#pragma once12/// @file AC_P_2D.h3/// @brief 2D P controller with output limiting, derivative constraint, and EEPROM-backed gain storage.45#include <AP_Common/AP_Common.h>6#include <AP_Param/AP_Param.h>78/// @class AC_P_2D9/// @brief 2-axis P controller10class AC_P_2D {11public:1213/// Constructor for 2D P controller with initial gain.14AC_P_2D(float initial_p);1516CLASS_NO_COPY(AC_P_2D);1718// Computes the P controller output given a target and measurement.19// Applies position error clamping based on configured limits.20// Optionally constrains output slope using the sqrt_controller.21Vector2f update_all(Vector2p &target, const Vector2p &measurement) WARN_IF_UNUSED;2223// Sets limits on output, output slope (D1), and output acceleration (D2).24// For position controllers: output = velocity, D1 = acceleration, D2 = jerk.25void set_limits(float output_max, float D_Out_max = 0.0f, float D2_Out_max = 0.0f);2627// Reduces the maximum allowable error after limit initialization.28// Intended to be called after set_limits().29void set_error_max(float error_max);3031// Returns the current error clamp limit in controller units.32float get_error_max() const { return _error_max; }3334// Saves controller configuration from EEPROM. (not used)35void save_gains() { _kp.save(); }3637// get accessors38AP_Float &kP() WARN_IF_UNUSED { return _kp; }39const AP_Float &kP() const WARN_IF_UNUSED { return _kp; }40const Vector2f& get_error() const { return _error; }4142// set accessors43void set_kP(float v) { _kp.set(v); }4445// parameter var table46static const struct AP_Param::GroupInfo var_info[];4748private:4950// parameters51AP_Float _kp;5253// internal variables54Vector2f _error; // error between target and measured55float _error_max; // error limit in positive direction56float _D1_max; // maximum first derivative of output5758const float default_kp;59};606162