You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
183 lines
4.6 KiB
183 lines
4.6 KiB
/******************************************************************************
|
|
|
|
版权所有 (C), 2018-2099, Radkil
|
|
|
|
******************************************************************************
|
|
文 件 名 : motor_manager.h
|
|
版 本 号 : 初稿
|
|
作 者 : radkil
|
|
生成日期 : 2026年7月13日
|
|
最近修改 :
|
|
功能描述 : 电机管理模块(多实例管理,协议无关)
|
|
|
|
修改历史 :
|
|
1.日 期 : 2026年7月13日
|
|
作 者 : radkil
|
|
修改内容 : 创建文件
|
|
|
|
******************************************************************************/
|
|
|
|
#ifndef __MOTOR_MANAGER_H__
|
|
#define __MOTOR_MANAGER_H__
|
|
|
|
#ifdef __cplusplus
|
|
#if __cplusplus
|
|
extern "C"{
|
|
#endif
|
|
#endif /* __cplusplus */
|
|
|
|
/*==============================================*
|
|
* include header files *
|
|
*----------------------------------------------*/
|
|
#include "motor_protocol.h"
|
|
|
|
/*==============================================*
|
|
* constants or macros define *
|
|
*----------------------------------------------*/
|
|
|
|
/*==============================================*
|
|
* data structures *
|
|
*----------------------------------------------*/
|
|
|
|
/*==============================================*
|
|
* project-wide global variables *
|
|
*----------------------------------------------*/
|
|
|
|
/*==============================================*
|
|
* routines' or functions' implementations *
|
|
*----------------------------------------------*/
|
|
|
|
/**
|
|
* @brief 初始化电机管理模块
|
|
*/
|
|
void MotorMgr_Init(void);
|
|
|
|
/**
|
|
* @brief 创建电机实例
|
|
* @param pstConfig 电机配置
|
|
* @param ptCAN 绑定的CAN控制器
|
|
* @param pstProtocol 协议操作函数表
|
|
* @param pstPrivData 协议私有数据(可为NULL)
|
|
* @return 电机实例指针,失败返回NULL
|
|
*/
|
|
Motor_Instance_t* MotorMgr_Create(const Motor_Config_t *pstConfig,
|
|
TComCtrl *ptCAN,
|
|
const Motor_Protocol_t *pstProtocol,
|
|
void *pstPrivData);
|
|
|
|
/**
|
|
* @brief 销毁电机实例
|
|
* @param pstMotor 电机实例
|
|
* @return 0成功,非0失败
|
|
*/
|
|
int MotorMgr_Destroy(Motor_Instance_t *pstMotor);
|
|
|
|
/**
|
|
* @brief 通过名称查找电机实例
|
|
* @param pszName 实例名称
|
|
* @return 电机实例指针,未找到返回NULL
|
|
*/
|
|
Motor_Instance_t* MotorMgr_FindByName(const char *pszName);
|
|
|
|
/**
|
|
* @brief 通过ID查找电机实例
|
|
* @param ucMotorID 电机节点ID
|
|
* @return 电机实例指针,未找到返回NULL
|
|
*/
|
|
Motor_Instance_t* MotorMgr_FindByID(uint8_t ucMotorID);
|
|
|
|
/**
|
|
* @brief 复位所有节点
|
|
*/
|
|
int MotorMgr_ResetAll(Motor_Instance_t *pstMotor);
|
|
|
|
/**
|
|
* @brief 激活所有节点
|
|
*/
|
|
int MotorMgr_ActivateAll(Motor_Instance_t *pstMotor);
|
|
|
|
/**
|
|
* @brief 设置当前位置为零点
|
|
*/
|
|
int MotorMgr_SetHome(Motor_Instance_t *pstMotor);
|
|
|
|
/**
|
|
* @brief 设置看门狗时间
|
|
*/
|
|
int MotorMgr_SetWatchdog(Motor_Instance_t *pstMotor, uint32_t uiTimeMs);
|
|
|
|
/**
|
|
* @brief 读取电机位置
|
|
*/
|
|
int MotorMgr_RequestPosition(Motor_Instance_t *pstMotor);
|
|
|
|
/**
|
|
* @brief 读取电机速度
|
|
*/
|
|
int MotorMgr_RequestVelocity(Motor_Instance_t *pstMotor);
|
|
|
|
/**
|
|
* @brief 读取电机电流/转矩
|
|
*/
|
|
int MotorMgr_RequestTorque(Motor_Instance_t *pstMotor);
|
|
|
|
/**
|
|
* @brief 读取故障码
|
|
*/
|
|
int MotorMgr_RequestFault(Motor_Instance_t *pstMotor);
|
|
|
|
/**
|
|
* @brief 速度模式初始化
|
|
*/
|
|
int MotorMgr_SpeedModeInit(Motor_Instance_t *pstMotor);
|
|
|
|
/**
|
|
* @brief 设置目标速度
|
|
*/
|
|
int MotorMgr_SetTargetSpeed(Motor_Instance_t *pstMotor, int32_t iTargetSpeed);
|
|
|
|
/**
|
|
* @brief 位置模式初始化
|
|
*/
|
|
int MotorMgr_PositionModeInit(Motor_Instance_t *pstMotor, int32_t iAccel, int32_t iDecel, int32_t iTargetSpeed);
|
|
|
|
/**
|
|
* @brief 设置目标位置(相对运动)
|
|
*/
|
|
int MotorMgr_SetTargetPosition(Motor_Instance_t *pstMotor, int32_t iTargetPos);
|
|
|
|
/**
|
|
* @brief 设置数字输出
|
|
*/
|
|
int MotorMgr_SetDO(Motor_Instance_t *pstMotor, uint8_t ucDoIndex, uint8_t ucState);
|
|
|
|
/**
|
|
* @brief 解析CAN响应数据(遍历所有电机实例尝试解析)
|
|
* @param ucMotorID 电机节点ID
|
|
* @param pucData 数据指针
|
|
* @param uiLen 数据长度
|
|
*/
|
|
void MotorMgr_ParseResponse(uint8_t ucMotorID, const uint8_t *pucData, uint32_t uiLen);
|
|
|
|
/**
|
|
* @brief 速度单位转换
|
|
*/
|
|
int32_t MotorMgr_SpeedConvert(Motor_Instance_t *pstMotor, int32_t iSpeedUserUnit);
|
|
|
|
/**
|
|
* @brief 获取电机数据
|
|
*/
|
|
const Motor_Data_t* MotorMgr_GetData(Motor_Instance_t *pstMotor);
|
|
|
|
/**
|
|
* @brief 获取电机状态
|
|
*/
|
|
Motor_State_e MotorMgr_GetState(Motor_Instance_t *pstMotor);
|
|
|
|
#ifdef __cplusplus
|
|
#if __cplusplus
|
|
}
|
|
#endif
|
|
#endif /* __cplusplus */
|
|
|
|
#endif /* __MOTOR_MANAGER_H__ */
|
|
|