[英]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.我将 Carla 模拟器下载到我的 Windows PC,我正在尝试将 Carla 真实引擎链接到 python,但我不确定如何。 I want to be able to locate vehicles using python. How do we access the interface in python?
我想使用python定位车辆,我们如何访问python中的接口? Thank you!
谢谢!
So you need to launch CARLA and connect to a client then integrate the API...因此,您需要启动 CARLA 并连接到客户端,然后集成 API...
First , launch CARLA via command line using the executable in (Windows version)首先,使用(Windows 版本)中的可执行文件通过命令行启动 CARLA
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通过python API使用CARLA,需要将Python客户端通过一个端口连接到服务器,这样就可以连接和控制仿真了
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客户端object 只是客户端连接到服务器的实例,您将使用它来加载函数
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在您的情况下,如果您想使用world.get_actors()方法关注模拟中的所有车辆,您可以过滤掉车辆并使用set_autopilot()方法将车辆控制给交通管理器
for vehicle in world.get_actors().filter('vehicle'):
vehicle.setUautopilot(true)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.