Search code examples
javaangleomnet++traffic-simulation

Getting Vehicle's angle in SUMO with Traci4j


I want to work together with SUMO and OMNeT++ in order to create a VANET simulation. For this purpose, I am using the Traci4j library for Java (available at https://github.com/egueli/TraCI4J), which allows to interact with SUMO from a remote port.

First of all I would like to state that I know that Veins exists, but I strongly have the need to do it with Java as part of my Bachelor Tesis

For the moment, I am able to get all the vehicles that are driving across my network, and get their speed and position (X,Y). However, I would also like to get the direction (angle) in which this vehicles are moving.

I have been looking through the different methods contained in Traci4j but I haven't found anything. The only related-part-of-code that I have found is in the class Constants:

/** angle (get: vehicle) */
public static final int VAR_ANGLE = 0x43;

But I don't really understand what is this useful for. Do you think it is possible to obtain this attribute from the vehicles?

I would appreciate any kind of help. Thank you!


Solution

  • The angle attribute is available via TraCI but the corresponding message is not implemented in TraCI4J. You might want to switch to TraaS which has this function implemented and is in general considered better in functional coverage of the TraCI protocol. This (untested) snippet might help:

     import de.tudresden.sumo.cmd.Vehicle;
     import it.polito.appeal.traci.SumoTraciConnection;
    
     SumoTraciConnection conn = new SumoTraciConnection(sumo_bin, config_file);
     conn.runServer();
    
     //load routes and initialize the simulation
     conn.do_timestep();
    
     double angle = (double) conn.do_job_get(Vehicle.getAngle("v0"));