简体   繁体   English

Python如何与Carla模拟器建立数据通信?

[英]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.

相关问题 Carla 模拟器中的 XMLSchemaChildrenValidationError (Python 3.7) - XMLSchemaChildrenValidationError in Carla simulator (Python 3.7) 如何在 C# 和 python 应用程序之间建立快速通信? - How to establish fast communication between C# and python apps? 如何在android设备和python脚本之间建立通信? - How can I establish a communication between an android device an a python script? 如何在Linux上运行的python脚本与Windows上运行的.NET C#应用程序之间建立通信? - How to establish communication between a python script running on Linux with a .NET C# application running on windows? 如何在Google App Engine上建立flex和python代码之间的通信 - How to establish communication between flex and python code build on Google App Engine Python如何在对象之间建立相等? - How does Python establish equality between objects? 用于线程之间通信的Python数据持久对象 - Python data persistent object for communication between threads 如何将 Carla 的相机数据保存到我的磁盘? - How do I save the camera Data of Carla to my disk? 如何使用 PYTHON SOCKETS 在同一网络中的两个设备之间建立连接? - How to establish a connection between two devices in the same network with PYTHON SOCKETS? 如何在 Java 和 Python 之间创建 2 路通信 - How to create a 2 way communication between Java and Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM