Frequently asked questions

Need technical support?

How Can I Get the Number of Left and Right Lanes Next to the Ego Car?

Question

(This is a legacy article. If you are using a current version of CarMaker please refer to the Ground Truth Sensor model for Lane output)

For the Road Sensor mode "Along Route Reference Line" there is a C-code variable called RoadSensor0.Lanes.nLanesL and RoadSensor0.Lanes.nLanesR.
Unfortunately, it can be observed that the output is always the number of lanes to the left and right of the reference line. The ego vehicle's position is not considered. This can also be observed looking at the UAQs Car.Road.Lane.nLeft and Car.Road.Lane.nRight (or any other Road Sensor quantity). Although there isn't a legitimate driving lane to the left of the vehicle, as these are just contrary lanes, the quantity values specify otherwise. So the question is: How can I get the remaining lanes to the left and the right of the ego vehicle depending on its position?

Solution

To get this information, there are a few more lines of code necessary. The quantities mentioned above (nLanesR and nLanesL) are information regarding the road definition. "How many lanes does my direction of travel have?" and "How many opposite lanes are there?"

For the calculation you need to know the number (index) of the lane the Road Sensor is in. You may already have noticed the definition in the Object List in the Scenario Editor called Lane L0, R1, L3, etc... Therefore, the position of the Road Sensor can be found in Lanes.laneIdxand Lanes.isRight (or Act.LaneId and Act.isRight as UAQs in CarMaker).

Attached you can find a C-code example for CarMaker 9.1.1 with a few line of code in the User.c file. Just copy this User.c file into the /src folder of your CM 9.1.x project directory and recompile the CarMaker executable. With the attached Vehicle and TestRun you can start the simulation and observe the output in the Session Log. Adapting it to CarMaker 10 is very easy, just copy the snippets into a CM 10 User.c file of a CM 10 project directory and recompile the CarMaker executable for version 10.

This example can be extended in case you don't want to consider all kinds of lane types (like road boarder, traffic island, etc...). To check the types of the lanes, you can iterate over the lanes to the left and right of the reference line using RoadSensor[0].lanes.left[] and RoadSensor[0].lanes.right[].

For more information on the Road Sensor, please refer to the documentation via Help > Reference Manual >20.9 "Road Sensor" or have a look into the header file in the CarMaker installation directory > include > Vehicle >Sensor_Road.h
For more information on the IPGRoad API in general, please refer to the documentation via Help > Additional Documents >IPGRoad API Reference or have a look into the header file in the CarMaker installation directory > include > road.h

Download: NumberLanes_CM911.zip

Need technical support?
  • Date: 04.05.2021
  • Product: CarMaker
  • Version: 9.1
  • Component: C-Code Interface
  • Language: English

Tags

C-Code
Sensor
Scenario Editor