Discover the new mydSPACE services: License Management, the new dSPACE Help, and dSPACE Chatbot for User Documentation. Find more information and support on our dedicated support page. Learn more & get support

FAQ 533: ModelDesk API: Determining Vehicle Direction (Approaching or Moving Away from a Junction)

Question

How can I obtain direction information of a road using ModelDesk API? 

In automated testing, it is required to determine whether a vehicle (ego or fellow) is approaching or moving away from a junction. 
To achive this, the road direction information needs to be retrieved and used in the evaluation logic.

In the ModelDesk GUI, the default direction of a road can be visually confirmed using arrows on the road. However, for automated testing purposes, this information must be accessed via the API.

[Display of Default Directions on ModelDesk's Road Network]

Solution

The default road direction and the relative movement of a vehicle with respect to a junction (approaching or moving away can be determined by combining multiple pieces of information available via the ModelDesk API.

This cannot be determined by using a single parameter.
Instead, the following two types of information must be used together:

  1. Default Road Direction Connected to the Junction (Road Direction) 
    The Road direciton connected to the junction can be obtained using RoadConnectionPointType
    • Start = 0    : The connection point of a road to a junction is the start point of that road.
    • End = 1 : The connection point of a road to a junction is the end point of that road.
      * the default road diretion is defined as Start -> End
        Reference: Class Description (RoadConnectionPoint)
  2. Driving Direction of the Road (Lane Direction)
    The actual driving direction depends on the Driving Direction configuration of each lane. 
    In ModelDesk, lanes are classified as follows:
    • direct lane : Same direction as the road's default direction
    • oncoming lane : Opposite direction to the road's default direction
    • bidirectional : A lane that can be traveled in both directions
      Reference: Road Network Element Properties 

Default Road 
[Determination Logic] 
By combining the above information, the relative direction of a vehicle with respect to a junction can be determined as follows:

  1. Connection point of a road to a junction is the start point of that road (ConnectionPointType = 0)
    • direct lane : Vehicle moves away from the junction
    • oncoming lane : Vehicle approaches the junction
  2. Connection point of a road to a junction is the end point of that road (ConnectionPointType = 1)
    • direct lane : Vehicle approaches the junction
    • oncoming lane : Vehicle moves away from the junction

[Sample scirpt]
The following sample script determines whether a road connected to a specified junction leads toward or away from the junction based on the logic described above.

The script uses the following information:

  • RoadConnectionPointType (Default direction of a Road connected to a Junction)
  • RoadのDriving Direction (direct / oncoming lanes)

This sample assumes a single-lane road with a single driving direction (single-direction).
If multiple lanes exist, the logic must be extended to evaluate each lane individually.

# Constants
CP_TYPE_START = 0
CP_TYPE_END = 1

# Enter a junction name
print('Please enter a junction name.')
trgtJncName = input()

try:
  # Get a junction
  trgtJnc = Application.ActiveProject.ActiveExperiment.Road.Junctions.Item(trgtJncName)

  print('Junction name: ' + trgtJncName)
  print('-----------------------')

  for i in range(trgtJnc.ConnectionPoints.Count): 
    # Get basic information 
    connectionPoint = trgtJnc.ConnectionPoints.Item(i)
    roadName = connectionPoint.CounterPart.Owner.Name
    cpType = connectionPoint.CounterPart.Type  # 0: Start / 1: End

    trgtRoad = Application.ActiveProject.ActiveExperiment.Road.Roads.Item(roadName)

    print('Connected Road name: ' + roadName)
    print('Connection Point number: ' + str(i))

    # --- Road direction (Start/End) ---
    if cpType == 1:
      print ('Road Connection Point type: ' + str(cpType) + ' (End) -> leads towards the junction (default direction).')
    else:
      print ('Road Connection Point type: ' + str(cpType) + ' (Start) -> leads away from the junction (default direction)')

    # --- Lane information ---
    numDirect = trgtRoad.NumberOfDirectLanes or 0
    numOncoming = trgtRoad.NumberOfOncomingLanes or 0
    print ('Number of lane with specified directions: ' + str(numberOfLane))

    # --- Road type ---
    if numberOfLane > 1:
      laneType = 'multiple lane'
      print('Lane type: ' + laneType)
      print('Since this script does not support multi-lane, it will skip this step.')
      print('-----------------------')
      continue
    elif numDirect == 1 and numOncoming == 0:
      laneType = 'direct'
    elif numDirect == 0 and numOncoming == 1:
      laneType = 'oncoming'
    elif numDirect == 0 and numOncoming == 0:
      laneType = 'bidirectional'
    else: 
      laneType = 'unspecified'
    print('Lane type: ' + laneType)

    # --- Final interpretation ---
    if laneType in ['unspecified', 'bidirectional']:
      print('Result: Cannot determine uniquely')
    else: 
      if cpType == CP_TYPE_START:
        if laneType == 'direct':
          print('Result: Moving away from junction')
        else:
          print('Result: Approaching junction')
      elif cpType == CP_TYPE_END:
        if laneType == 'direct':
          print('Result: Approaching junction')
        else:
          print('Result: Moving away from junction')
    print('-----------------------')
except:
  print('Junction Read Error! Please make sure that' + trgtJncName + 'is the correct Junction name.')

 

[Determination Logic] 

Product versions used in this solution 
  • dSPACE Release 2025-B

Tags

Date 2026-11-02
Informationstyp FAQ (Häufig gestellte Fragen)

Immer auf dem neuesten Stand mit unserem Newsletter-Service.

Mit unserem Newsletter-Service informieren wir Sie über aktuelle Anwendungsbeispiele, neue Lösungen und Produkte sowie über Schulungen und Veranstaltungen. Hier geht's zur Anmeldung.

Formularaufruf freigeben

An dieser Stelle ist ein Eingabeformular von Click Dimensions eingebunden. Dieses ermöglicht es uns Ihr Newsletter-Abonnement zu verarbeiten. Aktuell ist das Formular ausgeblendet aufgrund Ihrer Privatsphäre-Einstellung für unsere Website.

Externes Eingabeformular

Mit dem Aktivieren des Eingabeformulars erklären Sie sich damit einverstanden, dass personenbezogene Daten an Click Dimensions innerhalb der EU, in den USA, Kanada oder Australien übermittelt werden. Mehr dazu in unserer Datenschutzbestimmung.