mirror of
https://github.com/goldenfishs/MRobot.git
synced 2025-11-02 04:23:10 +08:00
更新代码
This commit is contained in:
parent
d16427f7d4
commit
09602c76cd
@ -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(
|
||||
|
||||
@ -71,6 +71,36 @@ def update_cmake_sources(cmake_file, c_files):
|
||||
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():
|
||||
"""主函数"""
|
||||
script_dir = Path(__file__).parent
|
||||
|
||||
BIN
assets/.DS_Store
vendored
BIN
assets/.DS_Store
vendored
Binary file not shown.
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user