Skip to main content

A gym environment for LuckyWorld

Project description

gym-luckyworld

A gym environment for the Lucky World simulator

ACT policy on ALOHA env

Installation

Create a virtual environment with Python 3.13 and activate it, e.g. with miniconda:

conda create -y -n luckyworld python=3.13 && conda activate luckyworld

Install gym-luckyworld:

pip install gym-luckyworld

Quickstart

import imageio
import numpy as np
import gymnasium as gym
import gym_luckyworld # noqa: F401

env = gym.make("gym_luckyworld/LuckyWorld-PickandPlace-v0")

observation, info = env.reset()
frames = []

for _ in range(1000):
    action = env.action_space.sample()
    observation, reward, terminated, truncated, info = env.step(action)
    image = env.render()
    if env.render_mode == "rgb_array":
        frames.append(image)

    if terminated or truncated:
        observation, info = env.reset()

env.close()

if env.render_mode == "rgb_array":  
    imageio.mimsave("example.mp4", np.stack(frames), fps=10)

Description

LuckyWorld environment for imitation learning with robotic manipulation tasks.

Two tasks are available:

  • PickandPlace: The SO100 robot arm needs to pick up objects and place them at target locations.
  • Navigation: Robot navigation tasks for mobile platforms.

Robots

  • SO100: 6-DOF robotic arm with the following actuators:
    • shoulder_pan: Shoulder rotation (-2.2 to 2.2 rad)
    • shoulder_lift: Shoulder elevation (-3.14 to 0.2 rad)
    • elbow_flex: Elbow joint (0.0 to 3.14 rad)
    • wrist_flex: Wrist flexion (-2.0 to 1.8 rad)
    • wrist_roll: Wrist rotation (-3.14 to 3.14 rad)
    • gripper: Gripper position (-0.2 to 2.0)

Action Space

The action space consists of continuous values for the robot's joint positions, resulting in a 6-dimensional vector for SO100:

  • Six values for the arm's joint positions (absolute values within joint limits).

Observation Space

Observations are provided as a dictionary with the following keys:

  • agent_pos: Current joint positions of the robot arm (6D vector for SO100).
  • pixels: RGB camera feed (480x640x3) from the robot's perspective.

Rewards

Important: This environment is designed for imitation learning. All rewards are set to 0.0 by default.

For reinforcement learning applications, you must implement custom reward functions by:

  1. Subclassing the task classes (PickandPlace, Navigation)
  2. Overriding the get_reward() method with your domain-specific reward logic

Termination Criteria

Episodes terminate based on task-specific conditions:

  • PickandPlace:
    • Success: Object is placed at target location
    • Failure: Object is dropped away from target
  • Navigation:
    • Success: Robot reaches target location
    • Failure: Robot collides with obstacles

Starting State

The robot and environment objects start at randomized positions within predefined bounds.

Arguments

>>> import gymnasium as gym
>>> import gym_luckyworld
>>> env = gym.make("gym_luckyworld/LuckyWorld-PickandPlace-v0", obs_type="pixels_agent_pos", render_mode="rgb_array")
>>> env
<TimeLimit<OrderEnforcing<PassiveEnvChecker<LuckyWorldEnv<gym_luckyworld/LuckyWorld-PickandPlace-v0>>>>>
  • obs_type: (str) The observation type. Currently supports pixels_agent_pos (camera + joint positions). Default is pixels_agent_pos.
  • render_mode: (str) The rendering mode. Can be human (OpenCV windows) or rgb_array (numpy arrays). Default is human.
  • scene: (str) The scene to load. Default is kitchen.
  • robot_type: (str) The robot type. Currently supports so100. Default is so100.
  • timeout: (float) Maximum episode duration in seconds. Default is 30.0.

Example Usage for Imitation Learning

import gymnasium as gym
import gym_luckyworld

# Create environment
env = gym.make(
    "gym_luckyworld/LuckyWorld-PickandPlace-v0",
    obs_type="pixels_agent_pos",
    render_mode="rgb_array"
)

# Collect demonstration data
observations = []
actions = []

obs, info = env.reset()
for step in range(100):
    # Your demonstration policy here
    action = your_policy(obs)
    
    observations.append(obs)
    actions.append(action)
    
    obs, reward, terminated, truncated, info = env.step(action)
    
    if terminated or truncated:
        obs, info = env.reset()

env.close()

# Use observations and actions for imitation learning
# (e.g., with ACT, BC, IQL, etc.)

Custom Rewards for RL

If you want to use this environment for reinforcement learning, implement custom rewards:

from gym_luckyworld.task import PickandPlace

class RewardedPickandPlace(PickandPlace):
    def get_reward(self, observation, info):
        # Implement your reward logic here
        object_distance = info.get("object_distance_from_target", float('inf'))
        reward = -object_distance  # Negative distance as reward
        
        # Add success bonus
        if object_distance < self.distance_threshold:
            reward += 100.0
            
        return reward

# Use your custom task
env = gym.make("gym_luckyworld/LuckyWorld-PickandPlace-v0")
env.task = RewardedPickandPlace("kitchen", "pickandplace", "so100", "human")

Contribute

Instead of using pip directly, we use poetry for development purposes to easily track our dependencies. If you don't have it already, follow the instructions to install it.

Install the project with dev dependencies:

poetry install --all-extras

Follow our style

# install pre-commit hooks
pre-commit install

# apply style and linter checks on staged files
pre-commit

Acknowledgment

gym-luckyworld is adapted from gym-aloha and built on top of the LuckyRobots simulation platform.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gym_luckyworld-0.0.3.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gym_luckyworld-0.0.3-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file gym_luckyworld-0.0.3.tar.gz.

File metadata

  • Download URL: gym_luckyworld-0.0.3.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for gym_luckyworld-0.0.3.tar.gz
Algorithm Hash digest
SHA256 0781d97ffa029376d17e15ecdd51f04f4c8454c668d33f11b19364c762b51d49
MD5 f72ffd1ac9b923b23dae159ed77c7eea
BLAKE2b-256 ea81132f752ebe06a7371e1e6bcabbdad4bc5aa4cd5ab8ab53d56a5215a2390c

See more details on using hashes here.

File details

Details for the file gym_luckyworld-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: gym_luckyworld-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for gym_luckyworld-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 18cbc656f9605e84346923db5dfbde4413ab6c07292048fe6a5987ae1cd23949
MD5 4ace112a942e1e1847d824b3ce256955
BLAKE2b-256 70b92504204b08023eeab20e89d21b21402e96e5cae41e51f8747290947d9887

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page