From eb121bcb56057b54bc39985f6bf474fcec63a061 Mon Sep 17 00:00:00 2001 From: kai <1797003616@qq.com> Date: Sat, 2 Mar 2024 17:04:22 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=99=9A=E6=8B=9F?= =?UTF-8?q?=E4=B8=B2=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/c_cpp_properties.json | 4 +- .vscode/launch.json | 12 +++++- .vscode/settings.json | 71 ++++------------------------------- .vscode/tasks.json | 4 +- Src/usbd_conf.c | 6 +-- 5 files changed, 22 insertions(+), 75 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 0859405..eec0eb2 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -11,8 +11,8 @@ "_UNICODE" ], "cStandard": "c17", - "cppStandard": "gnu++17", - "intelliSenseMode": "windows-gcc-arm", + "cppStandard": "gnu++14", + "intelliSenseMode": "windows-gcc-x86", "configurationProvider": "ms-vscode.makefile-tools" } ], diff --git a/.vscode/launch.json b/.vscode/launch.json index 0e9742c..704f635 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -21,7 +21,11 @@ ], "runToEntryPoint": "main", // 调试时在main函数入口停下 "rtos": "FreeRTOS", - //"preLaunchTask": "build task",//先运行Build任务编译项目,取消注释即可使用 + "preLaunchTask": "build task",//先运行Build任务编译项目,取消注释即可使用 + "liveWatch": { + "enabled": true, + "samplesPerSecond": 4 + } // dap若要使用log,请使用Jlink调试任务启动,之后再打开log任务 // 若想要在调试前编译并且打开log,可只使用log的prelaunch task并为log任务添加depends on依赖 }, @@ -39,7 +43,11 @@ "interface": "swd", "svdFile": "STM32F407.svd", "rtos": "FreeRTOS", - // "preLaunchTask": "build task",//先运行Build任务,取消注释即可使用 + "preLaunchTask": "build task",//先运行Build任务,取消注释即可使用 + "liveWatch": { + "enabled": true, + "samplesPerSecond": 4 + } //"preLaunchTask": "log", // 调试时同时开启RTT viewer窗口,若daplink使用jlinkGDBserver启动,需要先开始调试再打开log // 若想要在调试前编译并且打开log,可只使用log的prelaunch task并为log任务添加depends on依赖 }, diff --git a/.vscode/settings.json b/.vscode/settings.json index c84d887..fae2d40 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,68 +1,11 @@ { "files.associations": { - "robot_def.h": "c", - "bsp_dwt.h": "c", - "dji_motor.h": "c", - "message_center.h": "c", - "super_cap.h": "c", - "can_comm.h": "c", - "lqr.h": "c", - "math.h": "c", - "stdint.h": "c", - "general_def.h": "c", - "lk9025.h": "c", - "arm_math.h": "c", - "bmi088driver.h": "c", - "bmi088middleware.h": "c", - "bmi088_regndef.h": "c", - "bmi088reg.h": "c", - "balance.h": "c", - "stdlib.h": "c", - "memory.h": "c", - "bsp_usart.h": "c", - "compare": "c", - "limits": "c", - "*.tcc": "c", - "type_traits": "c", - "bsp_log.h": "c", - "segger_rtt.h": "c", - "referee.h": "c", - "referee_communication.h": "c", - "vmc_project.h": "c", - "user_lib.h": "c", - "quaternionekf.h": "c", + "stm32f4xx_hal_def.h": "c", "bsp_usb.h": "c", - "robot.h": "c", - "rm_referee.h": "c", - "stdio.h": "c", - "crc.h": "c", - "bmi088.h": "c", - "cmath": "c", - "ht04.h": "c", - "gain_table.h": "c", - "referee_task.h": "c", - "task.h": "c", - "robot_task.h": "c", - "motor_task.h": "c", - "bsp_flash.h": "c", - "bsp_iic.h": "c", - "usbd_cdc_if.h": "c", - "kf.h": "c", - "none.h": "c", - "buzzer.h": "c", - "bsp_pwm.h": "c", - "main.h": "c", - "stm32f4xx_hal_conf.h": "c", - "master_process.h": "c", - "bsp_can.h": "c", - "can.h": "c", - "servo_motor.h": "c" - }, - // "clangd.arguments": [ - // "-query-driver=C:/msys64/mingw64/bin/arm-none-eabi-*.exe", - // ], - "cortex-debug.variableUseNaturalFormat": true, - "C_Cpp.default.configurationProvider": "ms-vscode.makefile-tools", - // "C_Cpp.default.compilerPath": "D:\\Msys2\\mingw64\\bin\\arm-none-eabi-gcc.exe" - "makefile.compileCommandsPath": "build/compile_commands.json" + "usb_device.h": "c", + "usbd_cdc.h": "c", + "usbd_conf.h": "c", + "usbd_desc.h": "c", + "usbd_cdc_if.h": "c" + } } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 3c32888..00c3de3 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -15,7 +15,7 @@ { "label": "download dap", "type": "shell", // 如果希望在下载前编译,可以把command换成下面的命令 - "command":"mingw32-make download_dap", // "mingw32-make -j24 ; mingw32-make download_dap", + "command":"mingw32-make -j24 ; mingw32-make download_dap", // "mingw32-make -j24 ; mingw32-make download_dap", "group": { // 如果没有修改代码,编译任务不会消耗时间,因此推荐使用上面的替换. "kind": "build", "isDefault": false, @@ -24,7 +24,7 @@ { "label": "download jlink", // 要使用此任务,需添加jlink的环境变量 "type": "shell", - "command":"mingw32-make download_jlink", // "mingw32-make -j24 ; mingw32-make download_dap" + "command":"mingw32-make -j24 ; mingw32-make download_jlink", // "mingw32-make -j24 ; mingw32-make download_jlink" "group": { "kind": "build", "isDefault": false, diff --git a/Src/usbd_conf.c b/Src/usbd_conf.c index 4d67d2a..217c497 100644 --- a/Src/usbd_conf.c +++ b/Src/usbd_conf.c @@ -95,11 +95,7 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) HAL_NVIC_SetPriority(OTG_FS_IRQn, 5, 0); HAL_NVIC_EnableIRQ(OTG_FS_IRQn); /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */ - // 上电后重新枚举usb设备 - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); - DWT_Delay(100); - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); - DWT_Delay(100); + /* USER CODE END USB_OTG_FS_MspInit 1 */ } } From 619d148b45bcc3218920a6939b32e2df6c8faa06 Mon Sep 17 00:00:00 2001 From: kai <1797003616@qq.com> Date: Sat, 2 Mar 2024 20:58:17 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=8A=E7=94=B5?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E6=9E=9A=E4=B8=BEusb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/usbd_conf.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Src/usbd_conf.c b/Src/usbd_conf.c index 217c497..43bd48a 100644 --- a/Src/usbd_conf.c +++ b/Src/usbd_conf.c @@ -96,6 +96,12 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) HAL_NVIC_EnableIRQ(OTG_FS_IRQn); /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */ + // 上电后重新枚举usb设备 + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); + DWT_Delay(0.1); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_SET); + DWT_Delay(0.1); + /* USER CODE END USB_OTG_FS_MspInit 1 */ } } From 6029d10698962cec0a3afefd55201831e4cd4e88 Mon Sep 17 00:00:00 2001 From: kai <1797003616@qq.com> Date: Mon, 29 Apr 2024 11:41:49 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=A3=81=E5=88=A4?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E7=BB=93=E6=9E=84=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/referee/referee_protocol.h | 82 +++++++++++++++--------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/modules/referee/referee_protocol.h b/modules/referee/referee_protocol.h index 22416b3..3d7e908 100644 --- a/modules/referee/referee_protocol.h +++ b/modules/referee/referee_protocol.h @@ -88,16 +88,16 @@ typedef enum /* 命令码数据段长,根据官方协议来定义长度,还有自定义数据长度 */ typedef enum { - LEN_game_state = 3, // 0x0001 + LEN_game_state = 11, // 0x0001 LEN_game_result = 1, // 0x0002 - LEN_game_robot_HP = 2, // 0x0003 + LEN_game_robot_HP = 32, // 0x0003 LEN_event_data = 4, // 0x0101 LEN_supply_projectile_action = 4, // 0x0102 - LEN_game_robot_state = 27, // 0x0201 - LEN_power_heat_data = 14, // 0x0202 + LEN_game_robot_state = 13, // 0x0201 + LEN_power_heat_data = 16, // 0x0202 LEN_game_robot_pos = 16, // 0x0203 - LEN_buff_musk = 1, // 0x0204 - LEN_aerial_robot_energy = 1, // 0x0205 + LEN_buff_musk = 6, // 0x0204 + LEN_aerial_robot_energy = 2, // 0x0205 LEN_robot_hurt = 1, // 0x0206 LEN_shoot_data = 7, // 0x0207 LEN_receive_data = 6 + Communicate_Data_LEN, // 0x0301 @@ -107,12 +107,13 @@ typedef enum /****************************接收数据的详细说明****************************/ /****************************接收数据的详细说明****************************/ -/* ID: 0x0001 Byte: 3 比赛状态数据 */ -typedef struct -{ - uint8_t game_type : 4; - uint8_t game_progress : 4; - uint16_t stage_remain_time; +/* ID: 0x0001 Byte: 11 比赛状态数据 */ +typedef struct +{ + uint8_t game_type : 4; + uint8_t game_progress : 4; + uint16_t stage_remain_time; + uint64_t SyncTimeStamp; } ext_game_state_t; /* ID: 0x0002 Byte: 1 比赛结果数据 */ @@ -157,37 +158,31 @@ typedef struct uint8_t supply_projectile_num; } ext_supply_projectile_action_t; -/* ID: 0X0201 Byte: 27 机器人状态数据 */ +/* ID: 0X0201 Byte: 13 机器人状态数据 */ typedef struct { - uint8_t robot_id; - uint8_t robot_level; - uint16_t remain_HP; - uint16_t max_HP; - uint16_t shooter_id1_17mm_cooling_rate; - uint16_t shooter_id1_17mm_cooling_limit; - uint16_t shooter_id1_17mm_speed_limit; - uint16_t shooter_id2_17mm_cooling_rate; - uint16_t shooter_id2_17mm_cooling_limit; - uint16_t shooter_id2_17mm_speed_limit; - uint16_t shooter_id1_42mm_cooling_rate; - uint16_t shooter_id1_42mm_cooling_limit; - uint16_t shooter_id1_42mm_speed_limit; - uint16_t chassis_power_limit; - uint8_t mains_power_gimbal_output : 1; - uint8_t mains_power_chassis_output : 1; - uint8_t mains_power_shooter_output : 1; + uint8_t robot_id; + uint8_t robot_level; + uint16_t current_HP; + uint16_t maximum_HP; + uint16_t shooter_barrel_cooling_value; + uint16_t shooter_barrel_heat_limit; + uint16_t chassis_power_limit; + uint8_t power_management_gimbal_output : 1; + uint8_t power_management_chassis_output : 1; + uint8_t power_management_shooter_output : 1; } ext_game_robot_state_t; -/* ID: 0X0202 Byte: 14 实时功率热量数据 */ +/* ID: 0X0202 Byte: 16 实时功率热量数据 */ typedef struct { - uint16_t chassis_volt; - uint16_t chassis_current; - float chassis_power; // 瞬时功率 - uint16_t chassis_power_buffer; // 60焦耳缓冲能量 - uint16_t shooter_heat0; // 17mm - uint16_t shooter_heat1; + uint16_t chassis_voltage; + uint16_t chassis_current; + float chassis_power; + uint16_t buffer_energy; + uint16_t shooter_17mm_1_barrel_heat; + uint16_t shooter_17mm_2_barrel_heat; + uint16_t shooter_42mm_barrel_heat; } ext_power_heat_data_t; /* ID: 0x0203 Byte: 16 机器人位置数据 */ @@ -199,16 +194,21 @@ typedef struct float yaw; } ext_game_robot_pos_t; -/* ID: 0x0204 Byte: 1 机器人增益数据 */ +/* ID: 0x0204 Byte: 6 机器人增益数据 */ typedef struct { - uint8_t power_rune_buff; + uint8_t recovery_buff; + uint8_t cooling_buff; + uint8_t defence_buff; + uint8_t vulnerability_buff; + uint16_t attack_buff; } ext_buff_musk_t; -/* ID: 0x0205 Byte: 1 空中机器人能量状态数据 */ +/* ID: 0x0205 Byte: 2 空中机器人能量状态数据 */ typedef struct { - uint8_t attack_time; + uint8_t airforce_status; + uint8_t time_remain; } aerial_robot_energy_t; /* ID: 0x0206 Byte: 1 伤害状态数据 */ From 71086bb71ef53348bd607d323e7cebaa52b5679f Mon Sep 17 00:00:00 2001 From: kai <1797003616@qq.com> Date: Tue, 30 Apr 2024 16:41:08 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86?= =?UTF-8?q?=E7=94=B5=E6=9C=BA=E5=81=9C=E8=BD=AC=E5=92=8C=E5=8F=8D=E8=BD=AC?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/motor/DJImotor/dji_motor.c | 2 +- modules/motor/HTmotor/HT04.c | 7 ++++--- modules/motor/HTmotor/HT04.h | 1 + modules/motor/LKmotor/LK9025.c | 7 ++++--- modules/motor/LKmotor/LK9025.h | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/modules/motor/DJImotor/dji_motor.c b/modules/motor/DJImotor/dji_motor.c index e9345cc..bc215d4 100644 --- a/modules/motor/DJImotor/dji_motor.c +++ b/modules/motor/DJImotor/dji_motor.c @@ -300,7 +300,7 @@ void DJIMotorControl() // 若该电机处于停止状态,直接将buff置零 if (motor->stop_flag == MOTOR_STOP) - memset(sender_assignment[group].tx_buff + 2 * num, 0, 16u); + memset(sender_assignment[group].tx_buff + 2 * num, 0, sizeof(uint16_t)); } // 遍历flag,检查是否要发送这一帧报文 diff --git a/modules/motor/HTmotor/HT04.c b/modules/motor/HTmotor/HT04.c index fdfad15..eec1167 100644 --- a/modules/motor/HTmotor/HT04.c +++ b/modules/motor/HTmotor/HT04.c @@ -121,7 +121,7 @@ HTMotorInstance *HTMotorInit(Motor_Init_Config_s *config) Daemon_Init_Config_s conf = { .callback = HTMotorLostCallback, .owner_id = motor, - .reload_count = 5, // 20ms + .reload_count = 5, // 50ms }; motor->motor_daemon = DaemonRegister(&conf); @@ -155,6 +155,9 @@ __attribute__((noreturn)) void HTMotorTask(void const *argument) while (1) { pid_ref = motor->pid_ref; + if (setting->motor_reverse_flag == MOTOR_DIRECTION_REVERSE) + pid_ref *= -1; + if ((setting->close_loop_type & ANGLE_LOOP) && setting->outer_loop_type == ANGLE_LOOP) { if (setting->angle_feedback_source == OTHER_FEED) @@ -186,8 +189,6 @@ __attribute__((noreturn)) void HTMotorTask(void const *argument) } set = pid_ref; - if (setting->motor_reverse_flag == MOTOR_DIRECTION_REVERSE) - set *= -1; LIMIT_MIN_MAX(set, T_MIN, T_MAX); tmp = float_to_uint(set, T_MIN, T_MAX, 12); diff --git a/modules/motor/HTmotor/HT04.h b/modules/motor/HTmotor/HT04.h index 1ad61f5..caa8957 100644 --- a/modules/motor/HTmotor/HT04.h +++ b/modules/motor/HTmotor/HT04.h @@ -11,6 +11,7 @@ #define CURRENT_SMOOTH_COEF 0.9f #define SPEED_BUFFER_SIZE 5 #define HT_SPEED_BIAS -0.0109901428f // 电机速度偏差,单位rad/s +#define TORQUE_COEF_HT 3.5 // 扭矩系数,单位N.m/A #define P_MIN -95.5f // Radians #define P_MAX 95.5f diff --git a/modules/motor/LKmotor/LK9025.c b/modules/motor/LKmotor/LK9025.c index c9fadbc..b98c018 100644 --- a/modules/motor/LKmotor/LK9025.c +++ b/modules/motor/LKmotor/LK9025.c @@ -104,6 +104,8 @@ void LKMotorControl() measure = &motor->measure; setting = &motor->motor_settings; pid_ref = motor->pid_ref; + if (setting->motor_reverse_flag == MOTOR_DIRECTION_REVERSE) + pid_ref *= -1; if ((setting->close_loop_type & ANGLE_LOOP) && setting->outer_loop_type == ANGLE_LOOP) { @@ -132,9 +134,8 @@ void LKMotorControl() pid_ref = PIDCalculate(&motor->current_PID, measure->real_current, pid_ref); } - set = pid_ref; - if (setting->motor_reverse_flag == MOTOR_DIRECTION_REVERSE) - set *= -1; + set = (int16_t)pid_ref; + // 这里随便写的,为了兼容多电机命令.后续应该将tx_id以更好的方式表达电机id,单独使用一个CANInstance,而不是用第一个电机的CANInstance memcpy(sender_instance->tx_buff + (motor->motor_can_ins->tx_id - 0x280) * 2, &set, sizeof(uint16_t)); diff --git a/modules/motor/LKmotor/LK9025.h b/modules/motor/LKmotor/LK9025.h index a5cef5a..10a32ba 100644 --- a/modules/motor/LKmotor/LK9025.h +++ b/modules/motor/LKmotor/LK9025.h @@ -15,7 +15,7 @@ #define SPEED_SMOOTH_COEF 0.85f #define REDUCTION_RATIO_DRIVEN 1 #define ECD_ANGLE_COEF_LK (360.0f / 65536.0f) -#define CURRENT_TORQUE_COEF_LK 0.003645f // 电流设定值转换成扭矩的系数,算出来的设定值除以这个系数就是扭矩值 +#define CURRENT_TORQUE_COEF_LK 0.00512f // 电流设定值转换成扭矩的系数,这里对应的是16T typedef struct // 9025 {