Pat McC / Mbed 2 deprecated AUV_PIDusna

Dependencies:   mbed BNO055_fusion_AUV

Committer:
pmmccorkell
Date:
Thu Nov 12 20:25:07 2020 +0000
Revision:
4:e89234ca9d4e
Parent:
0:37123f30e8b2
asf

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pmmccorkell 0:37123f30e8b2 1 /*
pmmccorkell 0:37123f30e8b2 2 * PID class for mbed
pmmccorkell 0:37123f30e8b2 3 * US Naval Academy
pmmccorkell 0:37123f30e8b2 4 * Robotics and Control TSD
pmmccorkell 0:37123f30e8b2 5 * Patrick McCorkell
pmmccorkell 0:37123f30e8b2 6 *
pmmccorkell 0:37123f30e8b2 7 * Created: 2019 Dec 11
pmmccorkell 0:37123f30e8b2 8 *
pmmccorkell 0:37123f30e8b2 9 */
pmmccorkell 0:37123f30e8b2 10
pmmccorkell 0:37123f30e8b2 11 #include "mbed.h"
pmmccorkell 0:37123f30e8b2 12
pmmccorkell 0:37123f30e8b2 13 typedef struct {
pmmccorkell 0:37123f30e8b2 14 float Kp;
pmmccorkell 0:37123f30e8b2 15 float Ki;
pmmccorkell 0:37123f30e8b2 16 float Kd;
pmmccorkell 0:37123f30e8b2 17 } PID_GAINS_TypeDef;
pmmccorkell 0:37123f30e8b2 18
pmmccorkell 0:37123f30e8b2 19 class PID
pmmccorkell 0:37123f30e8b2 20 {
pmmccorkell 0:37123f30e8b2 21 public:
pmmccorkell 4:e89234ca9d4e 22 PID (float Kp, float Ki, float Kd, float dt, float deadzone=0);
pmmccorkell 0:37123f30e8b2 23 void calculate_K(float Tu);
pmmccorkell 4:e89234ca9d4e 24 void set_dt(float dt);
pmmccorkell 0:37123f30e8b2 25 void clear_integral();
pmmccorkell 0:37123f30e8b2 26 void clear_error();
pmmccorkell 0:37123f30e8b2 27 void clear_error_previous();
pmmccorkell 0:37123f30e8b2 28 void clear();
pmmccorkell 0:37123f30e8b2 29 void set_K(float Kp, float Ki=0, float Kd=0);
pmmccorkell 0:37123f30e8b2 30 void set_deadzone(float deadzone);
pmmccorkell 0:37123f30e8b2 31 float process(float setpoint, float measured);
pmmccorkell 0:37123f30e8b2 32 float process(float error);
pmmccorkell 0:37123f30e8b2 33 void get_gain_values(PID_GAINS_TypeDef *gains);
pmmccorkell 0:37123f30e8b2 34
pmmccorkell 0:37123f30e8b2 35 protected:
pmmccorkell 0:37123f30e8b2 36 float _Kp;
pmmccorkell 0:37123f30e8b2 37 float _Ki;
pmmccorkell 0:37123f30e8b2 38 float _Kd;
pmmccorkell 0:37123f30e8b2 39 float _floor;
pmmccorkell 0:37123f30e8b2 40 float _deadzone;
pmmccorkell 4:e89234ca9d4e 41 float _dt;
pmmccorkell 0:37123f30e8b2 42 float _error_previous;
pmmccorkell 0:37123f30e8b2 43 float _integral;
pmmccorkell 0:37123f30e8b2 44
pmmccorkell 0:37123f30e8b2 45 //private:
pmmccorkell 0:37123f30e8b2 46
pmmccorkell 0:37123f30e8b2 47 };
pmmccorkell 0:37123f30e8b2 48
pmmccorkell 0:37123f30e8b2 49