From 09602c76cd001b9f12456e6f174e1cc5a666e801 Mon Sep 17 00:00:00 2001 From: Robofish <1683502971@qq.com> Date: Mon, 22 Sep 2025 14:49:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 10244 -> 6148 bytes app/code_generate_interface.py | 3 ++- app/tools/update_cmake_sources.py | 30 +++++++++++++++++++++++++++++ assets/.DS_Store | Bin 6148 -> 6148 bytes assets/User_code/device/motor_rm.c | 9 ++++++++- 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/.DS_Store b/.DS_Store index 3f40116982974d510bfc26a9b72c0678aa6582c3..ded3be5c30a6c5d5fb67871a9eb9db6ce2858c20 100644 GIT binary patch delta 145 zcmZn(XfcprU|?W$DortDU=RQ@Ie-{Mvv5r;6q~50$jGxXU^g=(&t@KhV~iq3mS#E% z#+HV)Itta6Mg}?xCdOuyF9;YXIZi5VvV(NWWLcS8i`h9i1et+G0f7KF gkZ=W=y0P#(^JIP%Pmmo9Oc47(PGHy^&ohS^00b`^4*&oF literal 10244 zcmeHMO>o;p6n>keiJdf!^4FFYW?XV%rlurLXp&)|u9FOyzl1mwl1WKg1T7zLne3w zWZIW?Pof2dd8Uw_Df71&%-=gO&m8yDzJA@4o;fiwGWzjHX8sO^`CAW`5bDIzo{Y{B z0ucg-5x9h=Rw_`Hs#znre`il1xqjXkMVR?o#Vx1m@AAJWRt?>8hljsoEv;>*+B;$$ zv98#S+`6@ua|>?G$rS7rezjm(MzK*Z6c=@EE3XVpS*BaiP0bbtdP#%I>YKV*vbHi- z%`7>>Hs{@l#bfcja(;JrWHgmbj7+5Vl8N2P)NnE}c6DrTFCH5ldgi(L{Dx66t@k`P znNJneExG;vfzO*c+cYe*j25ol4kR4>G;+z2@VGDG5z>7`Pzm`YVbe-QAR|W!P@yZK zC=pr#JU;)=qvYJ~?&L@^F`63TK{7EmiXfRBmxAODCXRA!knkY#UDnl2Kjhgr4QGB( zlt$3UJG)MIpXpJ0`}%tadIty3o;yGI*oBK1@=AZPpl+0H9?VmgVc8j@rmd81y_BmK zRNX8ux!Sgy({F2erB70w*Ge}Jnih7d&>1*r5Z%3KYnmzgn_XLTG_Y`u2~py6KObG<+q$g&2}IU*(@y=Y`b8Vwam^9qfpe0Su@D@t&vV;xMPj15a>TH*;HvKJR`9jeJ3zV zmt=vZ2}n+rtoYLn(p!JXDht9zM1a%{?ibmZtw!6jhnyr?aO^n7GVwy-glfU&&}{LV zlKq(dUa0<6P(27cu4U%9vA#`yx1_HZ5VY? oP*3v;WZjdfp`6U00nz>+kBxs{2riIATd0%X0!91(fA5pt?~#}>(f|Me diff --git a/app/code_generate_interface.py b/app/code_generate_interface.py index 8154127..ff87169 100644 --- a/app/code_generate_interface.py +++ b/app/code_generate_interface.py @@ -163,7 +163,7 @@ class CodeGenerateInterface(QWidget): def on_cmake_config_btn_clicked(self): """配置cmake,自动更新CMakeLists.txt中的源文件列表""" try: - from app.tools.update_cmake_sources import find_user_c_files, update_cmake_sources + from app.tools.update_cmake_sources import find_user_c_files, update_cmake_sources,update_cmake_includes from pathlib import Path # 构建User目录和CMakeLists.txt路径 @@ -204,6 +204,7 @@ class CodeGenerateInterface(QWidget): # 更新CMakeLists.txt success = update_cmake_sources(cmake_file, c_files) + success = update_cmake_includes(cmake_file, user_dir) if success: InfoBar.success( diff --git a/app/tools/update_cmake_sources.py b/app/tools/update_cmake_sources.py index ce4557b..21f0f56 100644 --- a/app/tools/update_cmake_sources.py +++ b/app/tools/update_cmake_sources.py @@ -70,6 +70,36 @@ def update_cmake_sources(cmake_file, c_files): else: print("❌ 错误: 在CMakeLists.txt中找不到target_sources部分") return False + +def update_cmake_includes(cmake_file, user_dir): + """确保CMakeLists.txt中的include路径包含User""" + if not os.path.exists(cmake_file): + print(f"错误: CMakeLists.txt文件不存在: {cmake_file}") + return False + + with open(cmake_file, 'r', encoding='utf-8') as f: + content = f.read() + + # 构建新的include部分 + include_section = ( + "# Add include paths\n" + "target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE\n" + " # Add user defined include paths\n" + " User\n" + ")" + ) + + # 正则匹配并替换include部分 + pattern = r'# Add include paths\s*\ntarget_include_directories\(\$\{CMAKE_PROJECT_NAME\}\s+PRIVATE\s*\n.*?\)' + if re.search(pattern, content, re.DOTALL): + new_content = re.sub(pattern, include_section, content, flags=re.DOTALL) + with open(cmake_file, 'w', encoding='utf-8') as f: + f.write(new_content) + print("✅ 成功更新CMakeLists.txt中的include路径") + return True + else: + print("❌ 错误: 在CMakeLists.txt中找不到target_include_directories部分") + return False def main(): """主函数""" diff --git a/assets/.DS_Store b/assets/.DS_Store index f40f665f4a74be6ff485f427fcce0249d491cc1a..26268dd53cdc2e6422a3f194ae8d6b8b2828a808 100644 GIT binary patch delta 163 zcmZoMXfc=|#>B!ku~2NHo+2ar#(>?7ix)66F|tqQVbT_5VaQ>~XGmwrPbx1iNXp4i zVqjp{F?k15p}ItMwUMQnj)JkJVXclrwWX1Pj)IA?S#2#Rhp4i?bx?eEPHtX)*JOWY zdC6{|F1Sf$!9{sF`FZI;F~-d%Os|B)qu~2NHo+2ab#(>?7jI5J+ShP3Gv%X;3*zkgBGdl-A2T;joL5}at Vlles)IT(O|k%56_bA-qmW&l(%5Cs4L diff --git a/assets/User_code/device/motor_rm.c b/assets/User_code/device/motor_rm.c index cd6e633..e38073a 100644 --- a/assets/User_code/device/motor_rm.c +++ b/assets/User_code/device/motor_rm.c @@ -140,7 +140,13 @@ static void Motor_RM_Decode(MOTOR_RM_t *motor, BSP_CAN_Message_t *msg) { motor->feedback.torque_current = torque_current; } if (motor->motor.reverse) { - motor->feedback.rotor_abs_angle = M_2_PI - motor->feedback.rotor_abs_angle; + while (motor->feedback.rotor_abs_angle < 0) { + motor->feedback.rotor_abs_angle += M_2PI; + } + while (motor->feedback.rotor_abs_angle >= M_2PI) { + motor->feedback.rotor_abs_angle -= M_2PI; + } + motor->feedback.rotor_abs_angle = M_2PI - motor->feedback.rotor_abs_angle; motor->feedback.rotor_speed = -motor->feedback.rotor_speed; motor->feedback.torque_current = -motor->feedback.torque_current; } @@ -197,6 +203,7 @@ int8_t MOTOR_RM_Update(MOTOR_RM_Param_t *param) { motor->motor.header.online = true; motor->motor.header.last_online_time = BSP_TIME_Get(); Motor_RM_Decode(motor, &rx_msg); + motor->motor.feedback = motor->feedback; return DEVICE_OK; } }