探索全新的 mydSPACE 服务: 许可证管理、全新的 dSPACE 帮助以及用于用户文档的 dSPACE 聊天机器人。请访问我们的专用支持页面,获取更多信息和支持。 链接了解更多并获取支持

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
资料信息 常见问答

通过 dSPACE时事通讯服务了解最新信息。

通过 dSPACE 时事通讯服务,我们将随时向您通报当前的使用案例、新解决方案和产品以及培训和活动。在此注册,免费订阅。

Enable form call

At this point, an input form from Click Dimensions is integrated. This enables us to process your newsletter subscription. The form is currently hidden due to your privacy settings for our website.

External input form

By activating the input form, you consent to personal data being transmitted to Click Dimensions within the EU, in the USA, Canada or Australia. More on this in our privacy policy.