Python API Use Case Examples

The LGSVL Simulator teams has created sample Python scripts that use the LGSVL Simulator Python API to test specific scenarios or perform certain tasks. These example scripts can be found on our Github here.

Please contact us if you would like to contribute examples that you are using, or submit a pull request.

Scenarios

We have created basic sample scenarios using the Python API. Several are based on the scenario specifications from OpenScenario.

The below scenarios assume that the simulator can be connected to an instance of Apollo 3.5. See the guide for getting connected with Apollo 3.5 here. The Apollo modules that need to be started are shown below (localization, perception, planning, prediction, routing, traffic light, transform, control):

It is recommended to start Apollo and the modules before running a scenario. Apollo's destination can be set after the scenario is started, but before it is run.

Lane Change

  • Script: scenario-lane-change.py
  • This scenario simulates an NPC suddenly changing lanes in front of the ego vehicle. Here the NPC uses the waypoint system to define its path. With waypoints, the NPC ignores other traffic and does not attempt to avoid collisions. This ensures that it changes lanes on command. The start of the scenario looks like this:

For this scenario, Apollo's destination can simply be the intersection in front of the ego vehicle:

Overtaker

  • Script: scenario-overtaker.py
  • This scenario simulates an NPC approaching the ego vehicle from behind at a faster speed. The NPC will change lanes to the left to pass the ego vehicle and will change lanes back once it has passed the ego vehicle. The way the ego vehicle reacts to an approaching NPC will affect when the NPC changes lanes so in this scenario the NPC follows the lanes in the HD map. The start of the scenario looks ike this:

Traffic Jam

  • Script: scenario-trafficjam.py
  • This scenario simulates the ego vehicle approaching stopped traffic. The traffic does not move and the ego vehicle is expected to stop at a safe distance. The start of the scenario looks like this:

For both Overtaker and Traffic Jam, the same destination can be given to Apollo. It is the end of the highway in the same lane the the ego vehicle is spawned in. This is quite far away and should ensure that the NPC in overtaker is able to pass the ego vehicle.

Other Uses

Collecting data in KITTI format

  • Script: kitti_parser.py
  • This script shows an example of collecting data in the KITTI format. This data can be used to train for detecting vehicles in images.
  • This script spawns the ego vehicle in a random position in the San Francisco map. Then a number of NPC vehicles are randomly spawned in front of the ego vehicle. Camera and ground truth data is saved in the KITTI format. This data can be used to train for detecting vehicles in images.
  • For more information on KITTI please see: http://www.cvlibs.net/datasets/kitti/index.php The data format is defined in a README file downloadable from: https://s3.eu-central-1.amazonaws.com/avg-kitti/devkit_object.zip