I need some help: I'm trying to calculate the distance traveled by a vehicle I added in TRACI4Matlab in a SUMO scenario at the end of the simulation.
With my code I can calculate the distance but once passed the last node, since there is no more my vehicle in the SUMO scenario the error is thrown:
Error: Answered with error to command 0xa4: Vehicle 'prova' is not known.
this is my MATLAB code:
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()
How can I continue the simulation or avoid the error?
There is no way to get information via traci about a vehicle which is not in the simulation anymore. You could add a stop to the end of the route or just store the last distance you noticed. A different way of getting total route length would be to generate XML output for instance tripinfo and parse it.