Skip to content

Conversation

@jca0
Copy link

@jca0 jca0 commented Jan 13, 2026

sim bridge to simulate xarm7 in mujoco
created xarm7 sim driver, general sim bridge, xarm specific sim bridge

command to test: python3 -m dimos.simulation.sim_blueprints

todos: add sim support for piper arm, mujoco viewer doesn't work on mac

@jca0 jca0 requested a review from a team January 13, 2026 19:35
@greptile-apps
Copy link

greptile-apps bot commented Jan 13, 2026

Greptile Summary

Implements MuJoCo simulation bridge for xArm7 manipulator, enabling unified driver code to work with both hardware and simulation. The implementation follows a clean architecture with a base bridge class and xArm-specific extensions that mimic the UFACTORY SDK interface.

Key changes:

  • Added MujocoSimBridgeBase providing threading infrastructure, MuJoCo model loading, simulation loop at configurable frequency, and viewer integration
  • Implemented XArmSimBridge that mimics UFACTORY SDK with position/velocity control modes, periodic state reporting callbacks, and best-effort SDK method implementations via __getattr__
  • Created XArmSimDriver and XArmSimSDKWrapper integrating simulation with existing component-based driver architecture
  • Added simulation blueprint xarm7_trajectory_sim with LCM transport configuration
  • Enhanced xArm state query component with additional RPC methods for servo angles and FT sensor data
  • Cleaned up deprecated agent framework code (5000+ lines removed)
  • Added robot_descriptions dependency for loading robot models from Menagerie
  • Included test script for subscribing to joint states

Confidence Score: 4/5

  • This PR is safe to merge with one minor syntax fix needed
  • The simulation bridge implementation is well-structured with proper threading, locking, and error handling. The architecture cleanly separates concerns between base and derived classes. One syntax error was found (unused expression on line 103 of xarm_sim_bridge.py) that should be fixed before merge. The deprecated code cleanup is straightforward deletion with no logical issues.
  • dimos/simulation/manipulators/mujoco_sim/xarm_sim_bridge.py needs the syntax fix on line 103

Important Files Changed

Filename Overview
dimos/simulation/manipulators/mujoco_sim/xarm_sim_bridge.py Added XArm simulation bridge mimicking UFACTORY SDK; has one unused variable calculation on line 103
dimos/simulation/manipulators/mujoco_sim/bridge_base.py Added base class for MuJoCo simulation bridges with threading, state management, and viewer integration
dimos/simulation/manipulators/mujoco_sim/xarm_sim_driver.py Added MuJoCo-native xArm driver with SDK wrapper, integrates with component-based architecture
dimos/simulation/sim_blueprints.py Added simulation blueprint for xArm7 with trajectory controller using MuJoCo backend
dimos/hardware/manipulators/xarm/components/state_queries.py Added RPC methods for servo angles, FT sensor data, and removed unused type hints
pyproject.toml Added robot_descriptions dependency for MuJoCo model loading

Sequence Diagram

sequenceDiagram
    participant User
    participant XArmSimDriver
    participant XArmSimSDKWrapper
    participant XArmSimBridge
    participant MujocoSimBridgeBase
    participant MuJoCo
    participant Viewer

    User->>XArmSimDriver: Initialize with config
    XArmSimDriver->>XArmSimSDKWrapper: Create SDK wrapper
    XArmSimDriver->>XArmSimDriver: Setup components

    User->>XArmSimSDKWrapper: connect(config)
    XArmSimSDKWrapper->>XArmSimBridge: Create bridge instance
    XArmSimBridge->>MujocoSimBridgeBase: __init__()
    MujocoSimBridgeBase->>MuJoCo: Load robot description
    MujocoSimBridgeBase-->>XArmSimBridge: Model & Data ready
    
    XArmSimSDKWrapper->>XArmSimBridge: connect()
    XArmSimBridge->>MujocoSimBridgeBase: connect()
    MujocoSimBridgeBase->>MujocoSimBridgeBase: Start sim_thread
    XArmSimBridge->>XArmSimBridge: Start report_thread
    
    par Simulation Loop (sim_thread)
        loop Control Frequency (100 Hz)
            MujocoSimBridgeBase->>Viewer: launch_passive()
            MujocoSimBridgeBase->>XArmSimBridge: _apply_control()
            XArmSimBridge->>MuJoCo: Update ctrl[] with targets
            MujocoSimBridgeBase->>MuJoCo: mj_step()
            MuJoCo-->>MujocoSimBridgeBase: Updated state
            MujocoSimBridgeBase->>Viewer: sync()
            MujocoSimBridgeBase->>XArmSimBridge: _update_joint_state()
            XArmSimBridge->>XArmSimBridge: Update positions/velocities/efforts
        end
    and Report Loop (report_thread)
        loop Report Frequency (100 Hz)
            XArmSimBridge->>XArmSimBridge: _notify_report()
            XArmSimBridge->>User: report_callback(state data)
        end
    end

    User->>XArmSimSDKWrapper: set_joint_positions(positions)
    XArmSimSDKWrapper->>XArmSimBridge: set_servo_angle_j()
    XArmSimBridge->>XArmSimBridge: Update _joint_position_targets
    Note over XArmSimBridge,MuJoCo: Targets applied in next control loop

    User->>XArmSimSDKWrapper: get_joint_positions()
    XArmSimSDKWrapper->>XArmSimBridge: get_servo_angle()
    XArmSimBridge-->>XArmSimSDKWrapper: Current joint angles
    XArmSimSDKWrapper-->>User: Joint positions

    User->>XArmSimSDKWrapper: disconnect()
    XArmSimSDKWrapper->>XArmSimBridge: disconnect()
    XArmSimBridge->>XArmSimBridge: Stop report_thread
    XArmSimBridge->>MujocoSimBridgeBase: disconnect()
    MujocoSimBridgeBase->>MujocoSimBridgeBase: Stop sim_thread
    MujocoSimBridgeBase->>Viewer: Close viewer
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

54 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@spomichter
Copy link
Contributor

@jca0 thanks for attempting agents_deprecated rip out but thats out of scope here and needs to be done carefully since we are using some code in there still. revert those deletions

@spomichter spomichter changed the base branch from main to dev January 13, 2026 19:58
@jca0
Copy link
Author

jca0 commented Jan 13, 2026

oops must've deleted on accident, it's added back now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants