This commit is contained in:
ZHAISHUI04 2025-03-13 19:07:44 +08:00
parent 4fb995a11b
commit adbf87522c
8 changed files with 31 additions and 16 deletions

View File

@ -103,7 +103,7 @@ void MX_USART6_UART_Init(void)
/* USER CODE END USART6_Init 1 */ /* USER CODE END USART6_Init 1 */
huart6.Instance = USART6; huart6.Instance = USART6;
huart6.Init.BaudRate = 115200; huart6.Init.BaudRate = 4000000;
huart6.Init.WordLength = UART_WORDLENGTH_8B; huart6.Init.WordLength = UART_WORDLENGTH_8B;
huart6.Init.StopBits = UART_STOPBITS_1; huart6.Init.StopBits = UART_STOPBITS_1;
huart6.Init.Parity = UART_PARITY_NONE; huart6.Init.Parity = UART_PARITY_NONE;

View File

@ -12,7 +12,8 @@
int8_t up_init(UP_t *u,const UP_Param_t *param,float target_freq) int8_t up_init(UP_t *u,const UP_Param_t *param,float target_freq)
{ {
u->param = param; /*初始化参数 */ u->param = param; /*初始化参数 */
GO_M8010_init();
PID_init (&u->pid.VESC_5065_M1 ,PID_POSITION ,&(u->param ->VESC_5065_M1_param )); PID_init (&u->pid.VESC_5065_M1 ,PID_POSITION ,&(u->param ->VESC_5065_M1_param ));
PID_init (&u->pid.VESC_5065_M2 ,PID_POSITION ,&(u->param ->VESC_5065_M2_param )); PID_init (&u->pid.VESC_5065_M2 ,PID_POSITION ,&(u->param ->VESC_5065_M2_param ));

View File

@ -48,3 +48,15 @@ bool CRC16_Verify(const uint8_t *buf, size_t len) {
((const uint16_t *)((const uint8_t *)buf + ((const uint16_t *)((const uint8_t *)buf +
(len % 2)))[len / sizeof(uint16_t) - 1]; (len % 2)))[len / sizeof(uint16_t) - 1];
} }
uint16_t do_crc_table(uint8_t *ptr, int len)
{
uint16_t crc = 0x0000;
while(len--)
{
crc = (crc >> 8) ^ crc16_tab[(crc ^ *ptr++) & 0xff];
}
return crc;
}

View File

@ -12,6 +12,7 @@ extern "C" {
uint16_t CRC16_Calc(const uint8_t *buf, size_t len, uint16_t crc); uint16_t CRC16_Calc(const uint8_t *buf, size_t len, uint16_t crc);
bool CRC16_Verify(const uint8_t *buf, size_t len); bool CRC16_Verify(const uint8_t *buf, size_t len);
uint16_t do_crc_table(uint8_t *ptr, int len);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -7,7 +7,7 @@
#include <cmsis_os2.h> #include <cmsis_os2.h>
GO_Motorfield GO_motor_info[GO_NUM];//存放电机数据 GO_Motorfield GO_motor_info[GO_NUM];//存放电机数据
const float gravit_const =9.81;//计算前馈力矩有关 static const float gravit_const =9.81;//计算前馈力矩有关
//数据处理函数 //数据处理函数
static void GO_M8010_recv_data(uint8_t* Temp_buffer); static void GO_M8010_recv_data(uint8_t* Temp_buffer);
@ -38,7 +38,7 @@ void GO_M8010_init (){
//暂存接收数据 //暂存接收数据
static uint8_t Temp_buffer[16]; uint8_t Temp_buffer[16];
void USART6_RxCompleteCallback(void ) void USART6_RxCompleteCallback(void )
{ {
@ -79,12 +79,12 @@ void uartTxCB(UART_HandleTypeDef *huart)
*@input[in] K_W kp *@input[in] K_W kp
*@note t = T + - *K_P + - *K_W *@note t = T + - *K_P + - *K_W
*/ */
GO_Motorfield* motor;
void GO_M8010_send_data(UART_HandleTypeDef *huart, int id,int rev,float T,float Pos, void GO_M8010_send_data(UART_HandleTypeDef *huart, int id,int rev,float T,float Pos,
float W,float K_P,float K_W) float W,float K_P,float K_W)
{ {
// a pointer to target motor // a pointer to target motor
GO_Motorfield* motor;
motor = GO_motor_info+id; motor = GO_motor_info+id;
//这个rev是干啥的 //这个rev是干啥的
@ -130,7 +130,7 @@ void GO_M8010_send_data(UART_HandleTypeDef *huart, int id,int rev,float T,float
// interrupt buffer sending // interrupt buffer sending
HAL_UART_Transmit_IT(huart,motor->buffer,sizeof(motor->buffer)); HAL_UART_Transmit_IT(huart,motor->buffer,sizeof(motor->buffer));
osDelay(100); osDelay(1000);
HAL_UART_Receive_DMA(huart, Temp_buffer, 16);//有无都可以 HAL_UART_Receive_DMA(huart, Temp_buffer, 16);//有无都可以

View File

@ -35,23 +35,22 @@ typedef struct
uint16_t k_pos; // <20><><EFBFBD><EFBFBD><EFBFBD>ؽڸն<DAB8>ϵ<EFBFBD><CFB5> unit: 0.0-1.0 (q15) uint16_t k_pos; // <20><><EFBFBD><EFBFBD><EFBFBD>ؽڸն<DAB8>ϵ<EFBFBD><CFB5> unit: 0.0-1.0 (q15)
uint16_t k_spd; // <20><><EFBFBD><EFBFBD><EFBFBD>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5> unit: 0.0-1.0 (q15) uint16_t k_spd; // <20><><EFBFBD><EFBFBD><EFBFBD>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5> unit: 0.0-1.0 (q15)
} RIS_Comd_t; // <20><><EFBFBD>Ʋ<EFBFBD><C6B2><EFBFBD> 12Byte } RIS_Comd_t;
/** /**
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><EFBFBD><EFBFBD>ʽ *
* *
*/ */
typedef struct typedef struct
{ {
uint8_t head[2]; // <20><>ͷ 2Byte uint8_t head[2];
RIS_Mode_t mode; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ 1Byte RIS_Mode_t mode;
RIS_Comd_t comd; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 12Byte RIS_Comd_t comd;
uint16_t CRC16; // CRC 2Byte uint16_t CRC16;
} ControlData_t; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 17Byte } ControlData_t;

View File

@ -102,7 +102,6 @@ typedef struct {
BSP_CAN_t chassis5065; BSP_CAN_t chassis5065;
BSP_CAN_t motor3508; BSP_CAN_t motor3508;
BSP_CAN_t pitch6020; BSP_CAN_t pitch6020;
BSP_CAN_t sick; BSP_CAN_t sick;
} CAN_Params_t; } CAN_Params_t;

View File

@ -55,8 +55,11 @@ void Task_up(void *argument)
// GM6020_control(&UP, 100) ; // GM6020_control(&UP, 100) ;
// UP_M2006_angle(&UP, 180); // UP_M2006_angle(&UP, 180);
// UP_M3508_speed(&UP, 500); // UP_M3508_speed(&UP, 500);
// VESC_M5065_Control(&UP, 1000); VESC_M5065_Control(&UP, 00);
ALL_Motor_Control(&UP,&UP_CAN_out); ALL_Motor_Control(&UP,&UP_CAN_out);
// GO_M8010_send_data(&huart6, 0,0,0,5,10,0.12,0.08);
osDelay(1);
/*imu数据获取*/ /*imu数据获取*/
osMessageQueueGet(task_runtime.msgq.imu.eulr, &UP.pos088.imu_eulr, NULL, 0); osMessageQueueGet(task_runtime.msgq.imu.eulr, &UP.pos088.imu_eulr, NULL, 0);