diff --git a/.DS_Store b/.DS_Store index 3f40116..ded3be5 100644 Binary files a/.DS_Store and b/.DS_Store differ 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 f40f665..26268dd 100644 Binary files a/assets/.DS_Store and b/assets/.DS_Store differ 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; } }