From f050cec6aa3def90b03c2a7ef74e9f43de190d32 Mon Sep 17 00:00:00 2001 From: sladro Date: Fri, 12 Sep 2025 22:53:23 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=B6=88=E9=99=A4=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E9=87=8D=E5=A4=8D=EF=BC=8C=E6=8F=90=E5=8D=87=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=95=B4=E6=B4=81=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除path_executor.py中未使用的重复方法_move_to_configuration_reset - 删除空文件rrt_star.py,减少项目混乱度 - 验证KDL和PyBullet关节顺序转换在全项目中使用一致 - 更新CLAUDE.md文档记录修复内容 符合DRY原则,提高代码可维护性 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- CLAUDE.md | 23 ++++++++++++++++++++++- src/planning/path_executor.py | 32 -------------------------------- src/planning/rrt_star.py | 0 3 files changed, 22 insertions(+), 33 deletions(-) delete mode 100644 src/planning/rrt_star.py diff --git a/CLAUDE.md b/CLAUDE.md index 8cdd885..e7671d4 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -176,4 +176,25 @@ wall_position = [2.0, 0.0, 1.0] # 错误! - 修复 `cleanup()` 函数调用 `_clear_wall()` - 使用 `_wall_part_ids` 列表记录所有墙体部件ID -**修复文件**:`src/simulation/environment.py` \ No newline at end of file +**修复文件**:`src/simulation/environment.py` + +### 代码重复和一致性问题(2025-09-12)✅ 已解决 +**现象**: +1. `path_executor.py` 中存在未使用的重复方法 `_move_to_configuration_reset()` +2. 空文件 `rrt_star.py` 增加项目混乱度 +3. 需要验证KDL和PyBullet关节顺序转换的一致性 + +**根本原因**: +1. **代码重复**:两个功能相同的路径执行方法,违反DRY原则 +2. **遗留文件**:空的 `rrt_star.py` 文件未清理 +3. **架构复杂性**:需要确保关节顺序映射在所有地方正确使用 + +**解决方案**: +- 删除未使用的 `_move_to_configuration_reset()` 方法 +- 删除空的 `rrt_star.py` 文件 +- 验证确认关节顺序转换机制在全项目中使用一致 + +**修复文件**: +- `src/planning/path_executor.py` - 删除重复方法 +- `src/planning/rrt_star.py` - 删除空文件 +- 全项目关节顺序转换验证通过 \ No newline at end of file diff --git a/src/planning/path_executor.py b/src/planning/path_executor.py index 9ef550d..fabd797 100644 --- a/src/planning/path_executor.py +++ b/src/planning/path_executor.py @@ -157,35 +157,3 @@ class PathExecutor: return True - def _move_to_configuration_reset(self, target_config: List[float]) -> bool: - - current_config = self.arm_controller.get_current_joint_positions() - - distance = np.linalg.norm(np.array(target_config) - np.array(current_config)) - if distance < self.position_tolerance: - return True - - move_time = distance / self.velocity_scaling - num_steps = int(move_time / self.timestep) + 1 - num_steps = max(2, num_steps) - - robot_id = self.arm_controller.robot_loader.get_robot_id() - joint_indices = self.arm_controller.robot_loader.joint_indices - cid = self.arm_controller.physics_client - - for step in range(1, num_steps + 1): - ratio = step / num_steps - interpolated = ( - np.array(current_config) * (1 - ratio) + np.array(target_config) * ratio - ).tolist() - # 将KDL顺序转换为PyBullet顺序 - q_pb = self.arm_controller._to_pb_order(interpolated) - for j, jid in enumerate(joint_indices): - p.resetJointState(robot_id, jid, float(q_pb[j]), physicsClientId=cid) - time.sleep(self.timestep) - - final_config = self.arm_controller.get_current_joint_positions() - final_distance = np.linalg.norm(np.array(target_config) - np.array(final_config)) - if final_distance > self.position_tolerance: - raise RuntimeError(f"Failed to reach target, error: {final_distance}") - return True diff --git a/src/planning/rrt_star.py b/src/planning/rrt_star.py deleted file mode 100644 index e69de29..0000000