PID_Gen.h 2.2 KB
/*
 * @Date: 2023-12-01 17:08:18
 * @LastEditTime: 2024-01-25 18:14:28
 * @FilePath: \Motor_Board_231121mkdir\Hardware\new_pid.h
 * @Description:
 */
#ifndef __NEW_PID_H_
#define __NEW_PID_H_

// #include "stm32f4xx_hal.h"
#include "tva.h"
#include "OBS_PID.h"

typedef struct
{
    /*比例项*/
    float KP_a;
    float KP_b;
    float KP_c; // 取值范围kp_c=[0,1]

    /*积分项*/
    float KI_a;
    float KI_c; // 取值范围kI_c=[0,1]

    /*积分项增益系数*/
    float KI_e; // 取值范围ke_0=[0.1,0.5]
    float KI_0;
    float KI_1;

    /*微分项*/
    float KD_a; /*a要大于b*/
    float KD_b;
    float KD_c; // 取值范围kI_c=[0,1]
} varPID;

typedef struct
{
    float kp, ki, kd; // PID arg P I D
    // Speed / Slope
    float IerrV; // The Speed of IerrV : control the pile speed of Ierr
    // Limit
    float outputLimit; // Outpur Limit
    // float intS;        // Integral Saturation Value( as same as the intErr , the Ierr Limit but depend on the flow process )
    float intDetach; // Integral Separation Value
    float intLimit;  // Integral Limit
    // Not Recommend to use
    float deadzone; // the err where the PID return 0 ( better to don't use it )

    float output_ramp;
    varPID varPID;
}
GenPID_CONFIG; 

typedef struct
{
    //Runtime vaule
    float pi,pout;
    float sv, cv, pv; // Set Vaule(Target) , Previous Value ,  Current Vaule
                      //  float err, Ierr, perr; // Error(sv-cv) , Cumulative Error( Ierr += err ) , Previous Vaule

    float Ierr, perr ,perrLP; // Cumulative Error( Ierr += err ) , Previous Vaule

    // Time Recorder !
    TimeRec_s time;

    GenPID_CONFIG config;
} GenPID_s;

void GenPID_Init(GenPID_s *pid);
int GenPID_Set(GenPID_s *pid,GenPID_CONFIG config);
int GenPID_Set_Needle(GenPID_s *pid,GenPID_CONFIG *config);
float GenPID_Process(GenPID_s *pid, float sv, float cv,OBS_GenPID *obs);
float GenPID_ProcessSTD(GenPID_s *pid, float sv, float cv,OBS_GenPID *obs);
float GenPID_ProcessSTD_ErrIN(GenPID_s *pid, float err,OBS_GenPID *obs);
float GenPID_ProcessSTD_LPIn(GenPID_s *pid, float sv, float cv,float cv_LP,OBS_GenPID *obs);

//-----------------------PID DEBUG SW---------------------------
#define PID_DEBUG_SW 1

#endif