Python调用Sumo接口示例

#配置导入库目录
import sys
import os
sys.path.append("F:/install/Sumo/tools") 
#配置调用目录
sumoBinary = "F:/install/Sumo/bin/sumo-gui"
sumoCmd = [sumoBinary, "-c", "F:/install/Sumo/tools/game/square.sumocfg"]

#导入traci模块
import traci

traci.start(sumoCmd) 

step = 0
isAdd=True
while step < 2000:

   traci.simulationStep()
   if traci.simulation.getTime() > 20:

       if isAdd==True :
        #获取编号为0的车辆路线id
        #trip000= traci.vehicle.getRouteID("0")
        #添加路线,编号为trip000,路线包含边'right0to1/0', '1/0to1/1', '1/1toright1'
        traci.route.add("trip000", ['right0to1/0', '1/0to1/1', '1/1toright1'])
        #输出编号“0”的车辆路线
        print( traci.vehicle.getRoute("0"))
        #添加车辆,车辆id为"newVeh",沿路线 "trip000"行驶
        traci.vehicle.add("newVeh", "trip000")
        isAdd=False
       #设置"newVeh"的速度
       traci.vehicle.setDecel("newVeh", 10)
       #设置"newVeh"的颜色,暂未起作用
       colora=(125,255,255,255)
       traci.vehicle.setColor("newVeh",colora)
       #设置"newVeh"的长度
       traci.vehicle.setLength("newVeh",10)
       #获取"newVeh"当前位置
       #print(traci.vehicle.getPosition3D("newVeh"))
   step += 1


   

  • 3
    点赞
  • 47
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值