MetaDrive Documentation

repository·main·Indexed 22 days ago

https://github.com/metadriverse/metadrive

An open-source, lightweight, and compositional driving simulator for AI and autonomy research. It features infinite scene synthesis, realistic physics, and various sensory inputs (RGB, Depth, Point Cloud), with compatibility for RL frameworks via the Gymnasium API. The documentation covers vehicle control policies (IDMPolicy, WaypointPolicy, etc.), ROS2 bridge integration, and a detailed render pipeline including Panda3D patches, IES light profiles, and C++ native modules.

Tokens
27.7K
Snippets
69
Records
132
Agent score
78%

What's inside MetaDrive

  1. Overview of DI-drive

    main

    DI-drive is a Decision Intelligence Platform for Autonomous Driving simulation developed under OpenDILab. It is designed to apply Deep Learning methods to decision-making, planning, and control tasks in autonomous driving simulations.

    Key features include:

    • High ease of use and low barrier to entry.
    • Casezoo: A design component intended to make simulation environments closer to real-world driving.
    • Simulator Support: It supports both Carla and MetaDrive simulators.
    • Deep Learning Integration: It develops driving policies using PyTorch and DI-engine.
    • MetaDrive Integration: Provides tutorials for training agents specifically within the MetaDrive simulator and shares pre-trained models.
  2. Overview of MetaDrive simulator

    main

    MetaDrive is an efficient, compositional driving simulator designed for AI and autonomy research, specifically for Reinforcement Learning (RL).

    Key features include:

    • Compositional Scene Generation: Supports generating infinite scenes with diverse road maps and traffic settings to facilitate research into generalizable RL.
    • High Performance: Lightweight design capable of running up to 1,500 FPS on standard PCs (and over 2,000 FPS on MacBook Pro).
    • Realistic Simulation: Provides accurate physics and multiple sensory inputs, including:
      • Lidar
      • RGB images
      • Top-down semantic maps
      • First-person view images.
  3. What is ScenarioNet and how does it relate to MetaDrive?

    main
    ScenarioNet is a scenario database management system designed to work tightly with the MetaDrive simulator. While MetaDrive provides the driving simulation environment for high-level applications, ScenarioNet serves as the data foundation. It provides tools to convert real-world driving datasets—such as Waymo, nuScenes, nuPlan, and Argoverse—into a format compatible with the MetaDrive simulator. This allows researchers to reconstruct thousands of real-world scenarios within MetaDrive for machine learning and autonomy research.
  4. Use the MetaDrive ROS2 Bridge

    main

    To run the bridge, you must launch the ROS publishers and the socket server in separate terminal sessions.

    1. Terminal 1: Launch the ROS2 publishers using the provided launch file.
    2. Terminal 2: Launch the ZMQ socket server using the Python script.
    # Terminal 1, launch ROS publishers
    ros2 launch metadrive_example_bridge metadrive_example_bridge.launch.py
    
    # Terminal 2, launch socket server
    python ros_socket_server.py
  5. Apply Panda3D patches for the MetaDrive render pipeline

    main

    MetaDrive uses specific patches for the Panda3D engine to enable advanced render pipeline features that are not yet part of the official Panda3D repository.

    Workflow Requirement: After applying a patch to your Panda3D installation, you must delete the patch file from this directory. Deleting the file signals to the MetaDrive render pipeline that the patch has been successfully applied and is available for use.

  6. Run the MetaDrive ROS2 Bridge

    main

    The bridge requires two separate processes running in different terminals to function: one to launch the ROS2 publishers and another to launch the socket server that communicates with MetaDrive.

    1. Terminal 1: Launch the ROS2 publishers using the provided launch file.
    2. Terminal 2: Launch the socket server script.
    # Terminal 1, launch ROS publishers
    ros2 launch metadrive_example_bridge metadrive_example_bridge.launch.py
    
    # Terminal 2, launch socket server
    python ros_socket_server.py 
  7. Manage custom textures and models in the plugin prefab resource folder

    main

    To use custom assets such as textures, 3D models, or other external resources within a plugin prefab, place them directly into the metadrive/render_pipeline/rpplugins/plugin_prefab/resources/ directory.

    Once placed in this folder, you can retrieve the resource within your code using the get_resource method by providing the filename including its extension.

  8. Try out MetaDrive via command line

    main

    You can immediately test MetaDrive using pre-provided scripts.

    Important: Before running these scripts, ensure your current working directory does not contain a sub-folder named metadrive, as this may cause import conflicts.

    Single Agent Environment

    Run the following to drive using your keyboard:

    python -m metadrive.examples.drive_in_single_agent_env
    • Press T to start an "auto-drive" journey using a pre-trained RL agent.
    • Press H to view helper information and other shortcuts.

    Procedural Generation (PG)

    To see the map generation process via the PG algorithm:

    python -m metadrive.examples.procedural_generation

    To view multiple generated maps in a top-down view:

    python -m metadrive.examples.draw_maps

    Performance Profiling

    To verify the efficiency of MetaDrive:

    python -m metadrive.examples.profile_metadrive
    # Make sure current folder does not have a sub-folder named metadrive
    python -m metadrive.examples.drive_in_single_agent_env