go/User/device/djiMotor.h
2025-03-03 19:41:03 +08:00

115 lines
2.9 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.

#ifndef DJI_MOTOR_H
#define DJI_MOTOR_H
#ifdef __cplusplus
extern "C"{
#endif
#define FREERTOS_DJI 1
#include "struct_typedef.h"
#include "can.h"
#include "odrive_can.h"
typedef enum{
GM6020 = 0,
M3508 = 1,
M2006 = 2
}motor_type_e;
//rm motor data
typedef struct
{
uint16_t ecd;//编码器返回值0-8192
int16_t speed_rpm;//速度
int16_t given_current;//电流
uint16_t temperate;//温度
int16_t last_ecd;//上次的编码器角度
int16_t round_cnt;//转子圈数(ecd round)
int32_t total_angle;//输出轴角度
uint16_t offset_ecd;//开始的ecd值
uint32_t msg_cnt;//初始化开始ecd值用的
int16_t real_round;//输出轴圈数
int16_t real_angle;//输出轴单圈角度
motor_type_e type;//电机类型详见motor_type_e
} motor_measure_t;
typedef struct
{
uint16_t ecd;
int16_t speed_rpm;
int16_t given_current;
uint8_t temperate;
int16_t last_ecd;
} odrive_measure_t;
//motor calc ecd to angle
#define MOTOR_ECD_TO_ANGLE_3508 (360.0 / 8191.0 / (3591.0/187.0))
#define MOTOR_ECD_TO_ANGLE_6020 (360.0 / 8191.0 )
#define MOTOR_ECD_TO_ANGLE_2006 (360.0 / 8191.0 / 36)
#if FREERTOS_DJI == 1
/**
* @brief 大疆电机初始化
* @param none
* @retval none
*/
void djiInit(void);
/**
* @brief 等待新数据
*/
uint32_t waitNewDji(void);
#endif
/**
* @brief 发送电机控制电流(0x205,0x206,0x207,0x208)
* @param[in] motor1: (0x205) 电机控制电流
* @param[in] motor2: (0x206) 电机控制电流
* @param[in] motor3: (0x207) 电机控制电流
* @param[in] motor4: (0x208) 电机控制电流
* @retval none
*/
extern void CAN_cmd_1FF(int16_t motor1, int16_t motor2, int16_t motor3, int16_t motor4,CAN_HandleTypeDef*hcan);
/**
* @brief 发送电机控制电流(0x201,0x202,0x203,0x204)
* @param[in] motor1: (0x201) 电机控制电流
* @param[in] motor2: (0x202) 电机控制电流
* @param[in] motor3: (0x203) 电机控制电流
* @param[in] motor4: (0x204) 电机控制电流
* @retval none
*/
extern void CAN_cmd_200(int16_t motor1, int16_t motor2, int16_t motor3, int16_t motor4,CAN_HandleTypeDef*hcan);
/**
* @brief 发送电机控制电流(0x205,0x206,0x207,0x208)
* @param[in] motor1: (0x209) 电机控制电流
* @param[in] motor2: (0x20A) 电机控制电流
* @param[in] motor3: (0x20B) 电机控制电流
* @retval none
*/
extern void CAN_cmd_2FF(int16_t motor1, int16_t motor2, int16_t motor3, CAN_HandleTypeDef*hcan);
/**
* @brief 返回电机数据指针
* @param[in] i: 电机编号
* @retval 电机数据指针
*/
extern motor_measure_t *get_motor_point(uint8_t i);
/**
* @brief 数据处理函数
* @param[in] none
* @retval none
*/
void djiMotorEncode(void);
#ifdef __cplusplus
}
#endif
#endif