多个python客户端对象连接到一个相扑仿真 [英] Multiple python client objects connecting to one sumo simulation

查看:95
本文介绍了多个python客户端对象连接到一个相扑仿真的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是SUMO的新手。我有一个.net,一个.rou(包含300辆具有车辆驶离,id,路线边缘属性的车辆),一个.trip和一个表示交通场景的.sumoconfig文件。我想将这300辆车创建为python车辆对象,从包含其他功能的Vehicle类中生成以相互通信。他们如何动态连接到相扑并与场景中的那300辆车链接?我可以编写一个服务器来侦听这些对象并接受连接,但是将它们转发或链接到这些相扑场景工具的方式是什么?任何提示或引用或代码链接将不胜感激。

I am new in SUMO. I have a .net, a .rou (containing 300 vehicles with vehicle depart, id, route edges attributes), a .trip and a .sumoconfig file representing a traffic scenario. I want to create these 300 vehicles as python Vehicle object generating from a Vehicle class containing other functions to communicate with each other. How can they connect dynamically to sumo and get linked to those 300 cars in the scenario? I can write a server that listens for these objects and accepts connection but what is the way of forwarding or linking them to those sumo scenario vehicles? Any hint or reference or link to code will be highly appreciated.

推荐答案

与您要实现的目标最接近的示例可能是CityMobil教程,请参见 http://sumo.dlr.de/wiki/Tutorials/CityMobil ,但可以归结为以下内容:

The example which is closest to what you want to achieve is probably the CityMobil tutorial, see http://sumo.dlr.de/wiki/Tutorials/CityMobil but it boils down to something like that:

import traci
import traci.constants as tc

traci.start(["sumo", "my.sumocfg"])
traci.simulation.subscribe()
while True:
    moveNodes = {}
    traci.simulationStep()
    # update the position of all running vehicles
    for veh, subs in traci.vehicle.getAllSubscriptionResults().items():
        moveNodes[veh] = (subs[tc.VAR_ROAD_ID], subs[tc.VAR_LANEPOSITION])
    # add new departed vehicles
    for v in traci.simulation.getSubscriptionResults()[tc.VAR_DEPARTED_VEHICLES_IDS]:
        traci.vehicle.subscribe(v)
        subs = traci.vehicle.getSubscriptionResults(v)
        moveNodes[v] = (subs[tc.VAR_ROAD_ID], subs[tc.VAR_LANEPOSITION])

此为您提供了一张地图,其中存储了所有车辆的最新位置。请注意,地图是从头开始重建的,因此您无需担心离开车辆。如果您的车辆对象保留的时间更长,那么您将在没有更多订阅结果的情况下将其删除。

This gives you a map storing up to date positions for all vehicles. Please note that the map is rebuilt every step from scratch and thus you do not need to care about leaving vehicles. If your vehicle objects persist for longer you will need to delete them as soon as there are no more subscription results for them.

这篇关于多个python客户端对象连接到一个相扑仿真的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆