motor.h
4.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#ifndef __MOTOR_H
#define __MOTOR_H
// #include "PID.h"
#include "PID_Gen.h"
#include "math_utils.h"
#include "OBS_MOT.h"
#include "MOT_Dev_Config.h"
#include "ParaMge_Common.h"
#if MOT_DEV_TARGET == STM32_TARGET_A12_F4
#include "IMU_Pubilc.h"
#endif
//用于暂存校准后的数据
extern float offset_Temp;
extern float mge_direction_Temp;
extern float zeroElectricAngleOffset_Temp;
extern KFP kfp_ang;
//Motor Pre Setting
#define MOTOR_PP 7
//==OLD Part
extern LowPassFSTD_s velLP_Config;
//==Current Part
// extern int8_t motor_PP ; // 极对数
extern float Set_Velocity; // 目标转速
// extern LowPassFSTD_s velLP_Config;
extern float Target_Angle;
extern float angleIMU_traget;
typedef enum
{
MOTOR_IMU_DIRECTION_CW = 1,
MOTOR_IMU_DIRECTION_CCW = -1,
MOTOR_IMU_DIRECTION_UNKNOWN = 0
} MOTOR_IMU_DIRECTION;
typedef enum
{
CALIBRATION_FAILED = 0,
CALIBRATION_PROCESSING ,
CALIBRATION_CMPLETE ,
} CALIBRATION_STATE;
// CUT## 索引枚举
typedef enum{
__MOTOR_GENPID_INDEX_VEL = 1,
__MOTOR_GENPID_INDEX_ANG = 2,
}__MOTOR_GENPID_INDEX;
extern MOTOR_IMU_DIRECTION mot_Imu_dir;
extern CALIBRATION_STATE calibration_State; //校准状态
// CUT## 电机参数设置
/// @brief 电机的PP值,须>0,否则设置不会被应用
/// @param PP 整数,(>0)
/// @return 返回操作结果 , 0 - 成功 , -1 - 失败(输入非法)
int8_t motor_SetPP(uint8_t PP);
int8_t motor_GetPP();
int8_t motor_SetUpLimit(float AngLimit);
float motor_GetUpLimit();
int8_t motor_SetDownLimit(float AngLimit);
float motor_GetDownLimit();
// /// @brief 返回当前角度PID的设置,以结构体的形式
// /// @return 返回角度PID的GenPID_CONFIG结构体
// GenPID_CONFIG motor_angGenPID_Get();
// int motor_angGenPID_Get_Needle(GenPID_CONFIG *config);
// /// @brief 设置角度PID,以结构体的形式传入,传入结构体会赋值到最终结构体中(即需要在外部构建该结构体)
// /// @param config 角度PID设置,GenPID_CONFIG结构体
// /// @return 当前API,总是返回0
// int motor_angGenPID_Set(GenPID_CONFIG config);
// int motor_angGenPID_Set_Needle(GenPID_CONFIG *config);
// //NOTE: 速度PID设置和获取和角度PID相同
// GenPID_CONFIG motor_velGenPID_Get();
// int motor_velGenPID_Get_Needle(GenPID_CONFIG *config);
// int motor_velGenPID_Set(GenPID_CONFIG config);
// int motor_velGenPID_Set_Needle(GenPID_CONFIG *config);
//NOTE: 速度PID设置和获取和角度PID相同
// GenPID_CONFIG motor_GenPID_Get(__MOTOR_GENPID_INDEX index);
int motor_GenPID_Get_Needle(__MOTOR_GENPID_INDEX index,GenPID_CONFIG *config);
// int motor_GenPID_Set(__MOTOR_GENPID_INDEX index,GenPID_CONFIG config);
int motor_GenPID_Set_Needle(__MOTOR_GENPID_INDEX index,GenPID_CONFIG *config);
/// @brief 返回当前速度KFP滤波器的设置,以结构体的形式
/// @return 返回速度KFP滤波器的KFP_CONFIG结构体
KFP_CONFIG motor_velKFP_Get(void);
KFP_CONFIG motor_angKFP_Get(void);
/// @brief 设置速度KFP滤波器,以结构体的形式传入,传入结构体会赋值到最终结构体中(即需要在外部构建该结构体)
/// @param config KFP滤波器设置,KFP_CONFIG结构体
/// @return 当前API,总是返回0
int motor_velKFP_Set(KFP_CONFIG config);
int motor_angKFP_Set(KFP_CONFIG config);
// 电机电角度零位设置
float motor_Get_ZeroEAngleOffset();
void motor_Set_ZeroEAngleOffset(float offset);
float motor_Get_ZeroEAngleLoopOffset();
void motor_Set_ZeroEAngleLoopOffset(float offset);
// CUT## 电机功能函数
// 函数声明
__PARAMGE_DEF_MOT_CALI_STA motor_Align_Sensor(void);
uint8_t motor_start_SelfTest(void);
void motor_AutoCalibration();
void gimbal_Horizontalalign(void);
void gimbal_Axisalign(void);
void motor_InitALL(void);
#if MOT_DEV_TARGET == STM32_TARGET_A2_F1
void MOT_YandR_VelControl_Direct_GenPID_ErrIn(float err);
#endif
#if MOT_DEV_TARGET == STM32_TARGET_A12_F4
void MOT_Pitch_AngleControl_WithTCurve_GenPID(state_t *imu_AHRS_result);
#endif
void close_Angle_Control_GenPID(float Target_Angle);//目标角度闭环控制
#endif