更新dmmotor驱动文件
This commit is contained in:
parent
b476bd0aa6
commit
89edcd9e90
|
@ -212,7 +212,20 @@ void MatInit(mat *m, uint8_t row, uint8_t col)
|
|||
m->numRows = row;
|
||||
m->pData = (float *)zmalloc(row * col * sizeof(float));
|
||||
}
|
||||
/* 两个用于将uint值和float值进行映射的函数,在设定发送值和解析反馈值时使用 */
|
||||
uint16_t float_to_uint(float x, float x_min, float x_max, uint8_t bits)
|
||||
{
|
||||
float span = x_max - x_min;
|
||||
float offset = x_min;
|
||||
return (uint16_t)((x - offset) * ((float)((1 << bits) - 1)) / span);
|
||||
}
|
||||
|
||||
float uint_to_float(int x_int, float x_min, float x_max, int bits)
|
||||
{
|
||||
float span = x_max - x_min;
|
||||
float offset = x_min;
|
||||
return ((float)x_int) * span / ((float)((1 << bits) - 1)) + offset;
|
||||
}
|
||||
/**
|
||||
* @brief 一阶低通滤波初始化
|
||||
* @author RM
|
||||
|
|
|
@ -61,6 +61,15 @@ typedef struct
|
|||
float frame_period; //滤波的时间间隔 单位 s
|
||||
} first_order_filter_type_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float input; //输入数据
|
||||
float out; //输出数据
|
||||
float min_value; //限幅最小值
|
||||
float max_value; //限幅最大值
|
||||
float frame_period; //时间间隔
|
||||
} ramp_function_source_t;
|
||||
|
||||
#define VAL_LIMIT(val, min, max) \
|
||||
do \
|
||||
{ \
|
||||
|
@ -127,6 +136,8 @@ void Cross3d(float *v1, float *v2, float *res);
|
|||
float Dot3d(float *v1, float *v2);
|
||||
|
||||
float AverageFilter(float new_data, float *buf, uint8_t len);
|
||||
float uint_to_float(int x_int, float x_min, float x_max, int bits);
|
||||
uint16_t float_to_uint(float x, float x_min, float x_max, uint8_t bits);
|
||||
//一阶低通滤波初始化
|
||||
void first_order_filter_init(first_order_filter_type_t *first_order_filter_type, float frame_period, const float num[1]);
|
||||
//一阶低通滤波计算
|
||||
|
|
|
@ -12,18 +12,7 @@ static uint8_t idx;
|
|||
static DMMotorInstance *dm_motor_instance[DM_MOTOR_CNT];
|
||||
static osThreadId dm_task_handle[DM_MOTOR_CNT];
|
||||
/* 两个用于将uint值和float值进行映射的函数,在设定发送值和解析反馈值时使用 */
|
||||
static uint16_t float_to_uint(float x, float x_min, float x_max, uint8_t bits)
|
||||
{
|
||||
float span = x_max - x_min;
|
||||
float offset = x_min;
|
||||
return (uint16_t)((x - offset) * ((float)((1 << bits) - 1)) / span);
|
||||
}
|
||||
static float uint_to_float(int x_int, float x_min, float x_max, int bits)
|
||||
{
|
||||
float span = x_max - x_min;
|
||||
float offset = x_min;
|
||||
return ((float)x_int) * span / ((float)((1 << bits) - 1)) + offset;
|
||||
}
|
||||
|
||||
|
||||
void DMMotorSetMode(DMMotor_Mode_e cmd, DMMotorInstance *motor)
|
||||
{
|
||||
|
|
|
@ -26,19 +26,8 @@ static void HTMotorSetMode(HTMotor_Mode_t cmd, HTMotorInstance *motor)
|
|||
CANTransmit(motor->motor_can_instace, 1);
|
||||
memcpy(motor->motor_can_instace->tx_buff, zero_buff, 6);
|
||||
}
|
||||
/* 两个用于将uint值和float值进行映射的函数,在设定发送值和解析反馈值时使用 */
|
||||
static uint16_t float_to_uint(float x, float x_min, float x_max, uint8_t bits)
|
||||
{
|
||||
float span = x_max - x_min;
|
||||
float offset = x_min;
|
||||
return (uint16_t)((x - offset) * ((float)((1 << bits) - 1)) / span);
|
||||
}
|
||||
static float uint_to_float(int x_int, float x_min, float x_max, int bits)
|
||||
{
|
||||
float span = x_max - x_min;
|
||||
float offset = x_min;
|
||||
return ((float)x_int) * span / ((float)((1 << bits) - 1)) + offset;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief 解析电机反馈值
|
||||
|
|
|
@ -73,6 +73,7 @@ typedef enum
|
|||
NO_POWER_LIMIT = 0,
|
||||
POWER_LIMIT_ON = 1,
|
||||
} Power_Limit_Type_e;
|
||||
|
||||
/* 电机控制设置,包括闭环类型,反转标志和反馈来源 */
|
||||
typedef struct
|
||||
{
|
||||
|
@ -83,11 +84,19 @@ typedef struct
|
|||
Feedback_Source_e angle_feedback_source; // 角度反馈类型
|
||||
Feedback_Source_e speed_feedback_source; // 速度反馈类型
|
||||
Feedfoward_Type_e feedforward_flag; // 前馈标志
|
||||
|
||||
Power_Limit_Type_e power_limit_flag; //功率限制标志
|
||||
|
||||
} Motor_Control_Setting_s;
|
||||
|
||||
/* 电机控制方式枚举 */
|
||||
typedef enum
|
||||
{
|
||||
CONTROL_TYPE_NONE = 0,
|
||||
CURRENT_CONTROL,
|
||||
VOLTAGE_CONTROL,
|
||||
} Motor_Control_Type_e;
|
||||
|
||||
|
||||
/* 电机控制器,包括其他来源的反馈数据指针,3环控制器和电机的参考输入*/
|
||||
// 后续增加前馈数据指针
|
||||
typedef struct
|
||||
|
@ -117,17 +126,10 @@ typedef enum
|
|||
M2006,
|
||||
LK9025,
|
||||
HT04,
|
||||
ECA8210,
|
||||
DM4310,
|
||||
DM6006,
|
||||
} Motor_Type_e;
|
||||
|
||||
/* 电机控制方式枚举 */
|
||||
typedef enum
|
||||
{
|
||||
CONTROL_TYPE_NONE = 0,
|
||||
CURRENT_CONTROL,
|
||||
VOLTAGE_CONTROL,
|
||||
} Motor_Control_Type_e;
|
||||
|
||||
/**
|
||||
* @brief 电机控制器初始化结构体,包括三环PID的配置以及两个反馈数据来源指针
|
||||
* 如果不需要某个控制环,可以不设置对应的pid config
|
||||
|
@ -154,7 +156,6 @@ typedef struct
|
|||
Motor_Type_e motor_type;
|
||||
CAN_Init_Config_s can_init_config;
|
||||
Motor_Control_Type_e motor_control_type;
|
||||
|
||||
} Motor_Init_Config_s;
|
||||
|
||||
#endif // !MOTOR_DEF_H
|
||||
|
|
Loading…
Reference in New Issue