From f5a8f86a1b47a54e6ab6c620af943ae8d4e3f6b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=AF=E5=B0=8F=E4=BC=81=E9=B9=85=E5=91=80?= <1357482552@qq.com> Date: Mon, 27 May 2024 20:33:08 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9D=BF=E9=97=B4?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=8F=91=E9=80=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/robot_cmd/CAN_communication.c | 124 ++++++++++++++++++ application/robot_cmd/CAN_communication.h | 29 +++- ...50\346\204\217\344\272\213\351\241\271.md" | 2 +- 3 files changed, 153 insertions(+), 2 deletions(-) create mode 100644 application/robot_cmd/CAN_communication.c diff --git a/application/robot_cmd/CAN_communication.c b/application/robot_cmd/CAN_communication.c new file mode 100644 index 0000000..bff28d5 --- /dev/null +++ b/application/robot_cmd/CAN_communication.c @@ -0,0 +1,124 @@ +/** + ****************************(C) COPYRIGHT 2024 Polarbear**************************** + * @file CAN_communication.c/h + * @brief CAN通信部分 + * @history + * Version Date Author Modification + * V1.0.0 May-27-2024 Penguin 1. done + * + @verbatim + ============================================================================== +板间通信时stdid的内容如下 +data_type + (data_id << 4) + target_id + +bit 0-3: target_id +bit 4-7: data_id +bit 8-11: data_type + + ============================================================================== + @endverbatim + ****************************(C) COPYRIGHT 2024 Polarbear**************************** + */ +#include "CAN_communication.h" + +#include "bsp_can.h" + +static CanCtrlData_s CAN_CTRL_DATA = { + .tx_header.IDE = CAN_ID_STD, + .tx_header.RTR = CAN_RTR_DATA, + .tx_header.DLC = 8, +}; + +/*-------------------- Private functions --------------------*/ +// 板间通信 + +/** + * @brief 发送自定义数据 + * @param[in] hcan CAN句柄 + * @param[in] data_id 数据包ID + * @param[in] target_id 目标板ID + * @param[in] data 包含8个字节的数据的指针 + * @retval none + */ +static void SendData(hcan_t * hcan, uint16_t data_id, uint16_t target_id, uint8_t * data) +{ + CAN_CTRL_DATA.hcan = hcan; + + CAN_CTRL_DATA.tx_header.StdId = BOARD_DATA_ANY + (data_id << 4) + target_id; + + for (size_t i = 0; i < 8; i++) { + CAN_CTRL_DATA.tx_data[i] = data[i]; + } + + CAN_SendTxMessage(&CAN_CTRL_DATA); +} + +/** + * @brief 发送uint16数据 + * @param[in] hcan CAN句柄 + * @param[in] data_id 数据包ID + * @param[in] target_id 目标板ID + * @param[in] data_1 数据1 + * @param[in] data_2 数据2 + * @param[in] data_3 数据3 + * @param[in] data_4 数据4 + * @retval none + */ +static void Uint16SendData( + hcan_t * hcan, uint16_t data_id, uint16_t target_id, uint16_t data_1, uint16_t data_2, + uint16_t data_3, uint16_t data_4) +{ + CAN_CTRL_DATA.hcan = hcan; + + CAN_CTRL_DATA.tx_header.StdId = BOARD_DATA_UINT16 + (data_id << 4) + target_id; + + CAN_CTRL_DATA.tx_data[0] = data_1 >> 8; + CAN_CTRL_DATA.tx_data[1] = data_1; + CAN_CTRL_DATA.tx_data[2] = data_2 >> 8; + CAN_CTRL_DATA.tx_data[3] = data_2; + CAN_CTRL_DATA.tx_data[4] = data_3 >> 8; + CAN_CTRL_DATA.tx_data[5] = data_3; + CAN_CTRL_DATA.tx_data[6] = data_4 >> 8; + CAN_CTRL_DATA.tx_data[7] = data_4; + + CAN_SendTxMessage(&CAN_CTRL_DATA); +} + +/*-------------------- Public functions --------------------*/ + +/** + * @brief CAN发送数据到目标板 + * @param[in] can can口 + * @param[in] data_id 数据包ID + * @param[in] target_id 目标板ID + * @param[in] data 包含8个字节的数据的指针 + * @retval none + */ +void CanSendDataToBoard(uint8_t can, uint16_t data_id, uint16_t target_id, uint8_t * data) +{ + if (can == 1) + SendData(&hcan1, data_id, target_id, data); + else if (can == 2) + SendData(&hcan2, data_id, target_id, data); +} + +/** + * @brief CAN发送uint16数据到目标板 + * @param[in] can can口 + * @param[in] data_id 数据包ID + * @param[in] target_id 目标板ID + * @param[in] data_1 数据1 + * @param[in] data_2 数据2 + * @param[in] data_3 数据3 + * @param[in] data_4 数据4 + * @retval none + */ +void CanSendUint16DataToBoard( + uint8_t can, uint16_t data_id, uint16_t target_id, uint16_t data_1, uint16_t data_2, + uint16_t data_3, uint16_t data_4) +{ + if (can == 1) + Uint16SendData(&hcan1, data_id, target_id, data_1, data_2, data_3, data_4); + else if (can == 2) + Uint16SendData(&hcan2, data_id, target_id, data_1, data_2, data_3, data_4); +} \ No newline at end of file diff --git a/application/robot_cmd/CAN_communication.h b/application/robot_cmd/CAN_communication.h index 827cf1a..36cabbc 100644 --- a/application/robot_cmd/CAN_communication.h +++ b/application/robot_cmd/CAN_communication.h @@ -1,10 +1,37 @@ +/** + ****************************(C) COPYRIGHT 2024 Polarbear**************************** + * @file CAN_communication.c/h + * @brief CAN通信部分 + * @history + * Version Date Author Modification + * V1.0.0 May-27-2024 Penguin 1. done + * + @verbatim + ============================================================================== +板间通信时stdid的内容如下 +data_type + (data_id << 4) + target_id + +bit 0-3: target_id +bit 4-7: data_id +bit 8-11: data_type + + ============================================================================== + @endverbatim + ****************************(C) COPYRIGHT 2024 Polarbear**************************** + */ + #ifndef CAN_COMMUNICATION_H #define CAN_COMMUNICATION_H -#include "CAN_cmd_dji.h" #include "CAN_cmd_cybergear.h" #include "CAN_cmd_damiao.h" +#include "CAN_cmd_dji.h" #include "CAN_cmd_lingkong.h" #include "CAN_receive.h" +// clang-format off +#define BOARD_DATA_ANY ((uint16_t)0xA00) +#define BOARD_DATA_UINT16 ((uint16_t)0xB00) +// clang-format on + #endif // CAN_COMMUNICATION_H diff --git "a/doc/\346\263\250\346\204\217\344\272\213\351\241\271.md" "b/doc/\346\263\250\346\204\217\344\272\213\351\241\271.md" index 95f1ba8..91ae62e 100644 --- "a/doc/\346\263\250\346\204\217\344\272\213\351\241\271.md" +++ "b/doc/\346\263\250\346\204\217\344\272\213\351\241\271.md" @@ -5,7 +5,7 @@ 本本项目采取Google的开源代码风格 ### 编译要求 -最终编译结果要做到 `0-error,0-warning` ,若审核时将对代码进行完全编译,若发现有 error 或 warning,我们将会提醒。 +最终编译结果要做到 `0-error,0-warning` ,本项目启用了 `--diag_error=warning` 在编译时将 `warning` 视作 `error`。 ## 硬件上的 **达妙电机设置零点时先失能!!!!** \ No newline at end of file -- Gitee From 03e354d01d1520bbb8fb31ff58ceefee1213f3d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=AF=E5=B0=8F=E4=BC=81=E9=B9=85=E5=91=80?= <1357482552@qq.com> Date: Mon, 27 May 2024 20:34:52 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E5=BC=80=E6=94=BE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/robot_cmd/CAN_communication.c | 2 +- application/robot_cmd/CAN_communication.h | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/application/robot_cmd/CAN_communication.c b/application/robot_cmd/CAN_communication.c index bff28d5..563a6f2 100644 --- a/application/robot_cmd/CAN_communication.c +++ b/application/robot_cmd/CAN_communication.c @@ -121,4 +121,4 @@ void CanSendUint16DataToBoard( Uint16SendData(&hcan1, data_id, target_id, data_1, data_2, data_3, data_4); else if (can == 2) Uint16SendData(&hcan2, data_id, target_id, data_1, data_2, data_3, data_4); -} \ No newline at end of file +} diff --git a/application/robot_cmd/CAN_communication.h b/application/robot_cmd/CAN_communication.h index 36cabbc..b87ff6d 100644 --- a/application/robot_cmd/CAN_communication.h +++ b/application/robot_cmd/CAN_communication.h @@ -34,4 +34,10 @@ bit 8-11: data_type #define BOARD_DATA_UINT16 ((uint16_t)0xB00) // clang-format on +extern void CanSendDataToBoard(uint8_t can, uint16_t data_id, uint16_t target_id, uint8_t * data); + +extern void CanSendUint16DataToBoard( + uint8_t can, uint16_t data_id, uint16_t target_id, uint16_t data_1, uint16_t data_2, + uint16_t data_3, uint16_t data_4); + #endif // CAN_COMMUNICATION_H -- Gitee From 18212ecccd7ad7556facb565ee95163411d65d03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=AF=E5=B0=8F=E4=BC=81=E9=B9=85=E5=91=80?= <1357482552@qq.com> Date: Mon, 27 May 2024 20:49:21 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=9D=BF=E9=97=B4?= =?UTF-8?q?=E9=80=9A=E4=BF=A1=E6=95=B0=E6=8D=AE=E8=A7=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/robot_cmd/CAN_communication.h | 4 --- application/robot_cmd/CAN_receive.c | 41 ++++++++++++++++++----- application/robot_param.h | 1 + bsp/boards/bsp_can.h | 5 +++ 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/application/robot_cmd/CAN_communication.h b/application/robot_cmd/CAN_communication.h index b87ff6d..7d81855 100644 --- a/application/robot_cmd/CAN_communication.h +++ b/application/robot_cmd/CAN_communication.h @@ -29,10 +29,6 @@ bit 8-11: data_type #include "CAN_cmd_lingkong.h" #include "CAN_receive.h" -// clang-format off -#define BOARD_DATA_ANY ((uint16_t)0xA00) -#define BOARD_DATA_UINT16 ((uint16_t)0xB00) -// clang-format on extern void CanSendDataToBoard(uint8_t can, uint16_t data_id, uint16_t target_id, uint8_t * data); diff --git a/application/robot_cmd/CAN_receive.c b/application/robot_cmd/CAN_receive.c index 084b648..9285ccf 100644 --- a/application/robot_cmd/CAN_receive.c +++ b/application/robot_cmd/CAN_receive.c @@ -22,14 +22,16 @@ #include "CAN_receive.h" -#include - #include "bsp_can.h" #include "cmsis_os.h" #include "detect_task.h" +#include "robot_param.h" +#include "string.h" #include "usb_task.h" #include "user_lib.h" +#define DATA_NUM 10 + // 接收数据 static DjiMotorMeasure_t CAN1_DJI_MEASURE[11]; static DjiMotorMeasure_t CAN2_DJI_MEASURE[11]; @@ -42,6 +44,10 @@ static DmMeasure_s CAN2_DM_MEASURE[DM_NUM]; static LkMeasure_s CAN1_LK_MEASURE[LK_NUM]; static LkMeasure_s CAN2_LK_MEASURE[LK_NUM]; + +static uint8_t OTHER_BOARD_DATA_ANY[DATA_NUM][8]; +static uint16_t OTHER_BOARD_DATA_UINT16[DATA_NUM][4]; + /*-------------------- Decode --------------------*/ /** @@ -108,7 +114,7 @@ void LkFdbData(LkMeasure_s * lk_measure, uint8_t * rx_data) */ static void DecodeStdIdData(hcan_t * CAN, CAN_RxHeaderTypeDef * rx_header, uint8_t rx_data[8]) { - switch (rx_header->StdId) { + switch (rx_header->StdId) { //电机解码 case DJI_M1_ID: case DJI_M2_ID: case DJI_M3_ID: @@ -129,8 +135,8 @@ static void DecodeStdIdData(hcan_t * CAN, CAN_RxHeaderTypeDef * rx_header, uint8 { DjiFdbData(&CAN2_DJI_MEASURE[i], rx_data); } - break; - } + return; + } case DM_M1_ID: case DM_M2_ID: case DM_M3_ID: @@ -146,7 +152,8 @@ static void DecodeStdIdData(hcan_t * CAN, CAN_RxHeaderTypeDef * rx_header, uint8 { DmFdbData(&CAN2_DM_MEASURE[i], rx_data); } - } break; + return; + } case LK_M1_ID: case LK_M2_ID: case LK_M3_ID: @@ -160,11 +167,29 @@ static void DecodeStdIdData(hcan_t * CAN, CAN_RxHeaderTypeDef * rx_header, uint8 { LkFdbData(&CAN2_LK_MEASURE[i], rx_data); } - } break; + return; + } default: { break; } } + + //板间通信数据解码 + // clang-format off + uint16_t data_type = rx_header->StdId & 0xF00; + uint16_t data_id = (rx_header->StdId & 0x0F0) >> 4; + uint16_t target_id = rx_header->StdId & 0x00F; + // clang-format on + if (target_id != __SELF_BOARD_ID) return; + + if (data_type == BOARD_DATA_UINT16) { + OTHER_BOARD_DATA_UINT16[data_id][0] = (rx_data[0] << 8) | rx_data[1]; + OTHER_BOARD_DATA_UINT16[data_id][1] = (rx_data[2] << 8) | rx_data[3]; + OTHER_BOARD_DATA_UINT16[data_id][2] = (rx_data[4] << 8) | rx_data[5]; + OTHER_BOARD_DATA_UINT16[data_id][3] = (rx_data[6] << 8) | rx_data[7]; + } else if (data_type == BOARD_DATA_ANY) { + memcpy(OTHER_BOARD_DATA_ANY[data_id], rx_data, 8); + } } /** @@ -268,7 +293,7 @@ const DjiMotorMeasure_t * GetDjiMotorMeasurePoint(uint8_t can, uint8_t i) static void GetDjiFdbData(Motor_s * p_motor, const DjiMotorMeasure_t * p_dji_motor_measure) { p_motor->fdb.vel = p_dji_motor_measure->speed_rpm * RPM_TO_OMEGA * p_motor->reduction_ratio * - p_motor->direction; + p_motor->direction; p_motor->fdb.pos = p_dji_motor_measure->ecd * 2 * M_PI / 8192 - M_PI; p_motor->fdb.temp = p_dji_motor_measure->temperate; p_motor->fdb.curr = p_dji_motor_measure->given_current; diff --git a/application/robot_param.h b/application/robot_param.h index 882bcb1..fcd8a6e 100644 --- a/application/robot_param.h +++ b/application/robot_param.h @@ -29,5 +29,6 @@ #define __TUNING 0 // 调参模式 #define __MUSIC_ON 0 // 开启音乐 #define __TUNING_MODE TUNING_NONE // 调参模式 +#define __SELF_BOARD_ID 0 // 本板ID #endif /* ROBOT_PARAM_H */ diff --git a/bsp/boards/bsp_can.h b/bsp/boards/bsp_can.h index 13b29f0..0fa03ce 100644 --- a/bsp/boards/bsp_can.h +++ b/bsp/boards/bsp_can.h @@ -3,6 +3,11 @@ #include "struct_typedef.h" #include "stm32f4xx_hal.h" +// clang-format off +#define BOARD_DATA_ANY ((uint16_t)0xA00) +#define BOARD_DATA_UINT16 ((uint16_t)0xB00) +// clang-format on + typedef CAN_HandleTypeDef hcan_t; typedef struct __CanCtrlData -- Gitee From 788ca0817cf7d819beb3215940e690451f113b8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=AF=E5=B0=8F=E4=BC=81=E9=B9=85=E5=91=80?= <1357482552@qq.com> Date: Mon, 27 May 2024 20:55:27 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E2=9C=A8=20feat(can=20receive):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9D=BF=E9=97=B4=E9=80=9A=E4=BF=A1=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 仅uint16类型 --- application/robot_cmd/CAN_receive.c | 17 ++++++++++++++--- application/robot_cmd/CAN_receive.h | 2 ++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/application/robot_cmd/CAN_receive.c b/application/robot_cmd/CAN_receive.c index 9285ccf..df8d5f7 100644 --- a/application/robot_cmd/CAN_receive.c +++ b/application/robot_cmd/CAN_receive.c @@ -136,7 +136,7 @@ static void DecodeStdIdData(hcan_t * CAN, CAN_RxHeaderTypeDef * rx_header, uint8 DjiFdbData(&CAN2_DJI_MEASURE[i], rx_data); } return; - } + } case DM_M1_ID: case DM_M2_ID: case DM_M3_ID: @@ -153,7 +153,7 @@ static void DecodeStdIdData(hcan_t * CAN, CAN_RxHeaderTypeDef * rx_header, uint8 DmFdbData(&CAN2_DM_MEASURE[i], rx_data); } return; - } + } case LK_M1_ID: case LK_M2_ID: case LK_M3_ID: @@ -168,7 +168,7 @@ static void DecodeStdIdData(hcan_t * CAN, CAN_RxHeaderTypeDef * rx_header, uint8 LkFdbData(&CAN2_LK_MEASURE[i], rx_data); } return; - } + } default: { break; } @@ -416,3 +416,14 @@ void GetMotorMeasure(Motor_s * p_motor) break; } } + +/** + * @brief 获取板间通信数据 + * @param data_id 数据ID + * @param data_offset 数据位置偏移 + * @return none + */ +uint16_t GetOtherBoardDataUint16(uint8_t data_id, uint8_t data_offset) +{ + return OTHER_BOARD_DATA_UINT16[data_id][data_offset]; +} diff --git a/application/robot_cmd/CAN_receive.h b/application/robot_cmd/CAN_receive.h index 5c4d20d..95c326e 100644 --- a/application/robot_cmd/CAN_receive.h +++ b/application/robot_cmd/CAN_receive.h @@ -71,4 +71,6 @@ extern CybergearModeState_e GetCybergearModeState(Motor_s * p_motor); extern void GetMotorMeasure(Motor_s * p_motor); +extern uint16_t GetOtherBoardDataUint16(uint8_t data_id, uint8_t data_offset); + #endif -- Gitee From 7d19e19d1556f9eceba7075b11cc30debd0175f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=AF=E5=B0=8F=E4=BC=81=E9=B9=85=E5=91=80?= <1357482552@qq.com> Date: Mon, 27 May 2024 21:16:52 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=9D=BF=E9=97=B4?= =?UTF-8?q?=E9=80=9A=E4=BF=A1=E5=8F=AF=E4=BB=A5=E6=AD=A3=E5=B8=B8=E4=BD=BF?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/assist/usb_task.c | 41 ++++++++++--------- application/assist/usb_task.h | 2 +- .../mechanical_arm_penguin_mini.c | 8 ++++ application/robot_cmd/CAN_receive.c | 6 +-- application/robot_param.h | 2 +- bsp/boards/bsp_can.h | 4 +- 6 files changed, 35 insertions(+), 28 deletions(-) diff --git a/application/assist/usb_task.c b/application/assist/usb_task.c index d2ea69d..1df1a32 100644 --- a/application/assist/usb_task.c +++ b/application/assist/usb_task.c @@ -379,26 +379,27 @@ static void usb_send_outputPC(uint8_t t) OutputPCData.header = SET_OUTPUT_PC_HEDER; OutputPCData.length = sizeof(OutputPCData_s); - char_to_uint(OutputPCData.packets[0].name, "mode_0"); - char_to_uint(OutputPCData.packets[1].name, "mode_1"); - char_to_uint(OutputPCData.packets[2].name, "mode_2"); - char_to_uint(OutputPCData.packets[3].name, "p_0"); - char_to_uint(OutputPCData.packets[4].name, "p_1"); - char_to_uint(OutputPCData.packets[5].name, "p_2"); - char_to_uint(OutputPCData.packets[6].name, "tor_0"); - char_to_uint(OutputPCData.packets[7].name, "tor_1"); - char_to_uint(OutputPCData.packets[8].name, "tor_2"); - char_to_uint(OutputPCData.packets[9].name, "mode"); - char_to_uint(OutputPCData.packets[10].name, "zeroseted"); - char_to_uint(OutputPCData.packets[11].name, "fdbpos_0"); - char_to_uint(OutputPCData.packets[12].name, "fdbpos_1"); - char_to_uint(OutputPCData.packets[13].name, "fdbpos_2"); - char_to_uint(OutputPCData.packets[14].name, "refpos_0"); - char_to_uint(OutputPCData.packets[15].name, "refpos_1"); - char_to_uint(OutputPCData.packets[16].name, "refpos_2"); - // char_to_uint(OutputPCData.packets[17].name, "zAccel"); - // char_to_uint(OutputPCData.packets[18].name, "o_r"); - // char_to_uint(OutputPCData.packets[19].name, "o_p"); + // char_to_uint(OutputPCData.packets[0].name, "mode_0"); + // char_to_uint(OutputPCData.packets[1].name, "mode_1"); + // char_to_uint(OutputPCData.packets[2].name, "mode_2"); + // char_to_uint(OutputPCData.packets[3].name, "p_0"); + // char_to_uint(OutputPCData.packets[4].name, "p_1"); + // char_to_uint(OutputPCData.packets[5].name, "p_2"); + // char_to_uint(OutputPCData.packets[6].name, "tor_0"); + // char_to_uint(OutputPCData.packets[7].name, "tor_1"); + // char_to_uint(OutputPCData.packets[8].name, "tor_2"); + // char_to_uint(OutputPCData.packets[9].name, "mode"); + // char_to_uint(OutputPCData.packets[10].name, "zeroseted"); + // char_to_uint(OutputPCData.packets[11].name, "fdbpos_0"); + // char_to_uint(OutputPCData.packets[12].name, "fdbpos_1"); + // char_to_uint(OutputPCData.packets[13].name, "fdbpos_2"); + // char_to_uint(OutputPCData.packets[14].name, "refpos_0"); + // char_to_uint(OutputPCData.packets[15].name, "refpos_1"); + // char_to_uint(OutputPCData.packets[16].name, "refpos_2"); + char_to_uint(OutputPCData.packets[17].name, "data1"); + char_to_uint(OutputPCData.packets[18].name, "data2"); + char_to_uint(OutputPCData.packets[19].name, "data3"); + char_to_uint(OutputPCData.packets[20].name, "data4"); append_CRC16_check_sum((uint8_t *)&OutputPCData, sizeof(OutputPCData_s)); memcpy(usb_tx_buf, &OutputPCData, sizeof(OutputPCData_s)); diff --git a/application/assist/usb_task.h b/application/assist/usb_task.h index 5c777db..2ff6c94 100644 --- a/application/assist/usb_task.h +++ b/application/assist/usb_task.h @@ -85,7 +85,7 @@ #include #define PRESET_SELF_COLOR 1 -#define PC_PACKET_NUM 20 +#define PC_PACKET_NUM 22 typedef struct { uint8_t vision; diff --git a/application/mechanical_arm/mechanical_arm_penguin_mini.c b/application/mechanical_arm/mechanical_arm_penguin_mini.c index c22213b..7dd6ba7 100644 --- a/application/mechanical_arm/mechanical_arm_penguin_mini.c +++ b/application/mechanical_arm/mechanical_arm_penguin_mini.c @@ -294,6 +294,11 @@ void MechanicalArmObserver(void) OutputPCData.packets[14].data = MECHANICAL_ARM.ref.pos[0]; OutputPCData.packets[15].data = MECHANICAL_ARM.ref.pos[1]; OutputPCData.packets[16].data = MECHANICAL_ARM.ref.pos[2]; + + OutputPCData.packets[17].data = GetOtherBoardDataUint16(1, 0); + OutputPCData.packets[18].data = GetOtherBoardDataUint16(1, 1); + OutputPCData.packets[19].data = GetOtherBoardDataUint16(1, 2); + OutputPCData.packets[20].data = GetOtherBoardDataUint16(1, 3); } /*-------------------- Reference --------------------*/ @@ -467,6 +472,9 @@ void MechanicalArmSendCmd(void) ArmZeroForceSendCmd(); } } + + CanSendUint16DataToBoard( + 2, 1, 2, 200, 450, GenerateSinWave(200, 200, 3), GenerateSinWave(450, 450, 3)); } static void ArmEnable(void) diff --git a/application/robot_cmd/CAN_receive.c b/application/robot_cmd/CAN_receive.c index df8d5f7..b2cd219 100644 --- a/application/robot_cmd/CAN_receive.c +++ b/application/robot_cmd/CAN_receive.c @@ -357,12 +357,10 @@ static void GetDmFdbData(Motor_s * motor, const DmMeasure_s * dm_measure) */ static void GetLkFdbData(Motor_s * motor, const LkMeasure_s * lk_measure) { - // clang-format off - motor->fdb.pos = uint_to_float(lk_measure->encoder, -M_PI, M_PI, 16); - motor->fdb.vel = lk_measure->speed * DEGREE_TO_RAD; + motor->fdb.pos = uint_to_float(lk_measure->encoder, -M_PI, M_PI, 16); + motor->fdb.vel = lk_measure->speed * DEGREE_TO_RAD; motor->fdb.curr = lk_measure->iq * MF_CONTROL_TO_CURRENT; motor->fdb.temp = lk_measure->temprature; - // clang-format on uint32_t now = HAL_GetTick(); if (now - lk_measure->last_fdb_time > MOTOR_STABLE_RUNNING_TIME) { diff --git a/application/robot_param.h b/application/robot_param.h index fcd8a6e..325708b 100644 --- a/application/robot_param.h +++ b/application/robot_param.h @@ -29,6 +29,6 @@ #define __TUNING 0 // 调参模式 #define __MUSIC_ON 0 // 开启音乐 #define __TUNING_MODE TUNING_NONE // 调参模式 -#define __SELF_BOARD_ID 0 // 本板ID +#define __SELF_BOARD_ID 2 // 本板ID #endif /* ROBOT_PARAM_H */ diff --git a/bsp/boards/bsp_can.h b/bsp/boards/bsp_can.h index 0fa03ce..52bd538 100644 --- a/bsp/boards/bsp_can.h +++ b/bsp/boards/bsp_can.h @@ -4,8 +4,8 @@ #include "stm32f4xx_hal.h" // clang-format off -#define BOARD_DATA_ANY ((uint16_t)0xA00) -#define BOARD_DATA_UINT16 ((uint16_t)0xB00) +#define BOARD_DATA_ANY ((uint16_t)0x500) +#define BOARD_DATA_UINT16 ((uint16_t)0x600) // clang-format on typedef CAN_HandleTypeDef hcan_t; -- Gitee From 8f97790a508c32d361f01992a5dca780d17399e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=AF=E5=B0=8F=E4=BC=81=E9=B9=85=E5=91=80?= <1357482552@qq.com> Date: Mon, 27 May 2024 21:18:19 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E5=8F=91=E9=80=81=E4=BB=A3=E7=A0=81=E5=B9=B6=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=B5=8B=E8=AF=95=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/mechanical_arm/mechanical_arm_penguin_mini.c | 3 --- application/robot_param.h | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/application/mechanical_arm/mechanical_arm_penguin_mini.c b/application/mechanical_arm/mechanical_arm_penguin_mini.c index 7dd6ba7..73a6327 100644 --- a/application/mechanical_arm/mechanical_arm_penguin_mini.c +++ b/application/mechanical_arm/mechanical_arm_penguin_mini.c @@ -472,9 +472,6 @@ void MechanicalArmSendCmd(void) ArmZeroForceSendCmd(); } } - - CanSendUint16DataToBoard( - 2, 1, 2, 200, 450, GenerateSinWave(200, 200, 3), GenerateSinWave(450, 450, 3)); } static void ArmEnable(void) diff --git a/application/robot_param.h b/application/robot_param.h index 325708b..f4c9fa9 100644 --- a/application/robot_param.h +++ b/application/robot_param.h @@ -25,6 +25,7 @@ #include "robot_param_penguin_mini_arm.h" // 选择机器人的各种类型 +#define __TEST 0 // 测试模式 #define __DEBUG 0 // 调试模式 #define __TUNING 0 // 调参模式 #define __MUSIC_ON 0 // 开启音乐 -- Gitee From 7539b601bf50d1838c05dd9bc9ae815ee8bf1866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=AF=E5=B0=8F=E4=BC=81=E9=B9=85=E5=91=80?= <1357482552@qq.com> Date: Mon, 27 May 2024 21:21:17 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/robot_cmd/CAN_receive.c | 4 +++- application/robot_cmd/CAN_receive.h | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/application/robot_cmd/CAN_receive.c b/application/robot_cmd/CAN_receive.c index b2cd219..dc11a1b 100644 --- a/application/robot_cmd/CAN_receive.c +++ b/application/robot_cmd/CAN_receive.c @@ -11,10 +11,12 @@ * V2.0.0 Mar-27-2024 Penguin 1. 添加CAN发送函数和新的电机控制函数,解码中将CAN1 CAN2分开。 * V2.1.0 Mar-20-2024 Penguin 1. 添加DM电机的适配 * V2.2.0 May-22-2024 Penguin 1. 添加LK电机的适配 + * V2.3.0 May-22-2024 Penguin 1. 添加板间通信数据解码 * @verbatim ============================================================================== - + dm电机设置: + 为了配合本框架,请在使用上位机进行设置时,将dm电机的master id 设置为 slave id + 0x50 ============================================================================== @endverbatim ****************************(C) COPYRIGHT 2024 Polarbear**************************** diff --git a/application/robot_cmd/CAN_receive.h b/application/robot_cmd/CAN_receive.h index 95c326e..cb5a52e 100644 --- a/application/robot_cmd/CAN_receive.h +++ b/application/robot_cmd/CAN_receive.h @@ -11,10 +11,12 @@ * V2.0.0 Mar-27-2024 Penguin 1. 添加CAN发送函数和新的电机控制函数,解码中将CAN1 CAN2分开。 * V2.1.0 Mar-20-2024 Penguin 1. 添加DM电机的适配 * V2.2.0 May-22-2024 Penguin 1. 添加LK电机的适配 + * V2.3.0 May-22-2024 Penguin 1. 添加板间通信数据解码 * @verbatim ============================================================================== - + dm电机设置: + 为了配合本框架,请在使用上位机进行设置时,将dm电机的master id 设置为 slave id + 0x50 ============================================================================== @endverbatim ****************************(C) COPYRIGHT 2024 Polarbear**************************** -- Gitee From d1257337b2c0b8eb051aa6cd5e3ff4713a5cae5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=AF=E5=B0=8F=E4=BC=81=E9=B9=85=E5=91=80?= <1357482552@qq.com> Date: Mon, 27 May 2024 21:28:59 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E6=B7=BB=E5=8A=A0develop=5Ftask=E5=88=B0fr?= =?UTF-8?q?eertos=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 4 +++- Src/freertos.c | 10 ++++++++++ application/assist/develop_task.c | 15 +++++++++++++++ application/assist/develop_task.h | 4 ++++ application/robot_param.h | 2 +- 5 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 application/assist/develop_task.c create mode 100644 application/assist/develop_task.h diff --git a/.vscode/settings.json b/.vscode/settings.json index ee7f37f..6737570 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -80,7 +80,9 @@ "gimbal_yaw_pitch_direct.h": "c", "stdint.h": "c", "ahrs.h": "c", - "robot_param_penguin_mini_arm.h": "c" + "robot_param_penguin_mini_arm.h": "c", + "chassis_steering.h": "c", + "develop_task.h": "c" }, "C_Cpp.codeAnalysis.clangTidy.enabled": true, "[cpp]": { diff --git a/Src/freertos.c b/Src/freertos.c index 91b8a41..8281764 100644 --- a/Src/freertos.c +++ b/Src/freertos.c @@ -42,6 +42,7 @@ #include "shoot_task.h" #include "mechanical_arm_task.h" #include "music_task.h" +#include "develop_task.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -71,6 +72,10 @@ osThreadId mechanical_armTaskHandle; osThreadId musicTaskHandle; #endif +#if (__DEVELOP) +osThreadId developTaskHandle; +#endif + osThreadId imuTaskHandle; osThreadId led_RGB_flow_handle; @@ -210,6 +215,11 @@ void MX_FREERTOS_Init(void) { musicTaskHandle = osThreadCreate(osThread(musicTask), NULL); #endif +#if (__DEVELOP) + osThreadDef(developTask, develop_task, osPriorityNormal, 0, 256); + developTaskHandle = osThreadCreate(osThread(developTask), NULL); +#endif + osThreadDef(imuTask, IMU_task, osPriorityRealtime, 0, 1024); imuTaskHandle = osThreadCreate(osThread(imuTask), NULL); diff --git a/application/assist/develop_task.c b/application/assist/develop_task.c new file mode 100644 index 0000000..a8aa5a1 --- /dev/null +++ b/application/assist/develop_task.c @@ -0,0 +1,15 @@ +// 开发新功能时可以使用本任务进行功能测试 + +#include "develop_task.h" + +#include "cmsis_os.h" +void develop_task(void const * pvParameters) +{ + // 空闲一段时间 + vTaskDelay(10); + + while (1) { + // code here + vTaskDelay(2); + } +} diff --git a/application/assist/develop_task.h b/application/assist/develop_task.h new file mode 100644 index 0000000..0a0ddac --- /dev/null +++ b/application/assist/develop_task.h @@ -0,0 +1,4 @@ +#ifndef __DEVELOP_TASK_H +#define __DEVELOP_TASK_H +extern void develop_task(void const * pvParameters); +#endif diff --git a/application/robot_param.h b/application/robot_param.h index f4c9fa9..91b74c2 100644 --- a/application/robot_param.h +++ b/application/robot_param.h @@ -25,7 +25,7 @@ #include "robot_param_penguin_mini_arm.h" // 选择机器人的各种类型 -#define __TEST 0 // 测试模式 +#define __DEVELOP 0 // 开发模式 #define __DEBUG 0 // 调试模式 #define __TUNING 0 // 调参模式 #define __MUSIC_ON 0 // 开启音乐 -- Gitee