Auto Headlight Example#

Attention

Purpose: Vehicle function demonstration / simulation with open source software OpenXilEnv and Carla

../../../_images/headlightexample.jfif

Note

Example can be found in <output-folder>/examples/bin:
auto_headlight_app

Hint

The function should automatically switch on the light when the vehicle drives into a tunnel:

  • Two input signals represents the GPS position of the vehicle.

  • One output signal switches the heeadlight on or off.

  • The function (complex service) has internally a map containing the position of tunnels so it can switch on automatically the light.

VSS Interfaces#

Note

These following interfaces are not part of the standard but custom interfaces for demonstration purpose.

These values represent the GPS position of the vehicle:

  • Vehicle.Position.CurrentLatitude VSS signal for current latitude value (GPS-based).

  • Vehicle.Position.CurrentLongitude VSS signal for current longitude value (GPS-based).

Additionally, one output signal is used for the headlight:

  • Vehicle.Body.Light.Front.LowBeam VSS signal for front low beam headlight.

These signals should be described in a CSV file. Using the utility tool SDV_VSS_UTIL, an IDL (Interface Description Language) file shall be generated for vehicle devices and basic services.

The utility tool SDV_IDL_COMPILER generates header and source files for the vehicle devices and basic services using their respective IDL files.

These steps are typically automated via commands written in the CMakeLists.txt file, executed during the configuration or build process.

Generated Devices and Services#

The generated vehicle devices and basic services include:

  • Interfaces for event registration/unregistration These allow updates on the current latitude and longitude of the vehicle via callback functions.

  • Interfaces for output transmission Used to send values to the vehicle network, typically triggered by higher-level logic. In this example, headlight data is updated using callbacks.

  • Subscribing to signal updates Subscription to a signal shall take place and which trigger a callback to handle the updated value. Transmission and reception methods may vary.

  • Unit conversions Vehicle devices may include unit conversions for abstraction. In this example, no conversion is needed as the algorithm uses a compatible unit system.

Generated Vehicle Devices:

  • Vehicle.Position.CurrentLatitude_Device

  • Vehicle.Position.CurrentLongitude_Device

  • Vehicle.Body.Light.Front.LowBeam_Device

Generated Basic Services:

  • Vehicle.Position.CurrentLatitude_Service

  • Vehicle.Position.CurrentLongitude_Service

  • Vehicle.Body.Light.Front.LowBeam_Service

These above mentioned devices are illustrated in the picture below.

../../../_images/auto_headlight_example_arch.png

Note

Basic Service s include Proxy and Stub components for communication with remote or isolated processes. Vehicle Device s do not include these components, as their interfaces must not be reachable from isolated process.

Complex Service#

The algorithm is implemented in the Auto Headlight Service, a Complex Service.

  • During initialization, tunnel start and end points are parsed from a TOML file to calculate a bounding box.

  • The headlight is switched on/off based on the vehicle’s current position (latitude and longitude).

  • If the position is within the bounding box → headlight is on. If the position is outside → headlight is off.

Service Communication:

  • Complex services run in a isolated process and access basic services via proxy and stub.

  • Updates on vehicle position are received through callbacks from basic services.

  • Headlight status is calculated and written using headlight interfaces, which call the respective basic service and vehicle device interfaces to update the status.

@startuml

skinparam defaultFontColor black

box "Core Instance" #82b8b8ff
Participant "CAutoHeadlightAppSimulate" as EC #00A7AB
Participant "Rx Signal (Dispatch Service)" as RX #BFBFBF
Participant "Vehicle Device" as VD #7FD5F3
Participant "Basic Service" as BS #58D4FF
Participant "Complex Service" as CS #3B97CD
end box



rnote over EC
Rx Signals
are created
for Latitude and
Longitude
(GPS position)
endrnote

activate EC

EC->RX

activate RX

RX->RX : signal value updated
RX --> EC

deactivate EC


RX -> VD : Event Triggered
deactivate RX
activate VD

rnote over VD
Signal value
Updated
endrnote

VD -> BS : Event Triggered
deactivate VD
activate BS


rnote over BS
Signal value
Updated
endrnote

BS -> CS : Event Triggered
deactivate BS

activate CS
rnote over CS
Signal value
Updated and
processed
endrnote

deactivate CS

@enduml

Reception sequence#

@startuml
 set separator ::
 class CAutoHeadlightService <<Singleton>>
 {
   +void Initialize(const sdv::u8string& ssObjectConfig)
   +sdv::EObjectStatus GetStatus() const
   +void SetOperationMode(sdv::EOperationMode eMode)
   +void Shutdown()
   -void SetCurrentLatitude(float value)
   -void SetCurrentLongitude(float value)
   -bool IsinTunnel() const
   -bool GetHeadlightStatus() const
   -SGPSBoundBox GetGPSBoundBox() const
   -void ProcessHeadlightBasedOnEgoPosition()
   -bool LoadGPSBounds(const sdv::u8string& rssObjectConfig)
   -sdv::EObjectStatus m_eStatus
   -volatile float m_fCurrentLatitude
   -volatile float m_fCurrentLongitude
   -volatile bool m_bHeadlight
   -SGPSBoundBox m_SGPSBoundingBox
   -vss::Vehicle::Body::Light::Front::LowBeamService::IVSS_SetHeadLightLowBeam* m_pHeadlightSvc
 }

 class sdv::CSdvObject
 {
   {static} +sdv::sequence<sdv::u8string> GetClassAliasesStatic()
   {static} +sdv::u8string GetDefaultObjectNameStatic()
   {static} +bool IsSingletonStatic()
   {static} +sdv::sequence<sdv::u8string> GetObjectDependenciesStatic()

 }
 class CSdvObjectAccess
 Interface sdv::IObjectControl
 {
   {abstract} void Initialize(const sdv::u8string& ssObjectConfig)
   {abstract} EObjectStatus GetStatus() const
   {abstract} void SetOperationMode(EOperationMode eMode)
   {abstract} void Shutdown()
 }
 Interface IAutoheadlightService
 {
   struct SGPSBoundBox
   {abstract} bool IsinTunnel() const
   {abstract} bool GetHeadlightStatus() const
   {abstract} SGPSBoundBox GetGPSBoundBox() const
 }
 Interface vss::Vehicle::Position::CurrentLatitudeService::IVSS_SetCurrentLatitude_Event
 {
   {abstract} void SetCurrentLatitude(float value)
 }
 Interface vss::Vehicle::Position::CurrentLongitudeService::IVSS_SetCurrentLongitude_Event
 {
   virtual void SetCurrentLongitude(float value)
 }

 CAutoHeadlightService ..|> IObjectControl : Implements
 CAutoHeadlightService ..|> IAutoheadlightService : Implements
 CAutoHeadlightService ..|> IVSS_SetCurrentLatitude_Event : Implements
 CAutoHeadlightService ..|> IVSS_SetCurrentLongitude_Event : Implements
 CAutoHeadlightService --|> CSdvObject
 CSdvObject --|> CSdvObjectAccess : inherits
@enduml

Headlight complex service class diagram#

@startuml
 set separator ::
 package "Headlight Application executable"
 {
   class CAutoHeadlightAppSimulate
   {

     +bool Initialize()
     +void Shutdown()
     +void ExecuteTestRun()
     -bool KeyHit()
     -char GetChar()
     -bool GetAccessToServices()
     -bool RegisterSignalsSimDatalink()
     -void ResetSignalsSimDatalink()
     -bool IsSDVFrameworkEnvironmentSet()
     -virtual void SetCurrentLatitude(float value)
     -virtual void SetCurrentLongitude(float value)
     -void CallbackToSetCurrentLatitude(sdv::any_t value)
     -void CallbackToSetCurrentLongitude(sdv::any_t value)

   }

   class CConsole
   {
     +void PrintHeader()
     +bool PrepareDataConsumers()
     +void ResetSignals()
     +void StartUpdateDataThread()
     +void StopUpdateDataThread()
     -void WriteCurrentLatitude(float value)
     -void WriteCurrentLongitude(float value)
     -void SetCurrentLatitude(float value)
     -void SetCurrentLongitude(float value)
     -bool RegisterSignals()
     -void CallbackCurrentLatitude(sdv::any_t value)
     -void CallbackCurrentLongitude(sdv::any_t value)
     -void CallbackToSetCurrentLatitude(sdv::any_t value)
     -void CallbackToSetCurrentLongitude(sdv::any_t value)
     -void UpdateDataThreadFunc()
     -void UpdateTXSignal(SConsolePos sPos, const std::string& label, sdv::core::CSignal& signal, bool& value)
     -SConsolePos GetCursorPos() const
     -void SetCursorPos(SConsolePos sPos);
     -void PrintText(SConsolePos sPos, const std::string& rssText);
     -void PrintValue(SConsolePos sPos, const std::string& rssName, TValue tValue, const std::string& rssStatus);
     -std::string AlignString(const std::string& message, uint32_t desiredLength = 0);
     -inline void PrintValue(SConsolePos sPos, const std::string& rssName, TValue tValue, const std::string& rssUnits)
     -inline void PrintValue<bool>(SConsolePos sPos, const std::string& rssName, bool bValue, const std::string& rssUnits)
   }

 }
 Interface vss::Vehicle::Position::CurrentLatitudeService::IVSS_SetCurrentLatitude_Event
 {
   {abstract} void SetCurrentLatitude(float value)
 }
 Interface vss::Vehicle::Position::CurrentLongitudeService::IVSS_SetCurrentLongitude_Event
 {
   {abstract} void SetCurrentLongitude(float value)
 }



 Interface vss::Vehicle::Position::CurrentLatitudeDevice::IVSS_WriteCurrentLatitude_Event
 {
   {abstract} void WriteCurrentLatitude(float value)
 }
 Interface vss::Vehicle::Position::CurrentLongitudeDevice::IVSS_WriteCurrentLongitude_Event
 {
   {abstract} void WriteCurrentLongitude(float value)
 }

 CAutoHeadlightAppSimulate ..|>  IVSS_SetCurrentLatitude_Event : Implements
 CAutoHeadlightAppSimulate ..|>  IVSS_SetCurrentLongitude_Event : Implements
 CAutoHeadlightAppSimulate ..|>  IVSS_WriteCurrentLatitude_Event :Implements
 CAutoHeadlightAppSimulate ..|>  IVSS_WriteCurrentLongitude_Event :Implements
 CConsole ..|>  IVSS_SetCurrentLatitude_Event : Implements
 CConsole ..|>  IVSS_SetCurrentLongitude_Event : Implements

@enduml

Headlight application class diagram#

@startuml
 set separator ::
 class CBasicServiceCurrentLatitude
 {
   +void SetCurrentLatitude(float value)
   +float GetCurrentLatitude() const
   +void WriteCurrentLatitude(float value)
   +void RegisterOnSignalChangeOfFCurrentLatitude(vss::Vehicle::Position::CurrentLatitudeService::IVSS_SetCurrentLatitude_Event* callback)
   +void UnregisterOnSignalChangeOfFCurrentLatitude(vss::Vehicle::Position::CurrentLatitudeService::IVSS_SetCurrentLatitude_Event* callback)
   -float m_fCurrentLatitude
         -mutable std::mutex m_fCurrentLatitudeMutexCallbacks
         -std::set<vss::Vehicle::Position::CurrentLatitudeService::IVSS_SetCurrentLatitude_Event*> m_fCurrentLatitudeCallbacks
 }

 class sdv::CSdvObject
 {
   {static} +sdv::sequence<sdv::u8string> GetClassAliasesStatic()
   {static} +sdv::u8string GetDefaultObjectNameStatic()
   {static} +bool IsSingletonStatic()
   {static} +sdv::sequence<sdv::u8string> GetObjectDependenciesStatic()

 }

 Interface vss::Vehicle::Position::CurrentLatitudeDevice::IVSS_WriteCurrentLatitude_Event
 {
   {abstract} void WriteCurrentLatitude(float value)
 }

 Interface vss::Vehicle::Position::CurrentLatitudeService::IVSS_SetCurrentLatitude_Event
 {
   {abstract} void SetCurrentLatitude(float value)
 }

 Interface vss::Vehicle::Position::CurrentLatitudeService::IVSS_GetCurrentLatitude
 {
   {abstract} float GetCurrentLatitude() const
   {abstract} void RegisterOnSignalChangeOfFCurrentLatitude(IVSS_SetCurrentLatitude_Event* callback)
   {abstract} void UnregisterOnSignalChangeOfFCurrentLatitude(IVSS_SetCurrentLatitude_Event* callback)
 }

 CBasicServiceCurrentLatitude --|> sdv::CSdvObject : Inherits
 CBasicServiceCurrentLatitude ..|> vss::Vehicle::Position::CurrentLatitudeService::IVSS_GetCurrentLatitude : Implements
 CBasicServiceCurrentLatitude ..|> vss::Vehicle::Position::CurrentLatitudeService::IVSS_SetCurrentLatitude_Event : Implements
 CBasicServiceCurrentLatitude ..|> vss::Vehicle::Position::CurrentLatitudeDevice::IVSS_WriteCurrentLatitude_Event : Implements

@enduml

Current Latitude basic services class diagram#

@startuml
 set separator ::
 class CBasicServiceCurrentLongitude
 {
   +void SetCurrentLongitude(float value)
   +float GetCurrentLongitude() const
   +void WriteCurrentLongitude(float value)
   +void RegisterOnSignalChangeOfFCurrentLongitude(vss::Vehicle::Position::CurrentLongitudeService::IVSS_SetCurrentLongitude_Event* callback)
   +void UnregisterOnSignalChangeOfFCurrentLongitude(vss::Vehicle::Position::CurrentLongitudeService::IVSS_SetCurrentLongitude_Event* callback)
   -float m_fCurrentLongitude
   -mutable std::mutex m_fCurrentLongitudeMutexCallbacks
   -std::set<vss::Vehicle::Position::CurrentLongitudeService::IVSS_SetCurrentLongitude_Event*> m_fCurrentLongitudeCallbacks
 }

 Interface vss::Vehicle::Position::CurrentLongitudeDevice::IVSS_WriteCurrentLongitude_Event
 {
   {abstract} void WriteCurrentLongitude(float value)
 }

 Interface vss::Vehicle::Position::CurrentLongitudeService::IVSS_SetCurrentLongitude_Event
 {
   {abstract} void SetCurrentLongitude(float value)
 }

 Interface vss::Vehicle::Position::CurrentLongitudeService::IVSS_GetCurrentLongitude
 {
   {abstract} float GetCurrentLongitude() const
   {abstract} void RegisterOnSignalChangeOfFCurrentLongitude(IVSS_SetCurrentLongitude_Event* callback)
   {abstract} void UnregisterOnSignalChangeOfFCurrentLongitude(IVSS_SetCurrentLongitude_Event* callback)
 }

 class sdv::CSdvObject
 {
   {static} +sdv::sequence<sdv::u8string> GetClassAliasesStatic()
   {static} +sdv::u8string GetDefaultObjectNameStatic()
   {static} +bool IsSingletonStatic()
   {static} +sdv::sequence<sdv::u8string> GetObjectDependenciesStatic()

 }

 CBasicServiceCurrentLongitude --|> sdv::CSdvObject : Inherits
 CBasicServiceCurrentLongitude ..|> vss::Vehicle::Position::CurrentLongitudeService::IVSS_GetCurrentLongitude : Implements
 CBasicServiceCurrentLongitude ..|> vss::Vehicle::Position::CurrentLongitudeService::IVSS_SetCurrentLongitude_Event : Implements
 CBasicServiceCurrentLongitude ..|> vss::Vehicle::Position::CurrentLongitudeDevice::IVSS_WriteCurrentLongitude_Event : Implements

@enduml

Current Longitude basic service class diagram#

@startuml
 set separator ::
 class CBasicServiceHeadLightLowBeam
 {
   +bool SetHeadLightLowBeam(bool value)
         -vss::Vehicle::Body::Light::Front::LowBeamDevice::IVSS_WriteHeadLightLowBeam* m_ptrHeadLightLowBeam
 }

 class sdv::CSdvObject
 {
   {static} +sdv::sequence<sdv::u8string> GetClassAliasesStatic()
   {static} +sdv::u8string GetDefaultObjectNameStatic()
   {static} +bool IsSingletonStatic()
   {static} +sdv::sequence<sdv::u8string> GetObjectDependenciesStatic()
 }

 Interface vss::Vehicle::Body::Light::Front::LowBeamService::IVSS_SetHeadLightLowBeam
 {
   {abstract} bool SetHeadLightLowBeam(bool value)
 }

 CBasicServiceHeadLightLowBeam --|> sdv::CSdvObject : Inherits
 CBasicServiceHeadLightLowBeam ..|> vss::Vehicle::Body::Light::Front::LowBeamService::IVSS_SetHeadLightLowBeam : Implements

@enduml

HeadlightLowBeam basic service class diagram#

@startuml
 set separator ::
 class CVehicleDeviceHeadLightLowBeam
 {
   +void Initialize(const sdv::u8string& objectConfig)
   +sdv::EObjectStatus GetStatus() const
   +void SetOperationMode(sdv::EOperationMode eMode)
   +void Shutdown()
   +bool WriteHeadLightLowBeam(bool value)
   -sdv::core::CSignal m_bHeadLightLowBeam
   -std::atomic<sdv::EObjectStatus> m_status
 }

 class sdv::CSdvObject
 {
   {static} +sdv::sequence<sdv::u8string> GetClassAliasesStatic()
   {static} +sdv::u8string GetDefaultObjectNameStatic()
   {static} +bool IsSingletonStatic()
   {static} +sdv::sequence<sdv::u8string> GetObjectDependenciesStatic()
 }

 Interface sdv::IObjectControl
 {
   {abstract} void Initialize(const sdv::u8string& ssObjectConfig)
   {abstract} EObjectStatus GetStatus() const
   {abstract} void SetOperationMode(EOperationMode eMode)
   {abstract} void Shutdown()
 }

 Interface vss::Vehicle::Body::Light::Front::LowBeamDevice::IVSS_WriteHeadLightLowBeam
 {
   {abstract} bool WriteHeadLightLowBeam(bool value)
 }

 CVehicleDeviceHeadLightLowBeam --|> sdv::CSdvObject : Inherits
 CVehicleDeviceHeadLightLowBeam ..|> sdv::IObjectControl : Implements
 CVehicleDeviceHeadLightLowBeam ..|> vss::Vehicle::Body::Light::Front::LowBeamDevice::IVSS_WriteHeadLightLowBeam : Implements

@enduml

HeadlightLowBeam vehicle device class diagram#

@startuml
 set separator ::
 class CVehicleDeviceCurrentLatitude
 {
   +void Initialize(const sdv::u8string& objectConfig)
   +sdv::EObjectStatus GetStatus() const
   +void SetOperationMode(sdv::EOperationMode eMode)
   +void Shutdown()
   +void RegisterCurrentLatitudeEvent(vss::Vehicle::Position::CurrentLatitudeDevice::IVSS_WriteCurrentLatitude_Event* event)
   +void UnregisterCurrentLatitudeEvent(vss::Vehicle::Position::CurrentLatitudeDevice::IVSS_WriteCurrentLatitude_Event* event)
   +void ExecuteAllCallBacksForFCurrentLatitude(sdv::any_t value);
   -sdv::core::CSignal m_fCurrentLatitudeSignal
   -mutable std::mutex m_fCurrentLatitudeMutexCallbacks
   -std::set<vss::Vehicle::Position::CurrentLatitudeDevice::IVSS_WriteCurrentLatitude_Event*> m_fCurrentLatitudeCallbacks
   -std::atomic<sdv::EObjectStatus> m_status
 }

 class sdv::CSdvObject
 {
   {static} +sdv::sequence<sdv::u8string> GetClassAliasesStatic()
   {static} +sdv::u8string GetDefaultObjectNameStatic()
   {static} +bool IsSingletonStatic()
   {static} +sdv::sequence<sdv::u8string> GetObjectDependenciesStatic()
 }

 Interface sdv::IObjectControl
 {
   {abstract} void Initialize(const sdv::u8string& ssObjectConfig)
   {abstract} EObjectStatus GetStatus() const
   {abstract} void SetOperationMode(EOperationMode eMode)
   {abstract} void Shutdown()
 }

 Interface vss::Vehicle::Position::CurrentLatitudeDevice::IVSS_CurrentLatitude
 {
   {abstract} void RegisterCurrentLatitudeEvent(IVSS_WriteCurrentLatitude_Event* event)
   {abstract} void UnregisterCurrentLatitudeEvent(IVSS_WriteCurrentLatitude_Event* event)
 }

 CVehicleDeviceCurrentLatitude --|> sdv::CSdvObject : Inherits
 CVehicleDeviceCurrentLatitude ..|> sdv::IObjectControl : Implements
 CVehicleDeviceCurrentLatitude ..|> vss::Vehicle::Position::CurrentLatitudeDevice::IVSS_CurrentLatitude : Implements

@enduml

Current latitude vehicle device class diagram#

@startuml
 set separator ::
 class CVehicleDeviceCurrentLongitude
 {
   +void Initialize(const sdv::u8string& objectConfig)
   +sdv::EObjectStatus GetStatus() const
   +void SetOperationMode(sdv::EOperationMode eMode)
   +void Shutdown()
   +void RegisterCurrentLongitudeEvent(vss::Vehicle::Position::CurrentLongitudeDevice::IVSS_WriteCurrentLongitude_Event* event)
   +void UnregisterCurrentLongitudeEvent(vss::Vehicle::Position::CurrentLongitudeDevice::IVSS_WriteCurrentLongitude_Event* event)
   -void ExecuteAllCallBacksForFCurrentLongitude(sdv::any_t value)
   -sdv::core::CSignal m_fCurrentLongitudeSignal
   -mutable std::mutex m_fCurrentLongitudeMutexCallbacks
   -std::set<vss::Vehicle::Position::CurrentLongitudeDevice::IVSS_WriteCurrentLongitude_Event*> m_fCurrentLongitudeCallbacks
   -std::atomic<sdv::EObjectStatus> m_status
 }

 class sdv::CSdvObject
 {
   {static} +sdv::sequence<sdv::u8string> GetClassAliasesStatic()
   {static} +sdv::u8string GetDefaultObjectNameStatic()
   {static} +bool IsSingletonStatic()
   {static} +sdv::sequence<sdv::u8string> GetObjectDependenciesStatic()
 }

 Interface sdv::IObjectControl
 {
   {abstract} void Initialize(const sdv::u8string& ssObjectConfig)
   {abstract} EObjectStatus GetStatus() const
   {abstract} void SetOperationMode(EOperationMode eMode)
   {abstract} void Shutdown()
 }

 Interface vss::Vehicle::Position::CurrentLongitudeDevice::IVSS_CurrentLongitude
 {
   {abstract} void RegisterCurrentLongitudeEvent(IVSS_WriteCurrentLongitude_Event* event)
   {abstract} void UnregisterCurrentLongitudeEvent(IVSS_WriteCurrentLongitude_Event* event)
 }

 CVehicleDeviceCurrentLongitude --|> sdv::CSdvObject : Inherits
 CVehicleDeviceCurrentLongitude ..|> sdv::IObjectControl : Implements
 CVehicleDeviceCurrentLongitude ..|> vss::Vehicle::Position::CurrentLongitudeDevice::IVSS_CurrentLongitude : Implements

@enduml

Current latitude vehicle device class diagram#