sentry_chassis_hzz/modules/motor/HT04.h

104 lines
2.4 KiB
C
Raw Normal View History

2022-10-20 17:13:02 +08:00
#ifndef HT04_H
#define HT04_H
2022-12-12 22:29:51 +08:00
#include <stdint.h>
2022-10-20 17:13:02 +08:00
#include "bsp_can.h"
2022-10-20 21:14:17 +08:00
#include "controller.h"
#include "motor_def.h"
2022-10-20 17:13:02 +08:00
#define HT_MOTOR_CNT 4
#define CURRENT_SMOOTH_COEF 0.9f
#define SPEED_SMOOTH_COEF 0.85f
2022-10-20 17:13:02 +08:00
#define P_MIN -95.5f // Radians
2022-10-20 17:13:02 +08:00
#define P_MAX 95.5f
#define V_MIN -45.0f // Rad/s
2022-10-20 17:13:02 +08:00
#define V_MAX 45.0f
#define T_MIN -18.0f // N·m
2022-10-20 17:13:02 +08:00
#define T_MAX 18.0f
typedef struct // HT04
{ // 角度为多圈角度,范围是-95.5~95.5,单位为rad
float last_angle;
float total_angle;
float speed_aps;
float real_current;
} HTMotor_Measure_t;
/* HT电机类型定义*/
typedef struct
{
HTMotor_Measure_t motor_measure;
Motor_Control_Setting_s motor_settings;
PIDInstance current_PID;
PIDInstance speed_PID;
PIDInstance angle_PID;
float *other_angle_feedback_ptr;
float *other_speed_feedback_ptr;
float *speed_feedforward_ptr;
float *current_feedforward_ptr;
float pid_ref;
2022-10-20 21:14:17 +08:00
Motor_Working_Type_e stop_flag; // 启停标志
CANInstance *motor_can_instace;
} HTMotorInstance;
2022-10-20 17:13:02 +08:00
/* HT电机模式,初始化时自动进入CMD_MOTOR_MODE*/
2022-10-20 17:13:02 +08:00
typedef enum
{
CMD_MOTOR_MODE = 0xfc, // 使能,会响应指令
CMD_RESET_MODE = 0xfd, // 停止
CMD_ZERO_POSITION = 0xfe // 将当前的位置设置为编码器零位
} HTMotor_Mode_t;
/**
* @brief
*
* @param config
* @return HTMotorInstance*
*/
HTMotorInstance *HTMotorInit(Motor_Init_Config_s *config);
/**
* @brief
*
* @param motor
* @param current
*/
void HTMotorSetRef(HTMotorInstance *motor, float ref);
/**
* @brief HT电机发送控制指令
*
*/
void HTMotorControl();
2022-10-20 17:13:02 +08:00
/**
* @brief ,HTMotorSetRef设定的值
*
* @param motor
*/
void HTMotorStop(HTMotorInstance *motor);
2022-10-20 17:13:02 +08:00
/**
* @brief
*
* @param motor
*/
void HTMotorEnable(HTMotorInstance *motor);
2022-10-20 17:13:02 +08:00
/**
* @brief
* @attention ,,360°!
* ,,360°!
* ,,360°!
* ,,360°!
*
* @param motor
*/
void HTMotorCalibEncoder(HTMotorInstance *motor);
2022-10-20 17:13:02 +08:00
#endif // !HT04_H#define HT04_H