Search code examples
omnet++traffic-simulation

how to calculate distance between car and next junction in veins


using getCurrentPosition() method gives the current coordinates of the car and getJunctionPosition() gives the the coordinates of a node. but base on calculating distance of the car to the next junction and evaluating results i belives these cordinates are of different format( once sumo coordinates and other is omnet coordinates) so whats the best way to calculate the distance of car to next junction. second question is about the exit time of cars, how we can notify when a car left simulation and record the time when this happend


Solution

  • Veins distinguishes between coordinates of type Coord (which represent OMNeT++ coordinates) and those of type TraCICoord (which represent TraCI/SUMO coordinates). Because their transformation depends on the running simulation, it offers API calls to convert between them. The API calls to convert between TraCICoord and Coord are called omnet2traci and traci2omnet.

    You are right: In Veins 3.0, the getJunctionPosition API call returns a TraCICoord, hence you will need to call traci2omnet to convert this to a Coord, on which you can then call .distance(Coord).

    Note that (because this was such a common operation) in Veins 4a2, the Junction::getPosition API call directly returns a Coord.