From eefc0883ed15c3f2fa8ad795469ec11a4b8e665f Mon Sep 17 00:00:00 2001 From: NeoZng Date: Sun, 19 Mar 2023 11:11:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E7=AD=89=E7=BA=A7=E7=9A=84=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 6 +++++- .vscode/tasks.json | 3 +++ application/chassis/chassis.c | 1 + application/cmd/robot_cmd.c | 2 ++ application/gimbal/gimbal.c | 1 + application/shoot/shoot.c | 1 + bsp/can/bsp_can.c | 1 + bsp/log/bsp_log.c | 1 - bsp/log/bsp_log.h | 30 ++++++++++++++++++++++++------ bsp/usb/bsp_usb.c | 7 ++++--- modules/motor/DJImotor/dji_motor.c | 26 +++++++++++--------------- 11 files changed, 53 insertions(+), 26 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 989a8f1..9247755 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -19,8 +19,10 @@ "configFiles": [ "openocd_dap.cfg", // 配置文件已经在根目录提供,若要修改以此类推,openocd的路径下的share/scripts中有各种写好的配置文件 ], - "runToEntryPoint": "main" // 调试时在main函数入口停下 + "runToEntryPoint": "main", // 调试时在main函数入口停下 //"preLaunchTask": "build task",//先运行Build任务编译项目,取消注释即可使用 + //"preLaunchTask": "log", // 调试时同时开启RTT viewer窗口 + // 若想要在调试前编译并且打开log,可只使用log的prelaunch task并为log任务添加depends on依赖 }, // 使用j-link进行调试时的参考配置 { @@ -37,6 +39,8 @@ "svdFile": "STM32F407.svd", "rtos": "FreeRTOS", // "preLaunchTask": "build task",//先运行Build任务,取消注释即可使用 + //"preLaunchTask": "log", // 调试时同时开启RTT viewer窗口 + // 若想要在调试前编译并且打开log,可只使用log的prelaunch task并为log任务添加depends on依赖 }, ], } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 46dbedf..d5bf982 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -36,6 +36,9 @@ "command":"JlinkRTTClient", "args": [], "problemMatcher": [], + // "dependsOn":[ + // "build task", // 可以添加多个. + // ] } ] } \ No newline at end of file diff --git a/application/chassis/chassis.c b/application/chassis/chassis.c index 30a23d8..283cb24 100644 --- a/application/chassis/chassis.c +++ b/application/chassis/chassis.c @@ -17,6 +17,7 @@ #include "super_cap.h" #include "message_center.h" +// referee需要移动到module层 ///////////////////////// #include "referee.h" #include "rm_referee.h" diff --git a/application/cmd/robot_cmd.c b/application/cmd/robot_cmd.c index ebfac6b..d4fdab2 100644 --- a/application/cmd/robot_cmd.c +++ b/application/cmd/robot_cmd.c @@ -1,5 +1,7 @@ +// app #include "robot_def.h" #include "robot_cmd.h" +// module #include "remote_control.h" #include "ins_task.h" #include "master_process.h" diff --git a/application/gimbal/gimbal.c b/application/gimbal/gimbal.c index 389ad64..95f37f1 100644 --- a/application/gimbal/gimbal.c +++ b/application/gimbal/gimbal.c @@ -1,5 +1,6 @@ #include "gimbal.h" #include "robot_def.h" + #include "dji_motor.h" #include "ins_task.h" #include "message_center.h" diff --git a/application/shoot/shoot.c b/application/shoot/shoot.c index f2ff607..4f50b7d 100644 --- a/application/shoot/shoot.c +++ b/application/shoot/shoot.c @@ -1,5 +1,6 @@ #include "shoot.h" #include "robot_def.h" + #include "dji_motor.h" #include "message_center.h" #include "bsp_dwt.h" diff --git a/bsp/can/bsp_can.c b/bsp/can/bsp_can.c index 5d8c945..36066d1 100644 --- a/bsp/can/bsp_can.c +++ b/bsp/can/bsp_can.c @@ -6,6 +6,7 @@ /* can instance ptrs storage, used for recv callback */ // 在CAN产生接收中断会遍历数组,选出hcan和rxid与发生中断的实例相同的那个,调用其回调函数 +// @todo: 后续为每个CAN总线单独添加一个can_instance指针数组,提高回调查找的性能 static CANInstance *can_instance[CAN_MX_REGISTER_CNT] = {NULL}; static uint8_t idx; // 全局CAN实例索引,每次有新的模块注册会自增 diff --git a/bsp/log/bsp_log.c b/bsp/log/bsp_log.c index 630733e..da35f0d 100644 --- a/bsp/log/bsp_log.c +++ b/bsp/log/bsp_log.c @@ -4,7 +4,6 @@ #include "SEGGER_RTT_Conf.h" #include -#define BUFFER_INDEX 0 void BSPLogInit() { diff --git a/bsp/log/bsp_log.h b/bsp/log/bsp_log.h index d4fa43c..d5f0b2a 100644 --- a/bsp/log/bsp_log.h +++ b/bsp/log/bsp_log.h @@ -1,6 +1,20 @@ #ifndef _BSP_LOG_H #define _BSP_LOG_H +#include "SEGGER_RTT.h" +#include "SEGGER_RTT_Conf.h" +#include + +#define BUFFER_INDEX 0 + + + +/** + * @brief 日志系统初始化 + * + */ +void BSPLogInit(); + /** * @brief 日志功能原型,供下面的LOGI,LOGW,LOGE等使用 * @@ -12,20 +26,24 @@ ##__VA_ARGS__, \ RTT_CTRL_RESET) +/*------下面是日志输出的接口--------*/ + /* 清屏 */ #define LOG_CLEAR() SEGGER_RTT_WriteString(0, " "RTT_CTRL_CLEAR) /* 无颜色日志输出 */ #define LOG(format,...) LOG_PROTO("","",format,##__VA_ARGS__) -/* 有颜色格式日志输出 */ -#define LOGINFO(format,...) LOG_PROTO("I: ", RTT_CTRL_TEXT_BRIGHT_GREEN , format, ##__VA_ARGS__) -#define LOGWARNING(format,...) LOG_PROTO("W: ", RTT_CTRL_TEXT_BRIGHT_YELLOW, format, ##__VA_ARGS__) -#define LOGERROR(format,...) LOG_PROTO("E: ", RTT_CTRL_TEXT_BRIGHT_RED , format, ##__VA_ARGS__) - +/* 有颜色格式日志输出,建议使用这些宏来输出日志 */ +// information level +#define LOGINFO(format,...) LOG_PROTO("I", RTT_CTRL_TEXT_BRIGHT_GREEN , format, ##__VA_ARGS__) +// warning level +#define LOGWARNING(format,...) LOG_PROTO("W", RTT_CTRL_TEXT_BRIGHT_YELLOW, format, ##__VA_ARGS__) +// error level +#define LOGERROR(format,...) LOG_PROTO("E", RTT_CTRL_TEXT_BRIGHT_RED , format, ##__VA_ARGS__) /** - * @brief 通过segger RTT打印日志,支持格式化输出,格式化输出的实现参考printf + * @brief 通过segger RTT打印日志,支持格式化输出,格式化输出的实现参考printf. * * @param fmt 格式字符串 * @param ... 参数列表 diff --git a/bsp/usb/bsp_usb.c b/bsp/usb/bsp_usb.c index aade217..f19c69b 100644 --- a/bsp/usb/bsp_usb.c +++ b/bsp/usb/bsp_usb.c @@ -11,20 +11,21 @@ #include "bsp_usb.h" -static uint8_t *bsp_usb_rx_buffer; // 接收到的数据会被放在这里,buffer size为2028 +static uint8_t *bsp_usb_rx_buffer; // 接收到的数据会被放在这里,buffer size为2048 // 注意usb单个数据包(Full speed模式下)最大为64byte,超出可能会出现丢包情况 // 这是传输完成的回调函数,在usbd_cdc_if.c中被调用 __weak void USBTransmitCpltCallback(uint32_t len) { - // 本次发送的数据 + // 本次发送的数据长度 UNUSED(len); // 传输完成会调用此函数,to do something } +// 这是接收回调函数 __weak void USBReceiveCpltCallback(uint32_t len) { - // 本次接收的数据 + // 本次接收的数据长度 UNUSED(len); // 传输完成会调用此函数,to do something } diff --git a/modules/motor/DJImotor/dji_motor.c b/modules/motor/DJImotor/dji_motor.c index 6ca6fba..6127358 100644 --- a/modules/motor/DJImotor/dji_motor.c +++ b/modules/motor/DJImotor/dji_motor.c @@ -1,5 +1,6 @@ #include "dji_motor.h" #include "general_def.h" +#include "bsp_log.h" static uint8_t idx = 0; // register idx,是该文件的全局电机索引,在注册时使用 @@ -32,16 +33,6 @@ static CANInstance sender_assignment[6] = { */ static uint8_t sender_enable_flag[6] = {0}; -/** - * @brief 当注册的电机id冲突时,会进入这个函数并提示冲突的ID - * @todo 通过segger jlink 发送日志 - */ -static void IDcrash_Handler(uint8_t conflict_motor_idx, uint8_t temp_motor_idx) -{ - while (1) - ; -} - /** * @brief 根据电调/拨码开关上的ID,根据说明书的默认id分配方式计算发送ID和接收ID, * 并对电机进行分组以便处理多电机控制命令 @@ -79,7 +70,10 @@ static void MotorSenderGrouping(DJIMotorInstance *motor, CAN_Init_Config_s *conf for (size_t i = 0; i < idx; ++i) { if (dji_motor_instance[i]->motor_can_instance->can_handle == config->can_handle && dji_motor_instance[i]->motor_can_instance->rx_id == config->rx_id) - IDcrash_Handler(i, idx); + { + LOGERROR("[dji_motor] ID crash. Check in debug mode, add dji_motor_instance to watch to get more information."); // 后续可以把id和CAN打印出来 + while (1); // 6020的id 1-4和2006/3508的id 5-8会发生冲突(若有注册,即1!5,2!6,3!7,4!8) (1!5!,LTC! (((不是) + } } break; @@ -103,7 +97,10 @@ static void MotorSenderGrouping(DJIMotorInstance *motor, CAN_Init_Config_s *conf for (size_t i = 0; i < idx; ++i) { if (dji_motor_instance[i]->motor_can_instance->can_handle == config->can_handle && dji_motor_instance[i]->motor_can_instance->rx_id == config->rx_id) - IDcrash_Handler(i, idx); + { + LOGERROR("[dji_motor] ID crash. Check in debug mode, add dji_motor_instance to watch to get more information."); + while (1); // 6020的id 1-4和2006/3508的id 5-8会发生冲突(若有注册,即1!5,2!6,3!7,4!8) + } } break; @@ -139,7 +136,7 @@ static void DecodeDJIMotor(CANInstance *_instance) CURRENT_SMOOTH_COEF * (float)((int16_t)(rxbuff[4] << 8 | rxbuff[5])); measure->temperate = rxbuff[6]; - // 多圈角度计算,前提是两次采样间电机转过的角度小于180°,高速转动时可能会出现问题,自己画个图就清楚计算过程了 + // 多圈角度计算,前提是假设两次采样间电机转过的角度小于180°,自己画个图就清楚计算过程了 if (measure->ecd - measure->last_ecd > 4096) measure->total_round--; else if (measure->ecd - measure->last_ecd < -4096) @@ -191,8 +188,7 @@ void DJIMotorChangeFeed(DJIMotorInstance *motor, Closeloop_Type_e loop, Feedback } else { - while (1) - ; // LOOP TYPE ERROR!!!检查是否传入了正确的LOOP类型,或发生了指针越界 + LOGERROR("[dji_motor] loop type error, check memory access and func param");// 检查是否传入了正确的LOOP类型,或发生了指针越界 } }