A toolkit for MuJoCo simulation and visualization
Project description
A comprehensive toolkit for MuJoCo simulation, visualization, and data processing.
Todo List
Refactor
- [] Define the unified data format (txt npy npz)
- [] In recorder, the video that output the result of the activation is obviously not good.
Completed Features
- Basic MuJoCo model loading and simulation
- Command-line interface with comprehensive options
- 3D model motion trajectory rendering
- Multi-camera view support
- Customizable resolution (supports up to 4K)
- Adjustable playback speed and frame rate
- Joint positions (qpos) and velocities (qvel) recording
- Body positions (xpos) and orientations (xquat) recording
- Support for multiple data formats (.npy/.txt/.csv)
- Basic data analysis and processing utilities
- Initial pose configuration using model keyframes (init_qpos)
In Progress
- Add tests scripts to test the package
- Muscle activation heatmap display
- Tendon path points recording
- Sensor data recording
- Support for .mot trajectory format
- Advanced data analysis tools
- Documentation improvements
- Unit tests
- Example scripts for common use cases
Installation
# Install from source
git clone https://github.com/yourusername/mujoco_tools.git
cd mujoco_tools
pip install -e .
# Install from PyPI
pip install mujoco-tools
# Install from github
pip install git+https://github.com/ShanningZhuang/mujoco_tools.git
Project Structure
mujoco_tools/
├── mujoco_tools/ # Main package
│ ├── cli.py # Command-line interface
│ ├── mujoco_loader.py # MuJoCo model loading utilities
│ ├── player.py # Visualization player
│ ├── recorder.py # Data recording utilities
│ ├── tools.py # General utilities
│ └── data_processor.py # Data processing utilities
├── models/ # Test models
└── examples/ # Example scripts
Usage
1. Command Line Interface
mujoco-tools -m <model.xml> [options]
Required Arguments:
-m, --model: Path to MuJoCo XML model file--mode: Simulation mode (kinematics: runs mj.fwd_position, dynamics: runs mj.step) [default: kinematics]
Input Data Options:
-d, --data: Input data type and path (e.g., "qpos data/qpos.npy ctrl data/ctrl.npy") or Directly input the path of npz--input_data_freq: Frequency of input data [default: 50]--init_qpos: Initialize first frame with key_qpos[init_qpos] from the model (integer index)
Output Path Options:
--output_path: Output path [default: logs]--output_prefix: Output prefix [default: output]
Visualization Options:
--record_video: Enable video recording--width: Video width in pixels [default: 1920]--height: Video height in pixels [default: 1080]--fps: Video framerate [default: 50]--output_video_freq: Frequency of output video [default: 50]--camera: Camera name [default: Free]--flags: Custom vision flags (e.g., "mjVIS_ACTUATOR mjVIS_ACTIVATION")
Recording Options:
--record_data: Enable data recording--format: Output format (npy/txt/csv) [default: npy]--datatype: Data types to record (space-separated: qpos qvel xpos xquat sensor tendon) [default: qpos]--output_data_freq: Frequency of output data [default: 50]
2. Bash Script Usage
Create a bash script for configuration:
#!/bin/bash
# Default settings
MODEL_PATH="models/humanoid/humanoid.xml"
DATA_PATH="qpos data/qpos.npy"
MODE="kinematics"
OUTPUT="output/video.mp4"
RESOLUTION="1080p"
FPS=50
CAMERA="side"
RECORD_DATA=1
DATA_FORMAT="npy"
RECORD_TYPES="qpos qvel xpos"
# Build command
CMD="mujoco-tools \\
-m \"$MODEL_PATH\" \\
-d \"$DATA_PATH\" \\
--mode \"$MODE\" \\
-o \"$OUTPUT\" \\
--resolution \"$RESOLUTION\" \\
--fps \"$FPS\" \\
--camera \"$CAMERA\""
# Add recording options
if [ "$RECORD_DATA" -eq 1 ]; then
CMD+=" --record"
CMD+=" --format \"$DATA_FORMAT\""
CMD+=" --datatype \"$RECORD_TYPES\""
fi
# Execute command
eval "$CMD"
3. Python Module Usage
# Direct module import
from mujoco_tools import MujocoLoader, Player, Recorder
# Command line usage examples
# Basic usage
python -m mujoco_tools.cli -m /path/to/model.xml -d 'qpos /path/to/data.npy'
# Using initial keyframe position
python -m mujoco_tools.cli -m /path/to/model.xml --init_qpos 0 --record_video
# Advanced usage with activation visualization
mujoco-tools -m /home/zsn/research/mujoco_tools/logs/model/Arm_Hand/mj_vision_manipulation_high_cube.xml -d "act /home/zsn/research/mujoco_tools/logs/arm_hand/2025_02_08_23_07_44_HandCube_act.txt qpos /home/zsn/research/mujoco_tools/logs/arm_hand/2025_02_08_23_07_44_HandCube_qpos.txt" --mode kinematics --input_data_freq 500 --record_video --camera "record_camera_2" --width 1920 --height 1080 --output_prefix stage6 --flags "mjVIS_ACTUATOR mjVIS_ACTIVATION" --activation_map --activation_shape "10 9" --init_qpos 0
Data Format
The default output format is .npy (or .npz for multiple arrays). Data is stored in (time, data) format.
Development
Setup Development Environment
# Clone the repository
git clone https://github.com/yourusername/mujoco_tools.git
cd mujoco_tools
# Install development dependencies
pip install -e .
Publishing
The package is automatically published to PyPI when a new release is created on GitHub. To publish a new version:
- Update version in
setup.py - Create and push a new tag:
git tag v0.1.0 # Use appropriate version
git push origin v0.1.0
- Create a new release on GitHub using the tag
- The GitHub Action will automatically build and publish to PyPI
Running Tests
pytest tests/
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
To contribute:
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mujoco_tools-0.1.1.tar.gz.
File metadata
- Download URL: mujoco_tools-0.1.1.tar.gz
- Upload date:
- Size: 2.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1223a14b964ca7ab413cdf924ebc2b9272cddcec14c5d4a0e33cf17419ace02
|
|
| MD5 |
2e72adad00e811e4efc49ebe5e3ec3eb
|
|
| BLAKE2b-256 |
65c6e790623c89d1f14562b500aad9b44ab9bed23cda0d8669c9d9f8ea08a899
|
File details
Details for the file mujoco_tools-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mujoco_tools-0.1.1-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51d0d73f1106766c550a415ee17849fb249d1dc44a075c1ccb577fef6123d398
|
|
| MD5 |
dbfcf984018b4d78e041682d4599d936
|
|
| BLAKE2b-256 |
c45e8e37847cd9a03d41014ec79376736f845f552ea4cca8d3901ae3ea3f2051
|