Skip to content

Commit 29615d6

Browse files
Apply code simplification improvements
Simplifications made by code-simplifier agent: 1. sensor_feedback.py: - Added missing module-level logger definition - Fixes logger.warning() usage at line 291 2. robot_controller.py: - Removed unused variable kp = 100.0 in set_joint_velocities() - Updated comment from "PD controller" to "P controller on velocity" - More accurately reflects the actual implementation 3. multi_robot_coordinator.py: - Fixed status comparison to use RobotStatus.IDLE enum - Previously used string literals ["idle", "ready"] - Fixed return type annotation: str | None → TaskStatus | None 4. rl_integration.py: - Simplified _create_reward_function() control flow - Removed unreachable else clause - All TaskType enum values are explicitly handled All changes preserve functionality while improving: - Type safety (enum usage) - Code clarity (removed dead code) - Bug fixes (missing logger) - Accuracy (correct type annotations and comments) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 4492078 commit 29615d6

4 files changed

Lines changed: 8 additions & 10 deletions

File tree

src/mujoco_mcp/multi_robot_coordinator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ def _process_tasks(self):
374374
available_robots = [
375375
robot_id
376376
for robot_id, state in self.robot_states.items()
377-
if state.status in ["idle", "ready"]
377+
if state.status == RobotStatus.IDLE
378378
]
379379

380380
# Allocate new tasks
@@ -548,7 +548,7 @@ def formation_control(
548548
self.task_allocator.add_task(task)
549549
return task.task_id
550550

551-
def get_task_status(self, task_id: str) -> str | None:
551+
def get_task_status(self, task_id: str) -> TaskStatus | None:
552552
"""Get status of a task"""
553553
with self.task_lock:
554554
if task_id in self.task_allocator.active_tasks:

src/mujoco_mcp/rl_integration.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,13 +321,10 @@ def _create_reward_function(self) -> TaskReward:
321321
if self.config.task_type == TaskType.REACHING:
322322
target = np.array([0.5, 0.0, 0.5]) # Default target position
323323
return ReachingTaskReward(target)
324-
elif self.config.task_type == TaskType.BALANCING:
324+
if self.config.task_type == TaskType.BALANCING:
325325
return BalancingTaskReward()
326-
elif self.config.task_type == TaskType.WALKING:
327-
return WalkingTaskReward()
328-
else:
329-
# Default reward function
330-
return ReachingTaskReward(np.array([0.0, 0.0, 1.0]))
326+
# TaskType.WALKING
327+
return WalkingTaskReward()
331328

332329
def _create_model_xml(self) -> str:
333330
"""Create model XML for the RL task"""

src/mujoco_mcp/robot_controller.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ def set_joint_velocities(self, robot_id: str, velocities: List[float]) -> Dict[s
171171
controller["target_velocities"] = np.array(velocities)
172172
controller["control_mode"] = "velocity"
173173

174-
# Apply velocity control (simplified PD controller)
175-
kp = 100.0 # Position gain
174+
# Apply velocity control (simplified P controller on velocity)
176175
kv = 10.0 # Velocity gain
177176

178177
for i in range(model.nu):

src/mujoco_mcp/sensor_feedback.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from abc import ABC, abstractmethod
1515
import logging
1616

17+
logger = logging.getLogger(__name__)
18+
1719
# Domain-specific types for type safety
1820
Quality = NewType("Quality", float) # Sensor quality (0-1 range)
1921
Timestamp = NewType("Timestamp", float) # Time in seconds since epoch

0 commit comments

Comments
 (0)