简体   繁体   中英

How to establish data communication between Python and the Carla simulator?

I downloaded the Carla simulator to my Windows PC and I am trying to link Carla real engine to python but I am not sure how. I want to be able to locate vehicles using python. How do we access the interface in python? Thank you!

So you need to launch CARLA and connect to a client then integrate the API...

First , launch CARLA via command line using the executable in (Windows version)

cd /carla/root
./CarlaUE4.sh

You are going to the file directory then running the engine

To use CARLA through the python API, you need to connect the Python client to the server through a port so you can connect and control the simulation

import carla 
import random 

# Connecting to a client and retrieve the world object
client = carla.Client('localhost', 2000)
world = client.get_world()

The client object is just the instance of the client connection to the server which you would use to load functions

In your case, if you want to mind all the vehicles in the simulation using the world.get_actors() method, you can filter out vehicles and use the set_autopilot() method to control the vehicle to the traffic manager

for vehicle in world.get_actors().filter('vehicle'):
     vehicle.setUautopilot(true)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM