25_R1_chassis/User/Algorithm/pid.h
2025-05-25 20:10:14 +08:00

96 lines
2.4 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
****************************(C) COPYRIGHT 2016 DJI****************************
* @file pid.c/h
* @brief pidʵ<64>ֺ<EFBFBD><D6BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>PID<49><44><EFBFBD><EFBFBD><E3BAAF><EFBFBD><EFBFBD>
* @note
* @history
* Version Date Author Modification
* V1.0.0 Dec-26-2018 RM 1. <20><><EFBFBD>
*
@verbatim
==============================================================================
==============================================================================
@endverbatim
****************************(C) COPYRIGHT 2016 DJI****************************
*/
#ifndef PID_H
#define PID_H
#include "struct_typedef.h"
enum PID_MODE
{
PID_POSITION = 0,
PID_DELTA
};
/* PID<49><44><EFBFBD><EFBFBD> */
typedef struct {
float p;
float i;
float d;
float i_limit;
float out_limit;
float d_cutoff_freq;
float f;// 前馈增益系数
} pid_param_t;
typedef struct
{
uint8_t mode;
const pid_param_t *param;
fp32 set;
fp32 fdb;
fp32 out;
fp32 Pout;
fp32 Iout;
fp32 Dout;
fp32 Dbuf[3];
fp32 error[3];
fp32 Fout;
} pid_type_def;
/**
* @brief pid struct data init
* @param[out] pid: PID<49><EFBFBD><E1B9B9><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
* @param[in] mode: PID_POSITION:<3A><>ͨPID
* PID_DELTA: <20><><EFBFBD>PID
* @param[in] PID: 0: kp, 1: ki, 2:kd 3: i_limit 4: out_limit 5: d_cutoff_freq
* @retval none
*/
extern int8_t PID_init(pid_type_def *pid, uint8_t mode, const pid_param_t *param);
/**
* @brief pid calculate
* @param[out] pid: PID struct data point
* @param[in] ref: feedback data
* @param[in] set: set point
* @retval pid out
*/
/**
* @brief pid<69><64><EFBFBD><EFBFBD>
* @param[out] pid: PID<49><EFBFBD><E1B9B9><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
* @param[in] ref: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param[in] set: <20>趨ֵ
* @retval pid<69><64><EFBFBD>
*/
extern fp32 PID_calc(pid_type_def *pid, fp32 ref, fp32 set);
extern fp32 PID_feedforward(pid_type_def *pid, fp32 ref, fp32 set);
/**
* @brief pid out clear
* @param[out] pid: PID struct data point
* @retval none
*/
/**
* @brief pid <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param[out] pid: PID<49><EFBFBD><E1B9B9><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
* @retval none
*/
extern void PID_clear(pid_type_def *pid);
#endif