Create functions
Hi , base on your structure you have made I am trying to replicate for another functions , still not able to understand how to implement the functions (reaction) , for now created simple scenario a car in empty road simulated with esmini , how can I do that ? I did not know where to raise my question as it is not issue
Functions or driver model in the loop is solved in terms of controller. Controller is an OpenSCENARIO concept to hand over control of an entity from the default behavior (performing triggered actions, else moving along the lane with current speed). Either the complete functionality is embedded in the controller or the controller enables an external process/application to interact with esmini and the ongoing scenario simulation.
Examples
External control from C++ application (linking esminiLib):
- https://github.com/esmini/esmini/blob/dev/EnvironmentSimulator/code-examples/hello_world/hw4_external_ego_control.cpp
- https://esmini.github.io/#_driver_model
The first example (external_control) shows how you can report state of an external vehicle. It also shows the option to specify whether coordinate components (even individually) are absolute values or relative to the road surface.
If your vehicle model takes road elevation and slope into account you should probably report absolute z, pitch and roll values. However, if it lives in a flat world, you can report z, pitch, and roll = 0 relative road surface – and esmini will take care of aligning it to the road.
The second example (driver model) is a bit more complicated. It updates a simple vehicle model (like a 2D bike model) in terms of throttle, brake and steering commands based on looking ahead along the road. The road curvature affecting steering angle and target speed.
External driver model interacting via UDP:
- https://github.com/esmini/esmini/blob/master/scripts/udp_driver/testUDPDriver.py
- https://youtu.be/IuwuGE3BzKw?si=eROiWl8sPfJXLSHg
Interactive control implemented as controller:
- https://github.com/esmini/esmini/blob/master/EnvironmentSimulator/Modules/Controllers/ControllerInteractive.cpp
I think the first approach, using lib C++ API, should be the first recommended. But it all depends on the use case. Your functions could be implemented in the C++ application, just like the driver model in the second example.
You can also fetch states of all other vehicles for active safety functions. How to do that, see this example: https://github.com/esmini/esmini/blob/dev/EnvironmentSimulator/code-examples/hello_world/hw3_fetch_states.cpp
Let us know if you have more questions.