gimbal/User/component/Sliding.h
2025-12-08 20:32:09 +08:00

103 lines
2.0 KiB
C
Raw 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.

/*
滑膜相关命令
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <string.h>
#include "component/user_math.h"
/* USER INCLUDE BEGIN */
/* USER INCLUDE END */
/* 趋近率选择(滑模面求导) */
typedef enum {
EXPONENT,
POWER,
TFSMC,
VELSMC,
EISMC
} Smc_mode;
typedef struct {
float tar_now;//当前目标值
float tar_last;//上一次目标值
float tar_differential;//目标值一阶导
float tar_differential_last;//上一次目标值一阶导
float tar_differential_second;//目标值二阶导
float now_get;//当前
// float p_error;//位置误差
float error;//速度误差(位置误差一阶导)
float error_integral;//误差积分
// float v_error_integral;//速度误差积分
float error_integral_max; //积分限幅
float error_eps; //误差精度
// float vol_error_eps; //误差精度
float error_last;
}Error;
typedef struct {
/* 输出限幅 */
float u_max;
float J;
float limit; //饱和函数上下限
/* 控制器的增益K */
float K;
/* 趋于o的速度 */
float c;
float c1; //EIsmc参数
float c2; //EIsmc参数
float p; //tfsmc参数正奇数 p>q
float q; //tfsmc参数正奇数
float beta; //tfsmc参数正数
float epsilon; //ε噪声上限
}SlidingParam;
typedef struct {
float fun; //控制器输出
float u; //控制器输出
float s; //滑模面计算储存
float J;
SlidingParam *param;
SlidingParam *param_last;
Smc_mode mode;
Error position;
Error velocity;
float s1,s2,s3,s4;
}Sliding;
void SMC_Reset(Sliding *s);
void SMC_Init(Sliding *s,Smc_mode mode,SlidingParam *param);
void SMC_PErrorUpdate(Sliding *s,float target, float pos_now, float vol_now,float target_freq);
void SMC_VErrorUpdate(Sliding *s,float target,float vol_now,float target_freq);
float Smc_Calc(Sliding *s);
/* USER DEFINE BEGIN */
/* USER DEFINE END */
#ifdef __cplusplus
}
#endif