go/User/device/djiMotor.h

115 lines
2.9 KiB
C
Raw Normal View History

2025-03-03 19:41:03 +08:00
#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