Sumo Traci在windows和ubuntu系统下的通信(与python接口)

1 Ubuntu系统下

https://blog.csdn.net/renguoqing1001/article/details/52743255

 

本系统为ubuntu 17.10 采用 sudo apt-get install sumo sumo-tools安装sumo

这样的问题是 系统没有SUMO_HOME环境变量,在按照官网的教程中无法寻找到相关的环境变量。

因此在 写代码之前先加入SUMO_HOME这个环境变量。

第一步: Ubuntu17.10系统下加入SUMO_HOME环境变量

 exprot SUMO_HOME= '/usr/share/sumo/tools'

第二步:

import sys,os,subprocess
sys.path.append('/usr/share/sumo/tools') #import traci,sumolib
sumoBinary = "/usr/bin/sumo" #sumo or sumo-gui connection

import traci

第三步:

PORT=8813
sumoProcess = subprocess.Popen([sumoBinary , "-c", "sumo_config/heping.sumocfg", \
#    "--remote-port", str(PORT), "--xml-validation", "never"],stdout=sys.stdout, stderr=sys.stderr, )
traci.init(self.PORT)
.......
traci.close()

 

 

 

2 Windows平台下:

参考:http://www.sumo.dlr.de/userdoc/TraCI/Interfacing_TraCI_from_Python.html

第一步:准备sumo-home环境变量并导入相关模块:

import sys,os
# sumo related modules
try:
    sys.path.append(os.path.join(os.path.dirname(
        __file__), '..', '..', '..', '..', "tools"))  # tutorial in tests
    sys.path.append(os.path.join(os.environ.get("SUMO_HOME", os.path.join(
        os.path.dirname(__file__), "..", "..", "..")), "tools"))  # tutorial in docs

except ImportError:
    sys.exit(
        "please declare environment variable 'SUMO_HOME' as the root directory of your sumo installation (it should contain folders 'bin', 'tools' and 'docs')")
sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))

import traci
import sumolib

第二步: python和traci串口通信 开启

sumoBinary = "/path/to/sumo-gui"
# 此处sumo-gui 和 sumo按照需求使用
sumoCmd = [sumoBinary, "-c", "yourConfiguration.sumocfg"]

traci.start(sumoCmd)
  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值