A comprehensive simulation setup for the Universal Robots UR5e robot using MuJoCo physics engine.
ur5e_simulation/
├── ur5e_main.xml # Main simulation XML file
├── assets/ # Asset files
│ ├── ur5e/ # UR5e robot assets
│ │ ├── ur5e_assets.xml # Materials and mesh definitions
│ │ ├── ur5e_body.xml # Robot body structure
│ │ ├── ur5e_actuators.xml # Actuator definitions
│ │ └── meshes/ # STL mesh files
│ └── common_arena/ # Environment assets
│ └── simple_plane.xml # Ground plane
├── src/ # Source code
│ ├── __init__.py # Package initialization
│ ├── ur5e_simulator.py # Main simulator class
│ ├── util.py # Utility functions
│ ├── PID.py # PID controller
│ └── ik_module.py # Inverse kinematics utilities
├── demo_ur5e.py # Demonstration script
├── test_setup.py # Setup validation script
└── README.md # This file
- Complete UR5e Model: Accurate 6-DOF UR5e robot with proper joint limits and dynamics
- MuJoCo Integration: Full integration with MuJoCo physics engine
- Interactive Viewer: Real-time 3D visualization with camera controls
- Forward Kinematics: Compute end-effector pose from joint angles
- Inverse Kinematics: Solve for joint angles given target end-effector pose
- Joint Control: Position and velocity control of individual joints
- Physics Simulation: High-fidelity physics simulation with collision detection
- Visual Rendering: Real-time rendering with customizable materials and lighting
- Trajectory Planning: Tools for planning and executing robot trajectories
- PID Control: Built-in PID controller for joint position control
- Python 3.7+
- MuJoCo: Install MuJoCo physics engine
pip install mujoco
- NumPy: For numerical computations
pip install numpy
- Clone or download this project
- Ensure all mesh files are in the correct location (
assets/ur5e/meshes/) - Run the setup test:
python test_setup.py
from src.ur5e_simulator import UR5eSimulator
import numpy as np
# Initialize simulator
ur5e = UR5eSimulator(
xml_path='ur5e_main.xml',
USE_VIEWER=True
)
# Set joint positions (6 joints in radians)
home_position = np.array([-1.5708, -1.5708, 1.5708, -1.5708, -1.5708, 0])
ur5e.set_joint_positions(home_position)
# Get end-effector pose
position, rotation = ur5e.get_end_effector_pose()
# Render simulation
for i in range(1000):
ur5e.render()# Define target position
target_pos = np.array([0.3, 0.3, 0.5])
# Solve IK
joint_solution = ur5e.inverse_kinematics(target_pos)
if joint_solution is not None:
ur5e.set_joint_positions(joint_solution)-
Setup Test: Validate installation
python test_setup.py
-
Basic Demo: Run comprehensive demonstration
python demo_ur5e.py
- Simulation parameters (timestep, solver settings)
- Include statements for sub-components
- Default joint and material properties
- Keyframe definitions for common poses
- ur5e_assets.xml: Material properties and mesh references
- ur5e_body.xml: Robot link structure and joint definitions
- ur5e_actuators.xml: Motor and control definitions
- Ground plane and environmental objects
- Lighting and camera definitions
- Add mesh files to
assets/ur5e/meshes/ - Update
ur5e_body.xmlwith new link definitions - Modify
end_effector_namein simulator class
# Example: Custom PID control
from src.PID import PID_ControllerClass
pid_controller = PID_ControllerClass(
k_p=10.0, k_i=0.1, k_d=1.0, dim=6
)
# In control loop
target_joints = np.array([...]) # Target joint positions
current_joints = ur5e.get_joint_positions()
control_output = pid_controller.get_output(
x_trgt=target_joints,
x_curr=current_joints,
t_curr=ur5e.get_simulation_time()
)
ur5e.step(ctrl=control_output)Modify XML files to include:
- Force/torque sensors
- IMU sensors
- Camera sensors
- Proximity sensors
__init__(xml_path, USE_VIEWER=True): Initialize simulatorreset(): Reset simulation to initial statestep(ctrl=None, nstep=1): Step simulation forwardrender(): Update visualizationclose_viewer(): Close simulation window
get_joint_positions(): Get current joint anglesset_joint_positions(positions): Set joint anglesget_end_effector_pose(): Get end-effector position and orientationget_jacobian(body_name): Get Jacobian matrixinverse_kinematics(target_pos, target_rot=None): Solve IK
add_visual_marker(position, size, color): Add visual markersget_simulation_time(): Get current simulation timeis_viewer_alive(): Check if viewer is active
-
ImportError: No module named 'mujoco'
- Install MuJoCo:
pip install mujoco
- Install MuJoCo:
-
XML parsing errors
- Check that all mesh files exist in
assets/ur5e/meshes/ - Verify XML file paths and syntax
- Check that all mesh files exist in
-
Viewer not opening
- Check display settings
- Try running with
USE_VIEWER=Falsefor headless mode
-
IK not converging
- Target position may be outside workspace
- Adjust IK parameters (tolerance, max_iterations, step_size)
- Check for joint limit violations
- Use smaller timesteps for more accurate simulation
- Disable viewer for faster computation
- Use appropriate solver settings for your application
Feel free to contribute by:
- Adding new robot models
- Implementing advanced control algorithms
- Improving IK solvers
- Adding more comprehensive examples
This project is based on components from Simple-MuJoCo-PickNPlace and MuJoCo tutorials.