0

I’m very much a novice at both SUMO and Traci4J, however, I am interested in learning how to use these tools. I have ran into a problem when running virtually anything on Traci4J. When performing nextSimStep() on a SumoTraciConnection object I am met with the error

it.polito.appeal.traci.TraCIException$UnexpectedData: Unexpected command/status ID: expected 164, got 2

I cannot find any reason for this occurring, I have attempted it on 2 machines with a clean install of both the latest version of SUMO, the latest version of Traci4J, and Java SE 1.7.

Main method

    public static void main(String[] args) {
    SumoTraciConnection sumo;

    sumo = new SumoTraciConnection(URL_TO_SUMOCFG, (int) System.nanoTime());
    sumo.addOption("start", "1");
    try {
        sumo.runServer(true);
        sumo.nextSimStep();
        sumo.close();
    }catch(IOException | InterruptedException e) {
        e.printStackTrace();
    }
}

hello.sumocfg File

<input>
    <net-file value="hello.net.xml"/>
    <route-files value="hello.rou.xml"/>
</input>

<time>
    <begin value="0"/>
    <end value="10000"/>
</time>

<gui_only>
    <gui-settings-file value="hello.settings.xml"/>
</gui_only>

hello.net.xml File

<?xml version="1.0" encoding="UTF-8"?>
-->

<location netOffset="250.00,0.00" convBoundary="0.00,-71.61,501.00,0.00" origBoundary="-250.00,0.00,251.00,0.00" projParameter="!"/>

<edge id=":2_0" function="internal">
    <lane id=":2_0_0" index="0" speed="13.90" length="0.10" shape="500.00,-1.65 500.00,-1.65"/>
</edge>

<edge id="1to2" from="1" to="2" priority="-1">
    <lane id="1to2_0" index="0" speed="13.90" length="500.00" shape="0.00,-1.65 500.00,-1.65"/>
</edge>
<edge id="gneE0" from="gneJ0" to="gneJ1" priority="1">
    <lane id="gneE0_0" index="0" speed="13.89" length="153.61" shape="227.09,-64.38 380.45,-73.25"/>
</edge>
<edge id="out" from="2" to="3" priority="-1">
    <lane id="out_0" index="0" speed="13.90" length="1.00" shape="500.00,-1.65 501.00,-1.65"/>
</edge>

<junction id="1" type="dead_end" x="0.00" y="0.00" incLanes="" intLanes="" shape="0.00,-0.05 0.00,-3.25"/>
<junction id="2" type="priority" x="500.00" y="0.00" incLanes="1to2_0" intLanes=":2_0_0" shape="500.00,-0.05 500.00,-3.25 500.00,-0.05">
    <request index="0" response="0" foes="0" cont="0"/>
</junction>
<junction id="3" type="dead_end" x="501.00" y="0.00" incLanes="out_0" intLanes="" shape="501.00,-3.25 501.00,-0.05"/>
<junction id="gneJ0" type="dead_end" x="227.19" y="-62.74" incLanes="" intLanes="" shape="227.18,-62.79 227.00,-65.98"/>
<junction id="gneJ1" type="dead_end" x="380.54" y="-71.61" incLanes="gneE0_0" intLanes="" shape="380.35,-74.85 380.54,-71.66"/>

<connection from="1to2" to="out" fromLane="0" toLane="0" via=":2_0_0" dir="s" state="M"/>

<connection from=":2_0" to="out" fromLane="0" toLane="0" dir="s" state="M"/>

hello.rou.xml File

    <?xml version="1.0" encoding="UTF-8"?>

<!-- generated on 14/02/2018 21:20:37 by Netedit Version 0.31.0
<?xml version="1.0" encoding="UTF-8"?>

<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/netconvertConfiguration.xsd">

    <input>
        <sumo-net-file value="hello.net.xml"/>
    </input>

    <output>
        <output-file value="hello.net.xml"/>
    </output>

    <processing>
        <no-turnarounds value="true"/>
        <offset.disable-normalization value="true"/>
        <lefthand value="false"/>
        <junctions.corner-detail value="0"/>
        <rectangular-lane-cut value="false"/>
        <walkingareas value="false"/>
    </processing>

    <visualisation>
        <registry-viewport value="true"/>
    </visualisation>

</configuration>
-->

<net version="0.27" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/net_file.xsd">

    <location netOffset="250.00,0.00" convBoundary="0.00,-71.61,501.00,0.00" origBoundary="-250.00,0.00,251.00,0.00" projParameter="!"/>

    <edge id=":2_0" function="internal">
        <lane id=":2_0_0" index="0" speed="13.90" length="0.10" shape="500.00,-1.65 500.00,-1.65"/>
    </edge>

    <edge id="1to2" from="1" to="2" priority="-1">
        <lane id="1to2_0" index="0" speed="13.90" length="500.00" shape="0.00,-1.65 500.00,-1.65"/>
    </edge>
    <edge id="gneE0" from="gneJ0" to="gneJ1" priority="1">
        <lane id="gneE0_0" index="0" speed="13.89" length="153.61" shape="227.09,-64.38 380.45,-73.25"/>
    </edge>
    <edge id="out" from="2" to="3" priority="-1">
        <lane id="out_0" index="0" speed="13.90" length="1.00" shape="500.00,-1.65 501.00,-1.65"/>
    </edge>

    <junction id="1" type="dead_end" x="0.00" y="0.00" incLanes="" intLanes="" shape="0.00,-0.05 0.00,-3.25"/>
    <junction id="2" type="priority" x="500.00" y="0.00" incLanes="1to2_0" intLanes=":2_0_0" shape="500.00,-0.05 500.00,-3.25 500.00,-0.05">
        <request index="0" response="0" foes="0" cont="0"/>
    </junction>
    <junction id="3" type="dead_end" x="501.00" y="0.00" incLanes="out_0" intLanes="" shape="501.00,-3.25 501.00,-0.05"/>
    <junction id="gneJ0" type="dead_end" x="227.19" y="-62.74" incLanes="" intLanes="" shape="227.18,-62.79 227.00,-65.98"/>
    <junction id="gneJ1" type="dead_end" x="380.54" y="-71.61" incLanes="gneE0_0" intLanes="" shape="380.35,-74.85 380.54,-71.66"/>

    <connection from="1to2" to="out" fromLane="0" toLane="0" via=":2_0_0" dir="s" state="M"/>

    <connection from=":2_0" to="out" fromLane="0" toLane="0" dir="s" state="M"/>

</net>

Error Message Trace

it.polito.appeal.traci.TraCIException$UnexpectedData: Unexpected command/status ID: expected 164, got 2
at it.polito.appeal.traci.Utils.checkStatusResponse(Utils.java:57)
at it.polito.appeal.traci.ChangeStateQuery.pickResponses(ChangeStateQuery.java:83)
at it.polito.appeal.traci.MultiQuery.run(MultiQuery.java:108)
at it.polito.appeal.traci.SumoTraciConnection.nextSimStep(SumoTraciConnection.java:623)
at it.polito.appeal.traci.test.TraCITest.getFirstVehicle(TraCITest.java:337)
at it.polito.appeal.traci.test.TraCITest.testChangeTarget(TraCITest.java:577)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

I'm sorry if this is verbose, any help would be hugely appreciated

  • Further to this, sumo-gui does actually start and loads the .sumocfg file properly, but always fails at the nextSimStep() stage. Additionally, I've tried the examples included in Traci4J, however, anytime the nextSimStep() method is used the same error occurs. – SocialGamification Mar 01 '18 at 01:02
  • Welcome to StackOverflow. Questions seeking debugging help ("why isn't this code working?") must include **the desired behavior**, a **specific problem or error** and the shortest code necessary to reproduce it in the question itself. Questions without a **clear problem statement** are not useful to other readers. See: [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). Also, this is a Q & A site - please [**ask a question**](https://stackoverflow.com/help/how-to-ask) that can be answered. – NightOwl888 Mar 01 '18 at 01:08
  • Traci4J is considered deprecated, please use TraaS (which should be already part of your sumo download) – Michael Mar 01 '18 at 09:47
  • @Michael I can't seem to find any way to start up TraaS (although I have found executable Jar file in the sumo/bin directory). Do you know of any guide out there to help beginners like me? Any other tips about how to start up TraaS? – SocialGamification Mar 02 '18 at 19:45
  • Did you try the examples http://traas.sourceforge.net/cms/index.php?id=examples-1 ? – Michael Mar 06 '18 at 09:10
  • @Michael, I have but I'm unsure how to execute any of those examples. There's a TraaS executable in the SUMO folder but it doesn't seem to run when double clicked (at least not with a GUI). Any help would be much appreciated. – SocialGamification Mar 06 '18 at 23:31
  • You need to use it in your classpath when running your application. Much like in the TraCI4J case, I suppose. – Michael Mar 14 '18 at 20:55

1 Answers1

1

I meet the same question with using the Traci4J.

If you want to use Traas, I can give you some tips. You could find the WebService class here: traas/src/main/java/de/tudresden/ws/WebService.java This is an executable java file. Then you will get a running server. If you create a web service client, you could connect with the traas server and do the simulation with sumo. Btw I still have some doubt that the api of traas is less than the api for python and C++; Here is a small demo, supposing that you have already imported the traas.jar;

public class MyWebService {
    public static void main(String[] args) {
        Config.config_file = "resources/map.sumo.cfg";
        de.tudresden.ws.WebService.main(new String[]{});
    }
}

The web service client:

public class HelloWorldClient {
  public static TraasWSLocator locator;
  public static ServiceImpl service;

  static {
    try {
      locator = new TraasWSLocator();
      service = locator.getServiceImplPort();
    }
    catch (Exception e){
      e.printStackTrace();
    }
  }

  public static void main(String[] argv) throws RemoteException{
    service.setSumoBinary("sumo-gui");
    service.start("username");
    while (service.simulation_getMinExpectedNumber()>0){
        service.doTimestep();
    }
  }
}
recluse
  • 459
  • 4
  • 8