【问题标题】:Calculate distance traveled by a vehicle in sumo with traCI4Matlab使用 traCI4Matlab 计算车辆在相扑比赛中行驶的距离
【发布时间】:2022-12-22 22:40:39
【问题描述】:

我需要一些帮助:我正在尝试计算在模拟结束时在 SUMO 场景中添加到 TRACI4Matlab 中的车辆行驶的距离。

使用我的代码,我可以计算距离,但一旦通过最后一个节点,因为在 SUMO 场景中不再有我的车辆,就会抛出错误: Error: Answered with error to command 0xa4: Vehicle 'prova' is not known. 这是我的 MATLAB 代码:

clear
close all
clc

import traci.constants


[scenarioPath,~,~] = fileparts(which(mfilename));
cd(scenarioPath);

traci.start('sumo-gui -c ./scenario1.sumocfg --start');

SIM_STEPS = [0 1000];
beginTime = SIM_STEPS(1);
duration =  SIM_STEPS(2);
endTime =  SIM_STEPS(1) +  SIM_STEPS(2) - 1;

traci.vehicle.add('prova', 'percorso1', depart='100')

for i = 1 : duration
    id{i}=(traci.vehicle.getIDList());
    d1(i)=traci.vehicle.getDistance('prova');
    traci.simulation.step();
end


traci.close()

我怎样才能继续模拟或避免错误?

【问题讨论】:

    标签: matlab sumo vehicle-routing traffic-simulation


    【解决方案1】:

    无法通过 traci 获取有关不再在模拟中的车辆的信息。您可以在路线的末端添加一个停靠点,或者只存储您注意到的最后一段距离。获取总路由长度的另一种方法是生成 XML 输出,例如 tripinfo 并解析它。

    【讨论】:

      猜你喜欢
      • 2020-10-05
      • 2019-05-05
      • 1970-01-01
      • 1970-01-01
      • 2020-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多