#pragma once12/// @file AC_P_1D.h3/// @brief Position-based P controller with optional limits on output and its first derivative.45#include <AP_Common/AP_Common.h>6#include <AP_Param/AP_Param.h>78/// @class AC_P_1D9/// @brief Object managing one P controller10class AC_P_1D {11public:1213/// Constructor for 1D P controller with initial gain.14AC_P_1D(float initial_p);1516CLASS_NO_COPY(AC_P_1D);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.21float update_all(postype_t &target, postype_t 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_min, float output_max, float D_Out_max = 0.0f, float D2_Out_max = 0.0f);2627// Reduces error limits to user-specified bounds, respecting previously computed limits.28// Intended to be called after `set_limits()`.29void set_error_limits(float error_min, float error_max);3031// Returns the current minimum error clamp, in controller units.32float get_error_min() const { return _error_min; }3334// Returns the current maximum error clamp, in controller units.35float get_error_max() const { return _error_max; }3637// Saves controller configuration from EEPROM. (not used)38void save_gains() { _kp.save(); }3940// accessors41AP_Float &kP() WARN_IF_UNUSED { return _kp; }42const AP_Float &kP() const WARN_IF_UNUSED { return _kp; }43float get_error() const { return _error; }4445// set accessors46void set_kP(float v) { _kp.set(v); }4748// parameter var table49static const struct AP_Param::GroupInfo var_info[];5051private:5253// parameters54AP_Float _kp;5556// internal variables57float _error; // time step in seconds58float _error_min; // error limit in negative direction59float _error_max; // error limit in positive direction60float _D1_max; // maximum first derivative of output6162const float default_kp;63};646566