eclipse-sumo / sumo

Eclipse SUMO is an open source, highly portable, microscopic and continuous traffic simulation package designed to handle large networks. It allows for intermodal simulation including pedestrians and comes with a large set of tools for scenario creation.
https://eclipse.dev/sumo
Eclipse Public License 2.0
2.55k stars 1.43k forks source link

The failure of simulation.convertRoad() in TraaS #5490

Closed YenKang closed 5 years ago

YenKang commented 5 years ago

Dear @mkrumnow, @behrisch , @namdre,

convertRoad

I faced the SUMO error for SUMO error for command 171: Position conversion requires a source position and a position type as parameter. when I executed convertRoad() in Main.java at TraaS folder

System.out.println(conn.do_job_get(Simulation.convertRoad(2466.06, 7243.26, false, "ignoring")));

convertGeo & convert2D (success)

So far, I have already succeed to run the convertGeo() funcrion by running the following line of code.

System.out.println(conn.do_job_get(Simulation.convertGeo(3414.680, 5591.166, false )));

As I want to implement converRoad with the same logic of convertGeo, but I falied. The sumo-gui show the message:

Answered with error to command 0xab: Position conversion requires a source position and a position type as parameter.

Therefore, I found several bugs on SumoCommand.java and Simulation.java, thus I re-write parts of the above two files.

1.Simulation.java

edited part
public static SumoCommand convertRoad(double x, double y, boolean isGeo, String vClass){ 
    Byte posType = Constants.POSITION_2D;

    if(isGeo){
         posType = Constants.POSITION_LON_LAT;
    }

    Byte toType =  Constants.POSITION_ROADMAP;

    Object[] array = new Object[]{posType, x, y, toType, vClass};
    return new SumoCommand(
        Constants.CMD_GET_SIM_VARIABLE,
        Constants.POSITION_CONVERSION, 
        "", 
        array,
        Constants.RESPONSE_GET_SIM_VARIABLE, 
        Constants.POSITION_ROADMAP
    );
}

2.SumoCommand.java

else if((Integer) input1 == Constants.CMD_GET_SIM_VARIABLE && (Integer) input2 == Constants.POSITION_CONVERSION)
{
    //  cmd.content().writeInt(2);  // Int(2) in convert2D and convertGeo
    cmd.content().writeInt(3); // Int(3) in convertRoad

    if(array.length == 4){ //convertGeo

        cmd.content().writeUnsignedByte((byte) array[0]);
        cmd.content().writeDouble((double) array[1]); 
        cmd.content().writeDouble((double) array[2]); 
        cmd.content().writeUnsignedByte(Constants.TYPE_UBYTE);
        cmd.content().writeUnsignedByte((byte) array[3]);
    }

    if(array.length == 5){ // convertRoad array{posType, x, y, toType, vClass}
        cmd.content().writeUnsignedByte((byte) array[0]); //posType
        cmd.content().writeDouble((double) array[1]); // double x
        cmd.content().writeDouble((double) array[2]);  //  double u
        cmd.content().writeUnsignedByte(Constants.TYPE_UBYTE); // 
        cmd.content().writeUnsignedByte((byte) array[3]); // toType= Constants.POSITION_ROADMAP
        cmd.content().writeStringASCII((String) array[4]); // String vClass
    }

    /*
    else if (array.length == 5) { // convert2D
        cmd.content().writeUnsignedByte((byte) array[0]); // byte fromType  
        cmd.content().writeStringASCII((String) array[1]); // String edgeID
        cmd.content().writeDouble((double) array[2]);      // double pos 
        cmd.content().writeUnsignedByte((byte) array[3]); // byte landeIndex    
        cmd.content().writeUnsignedByte(Constants.TYPE_UBYTE); 
        cmd.content().writeUnsignedByte((byte) array[4]);   //  byte posType
    }
    */  
}

3.Traci.java

Finally,

the console show the error:

_it.polito.appeal.traci.TraCIException: SUMO error for command 171: Position conversion requires a source position and a position type as parameter. at de.tudresden.sumo.util.Query.queryAndVerify(Query.java:87) at de.tudresden.sumo.util.Query.queryAndVerifySingle(Query.java:217) at de.tudresden.sumo.util.CommandProcessor.do_job_get(CommandProcessor.java:363) at it.polito.appeal.traci.SumoTraciConnection.do_job_get(SumoTraciConnection.java:376) at Main.main(Main.java:80)_

ps. This is the link of my workspace of eclispe.

Thanks for your patience! Kang Yen

namdre commented 5 years ago

already solved (duplicate of #5478)