legged_gym

repository·master·Indexed 25 days ago

https://github.com/leggedrobotics/legged_gym

An Isaac Gym-based framework for training legged robots, such as ANYmal, to walk on rough terrain. It provides features for sim-to-real transfer, including actuator networks, randomization, and noisy observations. The repository includes scripts for training and playing policies, as well as guidelines for adding new robot environments and tasks.

Tokens
1.3K
Snippets
3
Records
6
Agent score
35%

What's inside legged_gym

  1. Install legged_gym and dependencies

    master

    Follow these steps to set up the environment. It is recommended to use Python 3.8.

    1. Create a Python virtual environment (Python 3.6, 3.7, or 3.8).
    2. Install PyTorch 1.10 with CUDA 11.3:
      pip3 install torch==1.10.0+cu113 torchvision==0.11.1+cu113 torchaudio==0.10.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html
    3. Install Isaac Gym Preview 3 (Note: Preview 2 is not supported):
      • Download from NVIDIA Developer.
      • Install the python package:
        cd isaacgym/python && pip install -e .
    4. Install rsl_rl (PPO implementation):
      git clone https://github.com/leggedrobotics/rsl_rl
      cd rsl_rl && git checkout v1.0.2 && pip install -e .
    5. Install legged_gym:
      git clone <repository_url>
      cd legged_gym && pip install -e .
  2. Add a new environment to legged_gym

    master

    To add a new robot or task, follow these steps:

    1. Create a config file: Add a new folder to envs/ containing <your_env>_config.py. This should inherit from an existing environment configuration.
    2. Add Robot Assets: If using a new robot, add assets to resources/. In your config, set the asset path, body names, default_joint_positions, and PD gains. Define the train_cfg and the environment class name.
    3. Implement the Environment (Optional): If needed, create <your_env>.py in envs/. Inherit from an existing environment and overwrite specific functions or add new reward functions.
    4. Register the Task: Register your environment in isaacgym_anymal/envs/__init__.py using: task_registry.register(name, EnvClass, EnvConfig, TrainConfig).
    5. Tune Parameters: Modify cfg and cfg_train. To remove a reward, set its scale to zero. Warning: Do not modify parameters of other environments.
  3. Workaround for unreliable contact forces on GPU

    master

    When simulating on GPU with triangle mesh terrain, net_contact_force_tensor is unreliable. Use force sensors on the feet/end effectors instead. To avoid gravity interference, set sensor_options.enable_forward_dynamics_forces = False.

    Implementation Example:

    sensor_pose = gymapi.Transform()
    for name in feet_names:
        sensor_options = gymapi.ForceSensorProperties()
        sensor_options.enable_forward_dynamics_forces = False # excludes gravity
        sensor_options.enable_constraint_solver_forces = True # includes contacts
        sensor_options.use_world_frame = True 
        index = self.gym.find_asset_rigid_body_index(robot_asset, name)
        self.gym.create_asset_force_sensor(robot_asset, index, sensor_pose, sensor_options)
    (...)
    
    sensor_tensor = self.gym.acquire_force_sensor_tensor(self.sim)
    self.gym.refresh_force_sensor_tensor(self.sim)
    force_sensor_readings = gymtorch.wrap_tensor(sensor_tensor)
    self.sensor_forces = force_sensor_readings.view(self.num_envs, 4, 6)[..., :3]
    (...)
    
    self.gym.refresh_force_sensor_tensor(self.sim)
    contact = self.sensor_forces[:, :, 2] > 1.
    sensor_options.enable_forward_dynamics_forces = False # for example gravity
    sensor_options.enable_constraint_solver_forces = True # for example contacts
  4. Fix ImportError: libpython3.8m.so.1.0

    master

    If you encounter ImportError: libpython3.8m.so.1.0: cannot open shared object file: No such file or directory, try the following:

    1. Install the library:
      sudo apt install libpython3.8
    2. Or, manually update your LD_LIBRARY_PATH to point to your Python library directory (e.g., your conda environment's lib folder):
      export LD_LIBRARY_PATH=/path/to/conda/envs/your_env/lib
  5. Train a legged robot policy

    master

    Use the train.py script to start training. You can override configuration values using command-line arguments.

    Command:

    python legged_gym/scripts/train.py --task=anymal_c_flat

    Arguments:

    • --task TASK: Task name (e.g., anymal_c_flat).
    • --sim_device cpu: Run simulation on CPU (default is GPU).
    • --rl_device cpu: Run reinforcement learning on CPU.
    • --headless: Run without rendering.
    • --resume: Resume training from a checkpoint.
    • --experiment_name EXPERIMENT_NAME: Name of the experiment.
    • --run_name RUN_NAME: Name of the specific run.
    • --load_run LOAD_RUN: Name of the run to load when resume=True. Use -1 to load the last run.
    • --checkpoint CHECKPOINT: Saved model checkpoint number. Use -1 to load the last checkpoint.
    • --num_envs NUM_ENVS: Number of environments to create.
    • --seed SEED: Random seed.
    • --max_iterations MAX_ITERATIONS: Maximum number of training iterations.

    Note: To improve performance, press v once training starts to stop rendering. You can re-enable it later to check progress.

    Output: Trained policies are saved in issacgym_anymal/logs/<experiment_name>/<date_time>_<run_name>/model_<iteration>.pt.

    python legged_gym/scripts/train.py --task=anymal_c_flat
  6. Play a trained policy

    master

    Use the play.py script to visualize a trained policy. By default, it loads the last model from the last run of the specified experiment folder.

    Command:

    python legged_gym/scripts/play.py --task=anymal_c_flat

    To select specific runs or checkpoints, you must set load_run and checkpoint within your training configuration files.

    python legged_gym/scripts/play.py --task=anymal_c_flat