Views
No views yet

1# Clone the repository
2git clone https://github.com/your-org/gym-soarm.git
3cd gym-soarm
4
5# Install in development mode
6pip install -e .
7
8# Or install with development dependencies
9pip install -e ".[dev,test]"pip install gym-soarm1import gymnasium as gym
2import gym_soarm
3
4# Create environment with human rendering and camera configuration
5env = gym.make('SoArm-v0', render_mode='human', obs_type='pixels_agent_pos', camera_config='front_wrist')
6
7# Reset environment with specific cube position
8obs, info = env.reset(options={'cube_grid_position': 4})
9
10# The environment automatically records MP4 videos when using example.py
11# Access joint positions and camera images
12print(f"Joint positions: {obs['agent_pos']}") # 6 joint values including gripper
13print(f"Available cameras: {list(obs['pixels'].keys())}") # front_camera, wrist_camera
14
15# Run simulation with 6DOF joint control
16for _ in range(200):
17 action = env.action_space.sample() # 6D action: [shoulder_pan, shoulder_lift, elbow_flex, wrist_flex, wrist_roll, gripper]
18 obs, reward, terminated, truncated, info = env.step(action)
19
20 if terminated or truncated:
21 obs, info = env.reset()
22
23env.close()1# Run the slider control sample
2python examples/slider_control_final.py1import gymnasium as gym
2import gym_soarm
3
4env = gym.make('SoArm-v0', render_mode='human')
5
6# Place cube at specific grid position (0-8)
7obs, info = env.reset(options={'cube_grid_position': 4}) # Center position
8
9# Use random position (default behavior)
10obs, info = env.reset(options={'cube_grid_position': None})0: (-10cm, -7.5cm) 1: (-10cm, 0cm) 2: (-10cm, +7.5cm)
3: ( 0cm, -7.5cm) 4: ( 0cm, 0cm) 5: ( 0cm, +7.5cm)
6: (+10cm, -7.5cm) 7: (+10cm, 0cm) 8: (+10cm, +7.5cm)1import gymnasium as gym
2import gym_soarm
3
4env = gym.make('SoArm-v0', render_mode='human')
5
6# Place cube at custom coordinates
7options = {
8 'cube_grid_position': -1, # Use -1 to enable custom coordinates
9 'cube_x': 0.15, # X coordinate in meters
10 'cube_y': 0.35 # Y coordinate in meters
11}
12obs, info = env.reset(options=options)1# Near the front of the table
2obs, info = env.reset(options={'cube_grid_position': -1, 'cube_x': 0.0, 'cube_y': 0.3})
3
4# Left side of workspace
5obs, info = env.reset(options={'cube_grid_position': -1, 'cube_x': -0.1, 'cube_y': 0.4})
6
7# Right side with precise positioning
8obs, info = env.reset(options={'cube_grid_position': -1, 'cube_x': 0.12, 'cube_y': 0.38})1# Completely random placement (default)
2obs, info = env.reset()
3
4# Explicitly request random placement
5obs, info = env.reset(options={'cube_grid_position': None})cube_x and cube_y parameters are required1# This will raise ValueError - missing cube_y
2try:
3 obs, info = env.reset(options={'cube_grid_position': -1, 'cube_x': 0.1})
4except ValueError as e:
5 print(e) # "cube_x and cube_y must be provided when cube_grid_position is -1"
6
7# This will raise ValueError - invalid grid position
8try:
9 obs, info = env.reset(options={'cube_grid_position': 10})
10except ValueError as e:
11 print(e) # "cube_grid_position must be between 0 and 8 (inclusive)..."1import gymnasium as gym
2import gym_soarm
3
4# Front camera only (minimal, fastest)
5env = gym.make('SoArm-v0', obs_type='pixels', camera_config='front_only')
6
7# Front and wrist cameras (default, balanced)
8env = gym.make('SoArm-v0', obs_type='pixels', camera_config='front_wrist')
9
10# All cameras (comprehensive, slower)
11env = gym.make('SoArm-v0', obs_type='pixels', camera_config='all')
12
13obs, info = env.reset()
14print(f"Available cameras: {list(obs.keys())}")front_only: Only front camera (side view) - fastest, minimal observationsfront_wrist: Front camera + wrist camera (first-person view) - balanced performanceall: All three cameras (overview + front + wrist) - comprehensive but slower1# front_only
2obs = {
3 'front_camera': np.ndarray(shape=(480, 640, 3))
4}
5
6# front_wrist
7obs = {
8 'front_camera': np.ndarray(shape=(480, 640, 3)),
9 'wrist_camera': np.ndarray(shape=(480, 640, 3))
10}
11
12# all
13obs = {
14 'overview_camera': np.ndarray(shape=(480, 640, 3)),
15 'front_camera': np.ndarray(shape=(480, 640, 3)),
16 'wrist_camera': np.ndarray(shape=(480, 640, 3))
17}example.py script automatically records camera observations to MP4 videos:1import gymnasium as gym
2import gym_soarm
3
4# Run the example script with video recording
5env = gym.make('SoArm-v0', render_mode='human', obs_type='pixels_agent_pos', camera_config='front_wrist')
6
7# Videos are automatically saved to videos/ directory with timestamps
8# - front_camera_20250729_143022.mp4
9# - wrist_camera_20250729_143022.mp4
10
11# Manual video recording can be implemented using:
12frames_storage = {}
13obs, info = env.reset()
14
15# Store frames from each camera
16if "pixels" in obs:
17 for camera_name, frame in obs['pixels'].items():
18 if camera_name not in frames_storage:
19 frames_storage[camera_name] = []
20 frames_storage[camera_name].append(frame.copy())
21
22# Use save_frames_to_mp4() function from example.py to save videosrender_mode='human', use these keyboard controls:1# For obs_type='pixels_agent_pos'
2obs_space = gym.spaces.Dict({
3 'agent_pos': gym.spaces.Box(-np.inf, np.inf, shape=(6,), dtype=np.float64), # Joint positions
4 'pixels': gym.spaces.Dict({
5 'front_camera': gym.spaces.Box(0, 255, shape=(480, 640, 3), dtype=np.uint8),
6 'wrist_camera': gym.spaces.Box(0, 255, shape=(480, 640, 3), dtype=np.uint8)
7 })
8})| Camera | Position | Orientation | FOV | Description |
|---|---|---|---|---|
| Overview | (0, 0.4, 0.8) | Top-down | 90° | Bird's eye view |
| Front | (0, 0.7, 0.25) | Angled forward | 120° | Side perspective |
| Wrist | (0, -0.04, 0) | 30° X-rotation | 110° | First-person view |
gym-soarm/
├── gym_soarm/ # Main package
│ ├── __init__.py # Package initialization
│ ├── env.py # Main environment class
│ ├── constants.py # Environment constants
│ ├── assets/ # Robot models and scenes
│ │ ├── so101_new_calib.xml # SO-ARM101 robot model (white color)
│ │ ├── so_arm_main_new.xml # Scene with table and objects
│ │ └── assets/ # STL mesh files
│ └── tasks/ # Task implementations
│ ├── __init__.py
│ └── sim.py # Manipulation tasks
├── examples/ # Example scripts and demonstrations
│ ├── example.py # Basic usage with MP4 recording
│ └── slider_control_final.py # Interactive joint control with sliders
├── videos/ # Auto-generated MP4 video outputs
├── setup.py # Package setup
├── pyproject.toml # Poetry configuration
└── README.md # This file1# Install test dependencies
2pip install -e ".[test]"
3
4# Run comprehensive test suite
5pytest tests/ -v
6
7# Run specific test categories
8pytest tests/test_e2e.py -v # End-to-end tests
9pytest tests/test_camera_config.py -v # Camera configuration tests
10
11# Run basic functionality test
12python examples/example.py
13
14# Test interactive joint control
15python examples/slider_control_final.py
16
17# Test camera configuration features
18python test_camera_features.py1# Install development dependencies
2pip install -e ".[dev]"
3
4# Run linting
5ruff check gym_soarm/
6
7# Auto-format code
8ruff format gym_soarm/xvfb-run for rendering.stl files are present in assets/assets/1@software{gym_soarm,
2 title={Gym SO-ARM: A Gymnasium Environment for SO-ARM101 Manipulation},
3 author={SO-ARM Development Team},
4 version={0.1.0},
5 year={2024},
6 url={https://github.com/your-org/gym-soarm}
7}