refactor: 消除代码重复,提升项目整洁度

- 删除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 <noreply@anthropic.com>
This commit is contained in:
sladro 2025-09-12 22:53:23 +08:00
parent a9db87d81d
commit f050cec6aa
3 changed files with 22 additions and 33 deletions

View File

@ -176,4 +176,25 @@ wall_position = [2.0, 0.0, 1.0] # 错误!
- 修复 `cleanup()` 函数调用 `_clear_wall()`
- 使用 `_wall_part_ids` 列表记录所有墙体部件ID
**修复文件**`src/simulation/environment.py`
**修复文件**`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` - 删除空文件
- 全项目关节顺序转换验证通过

View File

@ -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