2. Auto Headlight : Configure OpenXilEnv#

Follow chapter 1 before coming here : 1. Setting up Simulation Environment

Create Trigger File#

Write trigger files to map the input output variables between Carla and VAPI FMU examples in .tri file.

format : Receiver signal = Provider signal;

Current_Latitude = CARLAout__act_pos_x;
Current_Longitude = CARLAout__act_pos_y;
CARLAin__Headlight_Lowbeam = HeadLight_LowBeam;

In OpenXilEnv software, open the control panel and Internal process control section, select the Equation tab. browse the trigger file which you have created or modified.and activate the trigger file by clicking run button.

../../../_images/addtrigger.png

Hint

Example Trigger file location : examples\auto_headlight_example\simulation_artifacts\vapiexamplestriggerfile.tri

Create Script File#

Write script file to automate loading of FMUs and activation of trigger files.

  • starting the process can be automated by using below command with path to external process(FMU) as parameter.

// START_PROCESS (path to external process)
START_PROCESS (..\CarlaBridge\carla_bridge_2doors.fmu)
  • Getting the process state by using below command with name of external process as parameter. it is usually used with IF condition to check the state.

// get_process_state (external process name)
get_process_state (Doors2ExampleFMU.fmu)
  • Setting the signal values by using below command with name of signal and value.

SET_BBVARI(signal_name = value)
  • Activating the trigger file and also choosing when it should be used.

//START_EQUATION(Qty,trigger file name,timing, external process)
START_EQUATION(1,vapiexamplestriggerfile.tri,Before,Doors2ExampleFMU.fmu)
  • Sample of script is as shown below . this script is used for doors example.

IF (get_process_state (..\CarlaBridge\carla_bridge_headlight.fmu) == 0)
MESSAGE (Starting Carla Bridge fmu)
START_PROCESS (..\CarlaBridge\carla_bridge_headlight.fmu)
ENDIF
IF (get_process_state (carla_bridge_headlight.fmu) != 0)
MESSAGE(Auto Headlight fmu started!)
SET_BBVARI(CARLAin__toggle_view = 1)
SET_BBVARI(CARLAin__operation_mode = 4)
SET_BBVARI(CARLAin__toggle_display = 1)
ENDIF
IF (get_process_state (..\vapifmus\AutoHeadlightFMU.fmu) == 0)
MESSAGE (Starting VAPI Headlight Example fmu)
START_PROCESS (..\vapifmus\AutoHeadlightFMU.fmu)
ENDIF
START_EQUATION(1,vapiexamplestriggerfile.tri,Before,AutoHeadlightFMU.fmu)
IF (get_process_state (AutoHeadlightFMU.fmu) != 0)
MESSAGE(Auto Headlight fmu started!)
ENDIF
  • script file can also be loaded in similar fashion as trigger file but only change is one should select “script” tab and activate once file has been chosen.

../../../_images/controlpanelscriptadd.png

Hint

Auto Headlight example script file location : examples\auto_headlight_example\simulation_artifacts\vapiheadlightload.scr

Two Door example script file location : examples\auto_headlight_example\simulation_artifacts\vapi2doorload.scr

Four Door example script file location : examples\auto_headlight_example\simulation_artifacts\vapi4doorload.scr

Note: Verify paths and names of fmus while using it before loading it in the openxil. Adjust it accordingly if change is needed.

Assign script to button widget#

  • In the OpenXilEnv, right click to add user control widget as shown in the image.

../../../_images/adducwidget.png
  • right click on the widget and click on config button.

../../../_images/ucwidgetconfig.png
  • In this config, the parameters can be changed according to our wish. Add the button and configure on the right section to add name and script.

../../../_images/ucwidgetscrloadbutton.png

In this way the script will be assigned to button. and save the config before closing OpenXilEnv.

Add Widgets#

Add and configure widgets to simulate or control signal values

  • Add a new widget in OpenXilEnv by clicking right mouse button and choosing a widget.

../../../_images/widgetadd.png
  • Here in this example , text widget is chosen. this widget displays the signals and its attributes.

../../../_images/widgetconfig.png
  • Signals are visible when respective external processes(FMUs) are initiated. And user can add them on to the widgets for analysis and control.

../../../_images/widgetsignaladd.png
  • In similar way, other widgets can also be configured with respective signals.

../../../_images/widget1conf.png ../../../_images/widget2conf.png

Simulation with Openxil and VAPI only#

VAPI can also be simulated without use of CarlaBridge. By only utilizing the widgets present in Openxil and configuring them to the respective signals of VAPI. Values can be modified by user and VAPI FMU reacts to the changes.

 @startuml

 skinparam defaultFontColor black

 actor "User"
 participant "Openxil" as OX

 box "Core Instance" #82b8b8ff
 Participant "Headlight Application" as HA #00A7AB
 end box

 rnote over User
 Set Python env
 end rnote

 User -> OX : Start the Openxil

 activate OX

 rnote over OX
 OpenXil started
 end rnote

 User -> OX : Load Headlight FMU (VAPI)
 OX -> HA : Loads Headlight application

 deactivate OX

 HA -> HA : Loads Core services
 rnote over HA
 Headlight application
 loads **Core services**
 and registers
 following signals:
 1. Current Latitude
 2. Current Longitude
 3. Headlight Lowbeam
 end rnote


 HA -> HA : Loads vehicle devices
 HA -> HA : Loads basic services
 HA -> HA : Loads Complex service

 activate OX
 HA-->OX : Signals value information
 deactivate HA

 User -> OX : Add and configure widgets

 rnote over OX
 widget is configured
 with latitude,longitude
 and headlight signals
 end rnote

 rnote over OX
 Widget value
 is updated
 end rnote

 User -> OX : Modify latitude and longitude to tunnel location

 OX -> HA : Current Latitude and Longitude information
 activate HA
 HA -> HA : Toggles Headlight on

 HA -> OX : Headlight turned on
 deactivate HA
 rnote over OX
 Widget value
 is updated
 end rnote

 @enduml

Openxil and VAPI sequence diagram#