In order to measure the driver’s reaction time to brake when a pedestrian crosses the road, we need a scenario with a vehicle, a trigger and a pedestrian (Inactive) on the same road. The pedestrian must cross when the vehicle arrives.
We will not explain here how to do it but here are the screenshots of the Top view and the script for this scenario.
Define your KPI:
To define your KPI in order to be accessible in the ANALYSIS mode, you need to send the information you want through an exportChannel.
An export channel is a range of open channels on SCANeR simulation bus for end-users to easily exchange custom I/O with SCANeR environments.
To do so, you need to create a script:
- Click on the three white dots on the right of StoryBoard in SCENARIOS dock.
- Add a Step.
- Then add a Mice Script.
You can use a Python Script as well. All the documentation is available in the SCANeR studio documentation, part 2.20. PYTHON API.
Once inside your new script, you will need to calculate the time between the moment when the driver brakes and the pedestrian crosses and send it to an exportChannel.
Right click on Script and insert a Variable.
Add a second Variable.
These variables will be your time markers for the beginning of the vehicle braking and the beginning of the pedestrian movement. You can call them t1 and t2 for example.
3. Then right click on Script again and insert a rule.
4. With a right click on this rule, add a isPedestrianCrossing condition (Type: BECOME TRUE).
This condition returns TRUE as soon as the pedestrian leaves the sidewalk and until it reaches the opposite sidewalk. It indicates if the pedestrian is crossing a road due to a pedestrianCrossRoad action.
All the conditions, actions and functions are described in the Scripting Help.
5. Once the condition is created, insert a THEN action in the rule. This THEN action will use the function setVariable to give a value to one of your variable.
In this case, use the function getScenarioClock to give a value to the variable. It returns the time elapsed from scenario starting, in seconds. (Precision is about 10e-7.)
6. Add another THEN action to the rule to have a time marker without using a variable. That will help in the ANALYSIS mode to know exactly when the action occurred.
7. You finished your first rule, now let’s create a second one.
8. With a right click on this new rule, add a is > condition (Type: BECOMES TRUE). This condition will compare the function getBrakePedal with 0.
The getBrakePedal function returns the force applied on the brake pedal (0 if released).
9. Associate the getBrakePedal function with the EGO vehicle.
10. Once the condition finished, repeat the steps 5 and 6 for your second variable t2.
11. You now have your two variables set, you just need to send the time difference (t2 - t1) to an exportChannel. To do this, create a final rule with a isTrue condition.
A isTrue condition always returns TRUE.
12. Before adding an action, you must create a new exportChannel. To do this, click on CONFIGURATION above the toolbar and open the Export channel Manager. With the green +, you can add a new exportChannel.
Don’t forget to add a Category and a Name.
13. Now it’s time to add a THEN action in which we will use the setExportChannelByName action and the exportChannel you just create.
This action is used to exchange data (one float value per channel) on the SCANeR network.
The Value here uses the
- (minus) function to subtract the two variables.
We are done with the script, we just calculate the time between the moment when the driver brakes and the pedestrian crosses and send it to an exportChannel .
At the end, the script should look like this:
You can rename the script and the rules to have a better understanding of it.