File Exchange

image thumbnail

TraCI4Matlab

version 3.0.0.0 (962 KB) by Andres Acosta
An implementation of the TraCI interface for Matlab.

58 Downloads

Updated 03 Jan 2019

View License

TraCI4Matlab is an implementation of the TraCI (Traffic Control Interface) protocol that allows the user to interact with SUMO (Simulation of Urban MObility, www.sumo-sim.org) in a client-server scenario in which Matlab acts as the client, and SUMO as the server. TraCI4Matlab is compatible with traci version 10 and previous versions.

Cite As

Andres Acosta (2019). TraCI4Matlab (https://www.mathworks.com/matlabcentral/fileexchange/44805-traci4matlab), MATLAB Central File Exchange. Retrieved .

Acosta, Andr{\'{e}}s F., et al. “{TraCI}4Matlab: Enabling the Integration of the {SUMO} Road Traffic Simulator and Matlab{\Textregistered} Through a Software Re-Engineering Process.” Modeling Mobility with Open Data, Springer International Publishing, 2015, pp. 155–170, doi:10.1007/978-3-319-15024-6_9.

View more styles

Comments and Ratings (65)

Long Nguyen

Hi,
I followed the manual to connect MATLAB to SUMO, but there is the error that is
Error using traci.Socket/connect (line 25)
Java exception occurred:
java.net.ConnectException: Connection refused: connect

at java.net.DualStackPlainSocketImpl.connect0(Native Method)

at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)

at java.net.AbstractPlainSocketImpl.connect(Unknown Source)

at java.net.PlainSocketImpl.connect(Unknown Source)

at java.net.SocksSocketImpl.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

Error in matlab.internal.lang.fwdSubsref (line 4)
[varargout{1:nargout}] = subsref(A,s);

Error in traci.init (line 65)
connections(label).connect(host, port);

Error in traci_test (line 19)
[traciVersion,sumoVersion] = traci.init();
Error using traci.Socket/connect (line 25)
Java exception occurred:
java.net.ConnectException: Connection refused: connect

at java.net.DualStackPlainSocketImpl.connect0(Native Method)

at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)

at java.net.AbstractPlainSocketImpl.connect(Unknown Source)

at java.net.PlainSocketImpl.connect(Unknown Source)

at java.net.SocksSocketImpl.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

Error in matlab.internal.lang.fwdSubsref (line 4)
[varargout{1:nargout}] = subsref(A,s);

Error in traci.init (line 65)
connections(label).connect(host, port);

Error in traci_test (line 19)
[traciVersion,sumoVersion] = traci.init();

I try to change the port 8873 to 8813 or 8813 to 8873, but it is ineffective. Can you help me to solve it?

Hello,

Sorry to bother you, I want to use traci.vehicle.subscribeContext to get status information about the vehicles on the left and right lanes of the current vehicle., but the return values are error,the following are my codes:

clear

close all

clc

import traci.constants

scenarioPath=['F:\software\SUMO配置文件\bin\quickstart\quickstart.sumocfg'];

system(['sumo-gui -c ' '"' scenarioPath '"' ' --remote-port 8813 --start&']);

traci.init

SIM_STEPS = [1 900];

beginTime = SIM_STEPS(1);

duration = SIM_STEPS(2);

endTime = SIM_STEPS(1) + SIM_STEPS(2) - 1;

for i = 1:duration

traci.simulation.step();

IDList{i,1} = traci.vehicle.getIDList();

% arrivedIDList= traci.simulation.getArrivedIDList();

for j=1:length(IDList{i,1})

[leaderVehicleID{i,1}, dist{i,1}] = traci.vehicle.getLeader(char(IDList{i,1}(1:end,j)),50);

accel{i,1}(j)=traci.vehicle.getAcceleration(char(IDList{i,1}(1:end,j)));

speed{i,1}(j)=traci.vehicle.getSpeed(char(IDList{i,1}(1:end,j)));

laneID{i,1}=traci.vehicle.getLaneID(char(IDList{i,1}(1:end,j)));

lastStepMeanSpeed{i,1}= traci.lane.getLastStepMeanSpeed(char(laneID{i,1}));

% length{i,1} = traci.lane.getLength(char(laneID{i,1}));

allowedSpeed{i,1}(j) = traci.vehicle.getAllowedSpeed(char(IDList{i,1}(1:end,j)));

laneIndex{i,1} = traci.vehicle.getLaneIndex(char(IDList{i,1}(1:end,j)));

roadID{i,1} = traci.vehicle.getRoadID(char(IDList{i,1}(1:end,j)));

lanePosition{i,1}(j) = traci.vehicle.getLanePosition(char(IDList{i,1}(1:end,j)));

minGap{i,1}(j) = traci.vehicle.getMinGap(char(IDList{i,1}(1:end,j)));

angle{i,1}(j) = traci.vehicle.getAngle(char(IDList{i,1}(1:end,j)));

% Subscribe to the vehicle ID around the left lane of the current vehicle

traci.vehicle.subscribeContext(char(IDList{i,1}(1:end,j)),traci.constants.CMD_GET_VEHICLE_VARIABLE,150,{traci.constants.VAR_LANEPOSITION, traci.constants.VAR_SPEED});

traci.vehicle.addSubscriptionFilterLanes(1);

traci.vehicle.addSubscriptionFilterLeadFollow(1);

leftcontextSubscriptionResults{i,1}=traci.vehicle.getContextSubscriptionResults(char(IDList{i,1}(1:end,j)));

leftsurround_vehicle{i,1}=keys(leftcontextSubscriptionResults{i,1});

% Subscribe to the lane ID around the right lane of the current vehicle

traci.vehicle.subscribeContext(char(IDList{i,1}(1:end,j)),traci.constants.CMD_GET_VEHICLE_VARIABLE,150,{traci.constants.VAR_LANEPOSITION, traci.constants.VAR_SPEED});

traci.vehicle.addSubscriptionFilterLanes(-1);

traci.vehicle.addSubscriptionFilterLeadFollow(-1);

rightcontextSubscriptionResults{i,1}=traci.vehicle.getContextSubscriptionResults(char(IDList{i,1}(1:end,j)));

rightsurround_vehicle{i,1}=keys(rightcontextSubscriptionResults{i, 1});

% Subscribe to the lane ID around the current lane

traci.vehicle.subscribeContext(char(IDList{i,1}(1:end,j)),traci.constants.CMD_GET_VEHICLE_VARIABLE,150,{traci.constants.VAR_LANEPOSITION, traci.constants.VAR_SPEED});

traci.vehicle.addSubscriptionFilterLanes(0);

traci.vehicle.addSubscriptionFilterLeadFollow(0);

CurrentcontextSubscriptionResults{i,1}=traci.vehicle.getContextSubscriptionResults(char(IDList{i,1}(1:end,j)));

Currentsurround_vehicle{i,1}=keys(CurrentcontextSubscriptionResults{i, 1});

end

end

traci.close()

But the returned values of Currentsurround_vehicle, rightsurround_vehicle, leftsurround_vehicle are the same,can anyone give me some help for it. Looking forward to your reply.

Grant

This is a great submission, thank you.

One note, line 19 of +traci\+edge\getAdaptedTraveltime.m should be
adaptedTraveltime = result.readDouble();

Hosi Nm

Dear Andres
I am working on implementing a control strategy using TRACI4MATLAB in sumo. However I have trouble calculating the remaining phase time for the traffic lights. I use the command "traci.trafficlights.getNextSwitch('0')*0.001-traci.simulation.getTime()", unfortunately it returns the wrong value. I have tracked the problem and I'm guessing that something is wrong with the "traci.trafficlights.getNextSwitch" function. By the way I have defined a switch time program for the traffic light using a WAUT. I will be glad to receive any recommendations to help solving this problem.
Regards
Hosi

Just tried to start the traci_test program, but get this error:

Could not connect to TraCI server at 127.0.0.1:≭. Error using fprintf
Unable to convert 'MException' value to 'char'.

Error in traci.connect (line 47)
fprintf('Could not connect to TraCI server at %s:%s. %s\n', host, port, err);

Error in traci.start (line 62)
connections(label) = traci.connect(port, numRetries, host);

Error in traci_test (line 22)
[traciVersion,sumoVersion] = traci.start(['sumo -c ' '"' scenarioPath '"']);

So I can't initialize a connection... do u guys know how to solve my problem? Just installed everything as in the docu...
Thx

Mun Chon Ho

trafficLight.getNextSwitch() and trafficLight.getPhaseDuration() return wrong values because of the double conversion

Seho Han

Dear Andreas
I used this command "traci.vehicle.getAcceleration(VehId)" and I got this error "Undefined variable "traci" or class "traci.vehicle.getAcceleration"". I updated the library traci4matlab by downloading the last version but still does not work. Is there anything else should I do ?
By the way, this command works fine "traci.vehicle.getAccel(VehId)" but I need the accelaration of each vehicle in every time step.

Hello Andreas
i execute traci_test2 just fine.
the weird think is in contains traci.trafficligths.setRedYellowGreenState function
but when i try to use this function in my matlab function the simulation freezes and i get this error message on matlab command window:

"
Undefined variable "traci" or class "traci.trafficligths.setRedYellowGreenState".
Error in oneintersect(line 61)
traci.trafficligths.setRedYellowGreenState('n2', phase_seq(j+1,:));
"
what do you think might be the problem?

chaoyi chen

Also, recall that the default port is now 8813.

chaoyi chen

hi Andres,
Thanks for your kindly updating, but i still find something wrong with traci.init and traci.start.
Error in this line:
[traciVersion,sumoVersion] = traci.init();
connections(label).connect(host, port);
I think it's something with the IP address and port. I use matlab 2018B and the latest SUMO version, i have tested to run SUMO in python and it works just fine.
Thank you again!

Dear Adnan,
I just tested the command with the traci_test2.m script and it works fine. Please make sure you have the latest TraCI4Matlab version. A minimal example would look like this, in the main loop of the traci_test2.m file:

while traci.simulation.getMinExpectedNumber() > 0
traci.simulation.step();
vehicles = traci.vehicle.getIDList();
if ismember(testVehicle, vehicles)
vehWaitingTime = traci.vehicle.getWaitingTime(testVehicle)
end
end

Best Regards.

When i try to use getWaitingTime function the simulation crashes and i get this message:

Error using containers.Map/subsref
The specified key is not present in this container.

Error in traci.edge.getUniversal (line 22)
handleReturValueFunc = str2func(ReturnValueFunc(varID));

Error in traci.edge.getWaitingTime (line 12)
waitingTime = traci.edge.getUniversal(constants.VAR_WAITING_TIME, edgeID);

New update, version 3.0.0.0. Update for SUMO Version 1.1.0 (TraCI version 19), including the following improvements:
- Implemented all missing commands from SUMO version 0.30.0, including the vehicle filter context commands
- Now traci accepts time arguments as double-valued integers in seconds, which fixed the traci.simulationStep command
- New traci.start command, which facillitates instantiation
- Improved error management and argument validation in several commands

Peter Riegl

Hello everyone,
when I run the examples inter_palmas_actuated.m and traci_test2.m I got in SUMO the error:
Error: tcpip::Storage::readIsSafe: want to read 8 bytes from Storage, but only 4 remaining
Quitting (on error).

In Matlab I got the error:
Error using traci.recvExact (line 35)
Java exception occurred:
java.io.EOFException
at java.io.DataInputStream.readInt(Unknown Source)
Error in traci.sendExact (line 23)
result = traci.recvExact();
Error in traci.simulationStep (line 43)
result = traci.sendExact();
Error in traci_test2 (line 307)
traci.simulationStep();

Has I anybody an idea how ti solve this problem?

Thank a lot

Yevhen

Hello everyone.
I have a problem with traci.simulationStep();
Fro example I use test example inter_palmas_actuated . But whenever I launch any script contaning traci.simulationStep(); I get following error in SUMO:

Error: tcpip::Storage::readIsSafe: want to read 8 bytes from Storage, but only 4 remaining
Quitting (on error).

and next error is shown in Matlab:

Error using traci.recvExact (line 35)
Java exception occurred:
java.io.EOFException

at
java.io.DataInputStream.readInt(DataInputStream.java:392)

Error in traci.sendExact (line 23)
result = traci.recvExact();

Error in traci.simulationStep (line 43)
result = traci.sendExact();

Error in inter_palmas_actuated (line 65)
traci.simulationStep();

I would really apreciate to get some help with that problem
Thanks

Hi I have problem with adding TraCI4Matlab, Can anybody help me please?

Hi Andres,

I am trying to use function rerouteParkingArea(), but i can't find it any where even in the constant file is not defined,..
is it not implemented in matlab? and if so could you help me to implement it...
Thanks

Semaria Ruiz

abdo housni

j pas compris
jai besoin d'aide svpl
Error: tcpip::Socket::accept() Unable to create listening socket: Address already in use
Quitting (on error).

To be more precise, the aim is to allow two-way communication between SUMO and Matlab at each time step.

Hi Andres,
I install SUMO and added TraCl4Matlab.The test-files runs successfully,but When I run my edited file quickstart.m following messages is given:
Error using traci.Socket/connect (line 25)
Java exception occurred:
java.net.ConnectException: Connection refused: connect

at java.net.DualStackPlainSocketImpl.connect0(Native Method)

at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)

at java.net.AbstractPlainSocketImpl.connect(Unknown Source)

at java.net.PlainSocketImpl.connect(Unknown Source)

at java.net.SocksSocketImpl.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

Error in traci.init (line 65)
connections(label).connect(host, port);

Error in quickstart (line 19)
traci.init(8813);

This is my sumo- quickstart.configuration file:
<?xml version="1.0" encoding="iso-8859-1"?>
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://sumo.sf.net/xsd/sumoConfiguration.xsd">
<input>
<net-file value="quickstart.net.xml"/>
<route-files value="quickstart.rou.xml"/>
</input>

<time>
<begin value="54000"/>
<end value="54900"/>
</time>

<report>
<verbose value="true"/>
<no-step-log value="true"/>
</report>

<traci_server>
<remote-port value="8813"/>
</traci_server>

</configuration>

And this is my quickstart.m file:
clear
close all
clc

import traci.constants

% Get the filename of the example scenario
[scenarioPath,~,~] = fileparts(which(mfilename));
% scenarioPath = [scenarioPath '\inter_palmas'];
cd(scenarioPath);

system(['sumo-gui -c ' './quickstart.sumocfg &']);

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

traci.init(8813);

Kunyue Du

Hi Andres,
I am trying use some command about sublane model, for example changeSublane, but it doesn't work, is it not implemented in matlab?

How can i link this with SUMO ?

Dear Pradeep Kumar.

I have fixed this issue in the lastest version, i.e. version 2.9. Thanks for noticing it.

Best Regards.

Hello Andres Acosta and others,
Firstly thanks for the update. But please note that in the latest version 2.8, constants are incorrect for vehicle moveTo command. Instead of VAR_MOVE_TO_VTD it is defined as MOVE_TO_XY while in traci.vehicle.moveToXY() function VAR_MOVE_TO_VTD is used and not MOVE_TO_XY.

Mun Chon Ho

Hi Andres,
There are some simulation command missing such as saving state.
http://www.sumo.dlr.de/daily/pydoc/traci._simulation.html#SimulationDomain-saveState

Fried Rice

Mun Chon Ho

Dear Mr. Duc Le.

We have developed an implementation of the sumolib library for Java/Matlab:
https://www.mathworks.com/matlabcentral/fileexchange/51967-sumolib4matlab

The Net class has the convertLonLat2XY method which is what you are looking for. We hope to document this library soon, but you can find the documentation of the corresponding python implementation useful (http://sumo.dlr.de/wiki/Tools/Sumolib). Additionally, there is an example: net_test.m.

Duc Le

Hi,

I want to add a PoI to the SUMO network using to traci.poi.add(poiID, x, y, color...). However, I have only position of PoI in lat/lon-coordinates.
Is there any equation which I can apply to convert the lat/lon-coordinates to xy-coordinates? Then add the PoI to the network using the converted xy-coodinates.

Thanks.

Dear Sebastian.

We have updated TraCI4Matlab in the update 2.7, including some vehicle commands.

Best Regards,

Is there a changelog? I can't find any... Can somebody help?
Thanks for all the work with T4M!

jia xu

Duc Le

Dear All,

I want to get the CO2 concentration value of a particular position p(x, y) in the simulation area during the simulation time? This value may be sum of CO2 emission values of all vehicles, which currently are located within the given range centered at the position p(x, y).

I would appreciate much if you would provide me any suggestion on this problem?

Best regards,
Duc Van Le.

As an help to others. I followed Andres Acosta's instruction to add traci4matlab.jar to Matlab's' static java path file (scroll down for the link he gave).

Thereafter, I successfully tested with \examples\inter_palmas\tls_actuated\inter_palmas_actuated.m per his directive.

I will advise that these information be included in \TraCI4Matlab_User_Manual.pdf

Thanks to all.

PS: SUMO version 0.29.0.

gleepglorp

Dear Andres:
I have a problem with the example interpalmas.sumocfg communication is established by port 8873, but the sumo-gui does not run. And print the message: "simulation ended at time 50400 reason traci requested termination" could you help me please thanks.

Dear Hemant
You can find the log file in the same directory where the scenario is located. Can you give us more information about the error?

Regards.

Dear Andres,
I am trying to run the examples given in the folders. SUMO starts but simulation doesnt run even after pressing the play button in the SUMO itself and there is some error after some time and it tells me to see the log file. I don't know why its happening and I don't know where this log file is?

Pablo Báez

Dear Andres,

In the current Traci/Vehicle Value Retrieval specification command with id 0x71 is designed as electricity consumption, with its associated instruction getElectricityConsumption.
As this instruction is not yet specifically implemented in the last version of traci4matlab (0x71 is defined in constants.m as VAR_LOADED_VEHICLES_NUMBER), I would like to know if doing a getUniversal with 0x71 as command would return the actual electricity consumption, or if there is any other solution.

Thank you in advance for your kind attention and for all the work you've shared.

Dear Andres,
Thank you for your suggestions and support. SUMO call works fine.

I wanted to ask you if we can get some tips about your tracitest2. More specific consider 1 intersection with 1 green light and others red in each cycle, i set up

NGREEN = 'GGGGrrrrrrrrrrrr';
NYELLOW = 'yyyyrrrrrrrrrrrr';
SGREEN = 'rrrrGGGGrrrrrrrr';
SYELLOW = 'rrrryyyyrrrrrrrr';
WGREEN = 'rrrrrrrrrrrrGGGG';
WYELLOW = 'rrrryyyyrrrryyyy';
EGREEN= 'rrrrrrrrGGGGrrrr';
EYELLOW= 'rrrrrrrryyyyrrrr';

PROGRAM = {NGREEN,NYELLOW,SGREEN,SYELLOW,WGREEN,WYELLOW,EGREEN,EYELLOW};

but in simulation all of my lights are red except south road which is yellow constantly.

Do you have any suggestions or maybe i misunderstand something ?!

Thank you in advance for your assistance.

Dear Stelios

We recommend to verify TraCI4Matlab starting with the example found at \examples\inter_palmas\tls_actuated\inter_palmas_actuated.m, before trying the traci_test2.m example, since the latter implies to run the ''TraCI for Traffic Lights'' SUMO tutorial using the Python client.

Regards

For those experiencing problems with MATLAB:UndefinedFunctionUndefined function 'DataReader', please add traci4matlab.jar to your static java path file, as explained in https://www.mathworks.com/help/matlab/matlab_external/bringing-java-classes-and-methods-into-matlab-workspace.html#f111065

Best Regards

Update, i've got no errors.

I just cant see any simulation. SUMO starts and stays at time 0 till the following messages appear on matlab :

MATLAB:UndefinedFunctionUndefined function 'DataReader' for input arguments of type 'java.io.DataInputStream'.

Attempt to reference field of non-structure array.
Error in traci.sendExact (line 19)
activeConnection.dos.writeInt(len);
Error in traci.getVersion (line 23)
result = traci.sendExact();
Error in traci.init (line 75)
[traciVersion,sumoVersion] = traci.getVersion();
Error in traci_test2 (line 72)
traci.init();

Hello.

I'm trying to use your "library" for my simulations but i experience some problems. First of all i wanted to ask you whether the port number is 8813 or 8873(in your code port is 8873) but in your sumoconf you set at 8813 ?

Other errors are:
Error using traci.Socket/connect (line 25)
Error in traci.init (line 65)
Error in traci_test2 (line 72)

PS. I am sure that this library should be extremely useful for Research Com.

PS2. I'm thinking that if you had not contributed with this package, in this stage of my thesis i should also develop the connection between them so i really appreciate your work !!!

Hi,
I have same problem as A.F.M. Shahen Shah mentioned before. Does anyone know how to solve this problem?

Thank you in advance

Earlier time there was huge errors in MATLAB. There was problems with Java as Ilhan Sir told me because a lot of errors was showed related to java. Then I update Java in my computer and then I run the test file again. Now I get very few errors which are given below.

MATLAB:UndefinedFunctionUndefined function 'DataReader' for input arguments of type 'java.io.DataInputStream'.
Attempt to reference field of non-structure array.

Error in traci.sendExact (line 19)
activeConnection.dos.writeInt(len);

Error in traci.getVersion (line 23)
result = traci.sendExact();

Error in traci.init (line 75)
[traciVersion,sumoVersion] = traci.getVersion();

Error in traci_test2 (line 72)
traci.init();

I think there is problem with traci file. Please give me some suggestion in this regards.

hi,
i have install matlab and SUMO and added traci, when i run traci_test2.m; the SUMO graph display but without vehicles and in matlab display the following message:

MATLAB:UndefinedFunctionUndefined function 'DataReader' for input arguments of type 'java.io.DataInputStream'.
Attempt to reference field of non-structure array.

Error in traci.sendExact (line 19)
activeConnection.dos.writeInt(len);

Error in traci.getVersion (line 23)
result = traci.sendExact();

Error in traci.init (line 75)
[traciVersion,sumoVersion] = traci.getVersion();
Error in traci_test2 (line 72)
traci.init();

I install SUMO and added TraCl4Matlab. But when I run script traci_test2.m following message is given:

Error using traci.Socket/connect (line 25)
Java exception occurred:
java.net.ConnectException: Connection refused: connect

at java.net.DualStackPlainSocketImpl.connect0(Native Method)

at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)

at java.net.AbstractPlainSocketImpl.connect(Unknown Source)

at java.net.PlainSocketImpl.connect(Unknown Source)

at java.net.SocksSocketImpl.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

Error in traci.init (line 65)
connections(label).connect(host, port);

Error in traci_test2 (line 72)
traci.init();

Error using traci.Socket/connect (line 25)
Java exception occurred:
java.net.ConnectException: Connection refused: connect

at java.net.DualStackPlainSocketImpl.connect0(Native Method)

at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)

at java.net.AbstractPlainSocketImpl.connect(Unknown Source)

at java.net.PlainSocketImpl.connect(Unknown Source)

at java.net.SocksSocketImpl.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

Error in traci.init (line 65)
connections(label).connect(host, port);

Error in traci_test2 (line 72)
traci.init();

Error using traci.Socket/connect (line 25)
Java exception occurred:
java.net.ConnectException: Connection refused: connect

at java.net.DualStackPlainSocketImpl.connect0(Native Method)

at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)

at java.net.AbstractPlainSocketImpl.connect(Unknown Source)

at java.net.PlainSocketImpl.connect(Unknown Source)

at java.net.SocksSocketImpl.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

Error in traci.init (line 65)
connections(label).connect(host, port);

Error in traci_test2 (line 72)
traci.init();

Error using traci.Socket/connect (line 25)
Java exception occurred:
java.net.ConnectException: Connection refused: connect

at java.net.DualStackPlainSocketImpl.connect0(Native Method)

at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)

at java.net.AbstractPlainSocketImpl.connect(Unknown Source)

at java.net.PlainSocketImpl.connect(Unknown Source)

at java.net.SocksSocketImpl.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

Error in traci.init (line 65)
connections(label).connect(host, port);

Error in traci_test2 (line 72)
traci.init();

Error using traci.Socket/connect (line 25)
Java exception occurred:
java.net.ConnectException: Connection refused: connect

at java.net.DualStackPlainSocketImpl.connect0(Native Method)

at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)

at java.net.AbstractPlainSocketImpl.connect(Unknown Source)

at java.net.PlainSocketImpl.connect(Unknown Source)

at java.net.SocksSocketImpl.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

Error in traci.init (line 65)
connections(label).connect(host, port);

Error in traci_test2 (line 72)
traci.init();

Error using traci.Socket/connect (line 25)
Java exception occurred:
java.net.ConnectException: Connection refused: connect

at java.net.DualStackPlainSocketImpl.connect0(Native Method)

at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)

at java.net.AbstractPlainSocketImpl.connect(Unknown Source)

at java.net.PlainSocketImpl.connect(Unknown Source)

at java.net.SocksSocketImpl.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

Error in traci.init (line 65)
connections(label).connect(host, port);

Error in traci_test2 (line 72)
traci.init();

Error using traci.Socket/connect (line 25)
Java exception occurred:
java.net.ConnectException: Connection refused: connect

at java.net.DualStackPlainSocketImpl.connect0(Native Method)

at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)

at java.net.AbstractPlainSocketImpl.connect(Unknown Source)

at java.net.PlainSocketImpl.connect(Unknown Source)

at java.net.SocksSocketImpl.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

Error in traci.init (line 65)
connections(label).connect(host, port);

Error in traci_test2 (line 72)
traci.init();

MATLAB:Java:GenericExceptionJava exception occurred:
java.net.SocketException: Socket is not connected

at java.net.Socket.getInputStream(Unknown Source)

Attempt to reference field of non-structure array.

Error in traci.sendExact (line 19)
activeConnection.dos.writeInt(len);

Error in traci.getVersion (line 23)
result = traci.sendExact();

Error in traci.init (line 75)
[traciVersion,sumoVersion] = traci.getVersion();

Error in traci_test2 (line 72)
traci.init();

I recently found out that sumo has a functionality that can yield data concerning the upcoming TLS from the SUMO wiki page (link below)
http://sumo.dlr.de/wiki/TraCI/Vehicle_Value_Retrieval

I am currently using TracI4Matlab to conduct my simulations (co-simulation between MATLAB and SUMO). I am unable to find the 'getNextTLS' function in TraCI. It also turns out that the variable ubyte corresponding to this signal ('0x70') is being used by some other function. Makes me wonder if this functinality exists in SUMO at all.

Has any one managed to use this tool? If so how did you implement it?

Thanks in advance,

Regards,
Avinash

Hello all,

I finished the installation of SUMO and followed the instructions as in the user manual in TraCI4Matlab.

when I run the traci_test2.m file to
test TraCI4Matlab I am getting the following error

"Attempt to reference field of non-structure array.

Error in traci.sendExact (line 19)
activeConnection.dos.writeInt(len);

Error in traci.getVersion (line 23)
result = traci.sendExact();

Error in traci.init (line 75)
[traciVersion,sumoVersion] = traci.getVersion();

Error in traci_test2 (line 67)
traci.init();"

Can anyone help me with this ?

Thanks in advance.

Kevin

After the addition of Electric Vehicles, i needed a way to access the specific Parameters like actualBatteryCapacity and what not; so i added 2 scripts (getParameter and setParameter), which can be used to access and set those Parameters (and more if needed):

function paramValue = getParameter(vehID, paramName)

import traci.constants
global message

traci.beginMessage(constants.CMD_GET_VEHICLE_VARIABLE, constants.VAR_PARAMETER,...
vehID, 1+4+length(paramName));
message.string = [message.string uint8(sscanf(constants.TYPE_STRING,'%x')) ...
traci.packInt32(length(paramName)) uint8(paramName)];

paramValue = traci.checkResult(constants.CMD_GET_VEHICLE_VARIABLE, constants.VAR_PARAMETER, vehID).readString();

and

function setParameter(vehID, paramName, paramValue)
%setParameter set a Parameter for a vehicle

import traci.constants
global message

traci.beginMessage(constants.CMD_SET_VEHICLE_VARIABLE, constants.VAR_PARAMETER,...
vehID, 1+4+1+4+length(paramName)+1+4+length(paramValue));
message.string = [message.string uint8(sscanf(constants.TYPE_COMPOUND,'%x')) ...
traci.packInt32(2)];
message.string = [message.string uint8(sscanf(constants.TYPE_STRING,'%x')) ...
traci.packInt32(length(paramName)) uint8(paramName)];
message.string = [message.string uint8(sscanf(constants.TYPE_STRING,'%x')) ...
traci.packInt32(length(paramValue)) uint8(paramValue)];
traci.sendExact();

just call
actBatCap = traci.vehicle.getParameter(vehID, 'actualBatteryCapacity');

Michael

I use it on win and mac.
On mac I had to slightly fix the traci.init, due to problems with the generation of javapath needs platform dependent fileseperators.

the following worked for me (modified lines at the beginning of the traci.init)

isInPath = ismember(dynJavaPath,fullfile(fileparts(pathstr),'traci4matlab.jar'));
if(~any(isInPath) || isempty(isInPath))
javaaddpath(fullfile(fileparts(pathstr),'traci4matlab.jar'));
end

pencil

New version of Sumo has defined Electric Vehicle and Charging Station,so I am wondering how to get and set EV's parameters like actualBatteryCapacity

Dear Mr Sharan. Thank you so much for your contribution. It will be fixed in the next traci4matlab version. Additionally, we apologize for the late response.

Best Regards!

In setLaneChangeMode.m there is bug. Please update that file with the line mentioned below:

traci.sendIntCmd(constants.CMD_SET_VEHICLE_VARIABLE, constants.VAR_LANECHANGE_MODE, vehID, lcm);

Here VAR_LANECHANGEMODE is replaced by VAR_LANECHANGE_MODE.

Yuksel

Updates

3.0.0.0

Update for SUMO Version 1.1.0 (TraCI version 19):
- Included and tested all missing commands from SUMO version 0.30.0
- Now traci accepts time arguments as double-valued integers in seconds, fixing the traci.simulationStep command.

2.9.0.0

Fixed the moveToXY.m command of the vehicle package and implemented the getPhaseDuration.m command of the trafficlights package, thanks to Lawrence Soon.

2.8.0.0

Corrections to the new implemented commands

2.7.0.0

New traci.vehicle commands added

2.6.0.0

Removed old documentation and added two vehicle commands:
- moveToXY.m: Thanks to Steffen Kutter and Mario Krumnow
- setTypeID.m: Thanks to Marcus Müller

2.5.0.0

Removed old documentation and added two vehicle commands:
- moveToXY.m: Thanks to Steffen Kutter and Mario Krumnow
- setTypeID.m: Thanks to Marcus Müller

2.4.0.0

Updated documentation

2.3.0.0

Updated the examples folder

2.2.0.0

Fixed traci_test2.m

2.1.0.0

Added vehicle commands getStopState and resume. Corrected issues in traci_test.m.

2.0.0.0

-Fixed a bug in RETURN_VALUE_FUNC.m for lane commands, thanks to Babangida Zachariah
-Support for Traci version 10

1.9.0.0

Made some corrections for traci version 10, specifically the setAllowed.m add.m and moveToVTD.m commands. Also, made some modifications for supporting multiple connections to several SUMO instances.

1.8.0.0

Updated the vehicle property in the RETURN_VALUE_FUNC.m constants, thanks to Marcus Müller.

1.7.0.0

Updated the screenshot

1.7.0.0

Major update. TraCI4Matlab now supports TraCI version 9, including the pedestrian commands and a new test scenario for pedestrians. Other update notes include:
-Performance improvements
-Improved documentation

1.6.0.0

Included the compatibility with traci version 8 and previous versions in the description.

1.5.0.0

Updated to support SUMO release 0.20.0, including lane areal detectors. Included a user's manual.

1.4.0.0

Corrected a license issue

1.2.0.0

Changed the traci_test script to make it more easy to run.

1.1.0.0

Bug correction in the traci_test.m script.

MATLAB Release Compatibility
Created with R2012b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.


Learn About Live Editor

traci4matlab/+traci

traci4matlab/+traci/+edge

traci4matlab/+traci/+gui

traci4matlab/+traci/+inductionloop

traci4matlab/+traci/+junction

traci4matlab/+traci/+lane

traci4matlab/+traci/+lanearea

traci4matlab/+traci/+multientryexit

traci4matlab/+traci/+person

traci4matlab/+traci/+poi

traci4matlab/+traci/+polygon

traci4matlab/+traci/+route

traci4matlab/+traci/+simulation

traci4matlab/+traci/+trafficlights

traci4matlab/+traci/+vehicle

traci4matlab/+traci/+vehicletype

traci4matlab/examples

traci4matlab/examples/inter_palmas

traci4matlab/examples/inter_palmas/tls

traci4matlab/examples/inter_palmas/tls_actuated