Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AC_PID/AC_P_2D.h
Views: 1798
#pragma once12/// @file AC_P_2D.h3/// @brief 2-axis P controller with EEPROM-backed storage of constants.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// constructor14AC_P_2D(float initial_p);1516CLASS_NO_COPY(AC_P_2D);1718// set target and measured inputs to P controller and calculate outputs19Vector2f update_all(postype_t &target_x, postype_t &target_y, const Vector2f &measurement) WARN_IF_UNUSED;2021// set target and measured inputs to P controller and calculate outputs22// measurement is provided as 3-axis vector but only x and y are used23Vector2f update_all(postype_t &target_x, postype_t &target_y, const Vector3f &measurement) WARN_IF_UNUSED {24return update_all(target_x, target_y, Vector2f{measurement.x, measurement.y});25}2627// set_limits - sets the maximum error to limit output and first and second derivative of output28void set_limits(float output_max, float D_Out_max = 0.0f, float D2_Out_max = 0.0f);2930// set_error_max - reduce maximum position error to error_max31// to be called after setting limits32void set_error_max(float error_max);3334// get_error_max - return maximum position error35float get_error_max() { return _error_max; }3637// save gain to eeprom38void save_gains() { _kp.save(); }3940// get accessors41AP_Float &kP() WARN_IF_UNUSED { return _kp; }42const AP_Float &kP() const WARN_IF_UNUSED { return _kp; }43const Vector2f& 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 variables57Vector2f _error; // error between target and measured58float _error_max; // error limit in positive direction59float _D1_max; // maximum first derivative of output6061const float default_kp;62};636465