"# Quick Start Tutorial of Scenario Simulation\n",
"\n",
"Welcome to try out MetaDrive & ScenarioNet!\n",
"\n",
"The simulation supports two running modes:\n",
"\n",
"1. **With 3D rendering functionality**: MetaDrive can easily install and run in personal computer, but may need special treatments for 3D rendering in headless machine and cloud servers.\n",
"\n",
"2. **Without 3D rendering functionality**: MetaDrive can easily install and run in any machine. In this Colab notebook, we demonstrate MetaDrive in this mode and the renderer will be the **2D** **Pygame** renderer.\n",
"\n",
"In this tutorial, we will navigate you through the installation and some basic functionality of the simulator!"
"Let's import some modules and specify the dataset directory.\n",
"**Note: if your machine supports 3D OpenGL rendering, you can turn on the *threeD_render* flag in the following cell. It will render both the 2D results and 3D results.**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#@title Make some configurations and import some modules\n",
"os.listdir(waymo_data) # there are 3 waymo scenario file with a 'dataset_summary.pkl'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"os.listdir(nuscenes_data) # there are 10 nuscenes scenario file with a 'dataset_summary.pkl' and a 'dataset_summary.pkl'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Simulate one Waymo scenario\n",
"The simulation interface is in gym-style and let's create a environment first. \n",
"By specifying the *data_directory*, we can load the Waymo dataset to simulation. *num_scenarios* is used to determine how many scenarios are loaded from the datasets. Here we only load one scenario from the Waymo dataset."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"env = ScenarioEnv(\n",
" {\n",
" \"manual_control\": False,\n",
" \"reactive_traffic\": False,\n",
" \"use_render\": threeD_render,\n",
" \"agent_policy\": ReplayEgoCarPolicy,\n",
" \"data_directory\": waymo_data,\n",
" \"num_scenarios\": 1\n",
" }\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now the simulation can run with *env.step()* and *env.reset(seed=scenario-index)*. Their functions are as follows.\n",
"\n",
"- The *env.reset(seed=scenario-index)* tells the simulator to remove all existing objects created in last episode, create a new scenario with index *scenario-index* and start a new episode.\n",
"**As we only have one scenario loaded to the simulator, the *scenario-index* can only be 1 in this example.**\n",
"\n",
"\n",
"- *env.step()* will progress the simulation by one step (0.1 second) and return the new observation, reward and termination flag. It takes an action as input which is a 2-dim vector representing the throttle and steering angle for the ego car.\n",
"As we are using the *ReplayEgoCarPolicy* here, the ego car will not take the external action accepted from *env.step()*.\n",
"**Instead, the ego car will follow the recorded trajectory. Thus the following code is for playing one recorded scenario including maps and trajetcories.**"