Skip to main content
Simulation Framework provides the possibility to inject any custom logic into a standalone activity, which is a separate process running outside simfwk_cli, but is able to connect with the simfwk core and communicate with other activities.

Interfaces and topic definition in Autonomy

To implement a customized standalone activity, review these essential pieces:
  • core/lifecycle/activity/base_activity.h: base class for all activities; implement logic in ExecuteStep() and add pub/sub in AddPublisherAndSubscriber().
  • core/service/standalone_activity_service/standalone_activity_service.h: runs your activity process and binds it to core scheduling/communication.
  • core/service/standalone_activity_service/standalone_activity_creator/i_standalone_activity_creator.h: defines how your standalone activity is instantiated (with or without StandaloneInitData).
  • core/communication/topic_registry.h: the canonical list of Topic type aliases and DDS message types, with examples.
topic_registry defines concrete Topics you can use to create communication channels with given underlying DDS messages. Each TopicId (string) is globally unique and represents a single Topic; multiple Topics can share the same underlying message type. Currently, these Topics and Message Types are available with the Simulation Framework core library: Tip:
  • rtidds::VariantMessage is an alias of rtidds::FmuMessage (and VariantData/VariantDatatype alias FmuData/FmuDatatype). See core/communication/topic_registry.h.
  • For VariantMap, see native helpers and converters in core/communication/utils/variant_map.h and core/communication/utils/variant_map_converter.h.

Limitation of topic

As mentioned in the sections above, activities can exchange data using messages through Topics. Users must be careful to ensure deterministic behavior of the simulation. This means that one Topic should have only one publisher. The issue with having multiple publishers on the same topic is that the first message from the faster publisher may arrive on the subscriber side and get consumed, while the second message from the slower publisher might be neglected. Hence, Simulation Framework enforces a “single publisher only” to ensure deterministic behavior of the simulation. If multiple publishers for one topic are instantiated, an exception will be thrown to prevent this.

Customize your topic

By means of any existing message type provided by core/communication/topic_registry.h, you can create any Topic you need for your simulations. Example of creating a new Topic with Message Type rtidds::GenericBytesMessage in one line:
After that, your_topic is ready to be used to instantiate your activities.

Create a Topic using GenericBytesMessage

rtidds::GenericBytesMessage is a generic type that lets you carry arbitrary serialized payloads (protobuf, custom binary, etc.) as a bytes array. A common use case is transporting OSI protobuf messages.
Subscriber-side deserialization:

Create a Topic using VariantMessage (alias of FmuMessage)

rtidds::VariantMessage is currently an alias of rtidds::FmuMessage. Likewise, rtidds::VariantData aliases rtidds::FmuData, and rtidds::VariantDatatype aliases rtidds::FmuDatatype. This gives you a semantic “Variant” naming today while staying 100% compatible with FMU messages.
  • See core/communication/topic_registry.h for the canonical Topic type aliases, details, and examples
  • Topic type: core::topic_registry::VariantDataTopicType (uses rtidds::VariantMessage)
Publish/subscribe example:
You can equivalently replace rtidds::VariantMessage with rtidds::FmuMessage in the code above due to the aliasing.

Create a Topic using VariantMap

rtidds::VariantMap offers a flexible key/value format with typed values and an optional timestamp per entry. For convenience, a native C++ VariantMap API and bi-directional converters are provided:
  • Native map and helpers: core/communication/utils/variant_map.h
  • Converters: core/communication/utils/variant_map_converter.h
  • Topic type: core::topic_registry::VariantMapTopicType (uses rtidds::VariantMap)
Option A — Publish DDS VariantMap directly:
Option B — Use native C++ VariantMap and convert to/from DDS:
Option C — Convert from VariantMessage/FmuMessage into VariantMap for publishing:
See also:
  • core/communication/topic_registry.h for all Topic type aliases and examples
  • core/communication/utils/variant_map.h and core/communication/utils/variant_map_converter.h for the native map API and converters

Examples

Following the API documentation and the many sample activities in simfwk_examples (if installed), you can learn step by step how to build activities for any customized simulation.

Use one standalone activity

You can use one standalone activity, e.g. my_test_activity by defining the following JSON content in simulation_scheduling.
and use it in a simulation by running simfwk_cli:

Access Global Static Parameters and Timestamp

The IActivity interface and its derived class, core/lifecycle/activity/base_activity.h, provide several APIs to retrieve information related to the current simulation context. These include the current simulation timestamp, the cycle time for an activity, the simulation output directories, and input files. Available APIs are as follows:

Simulation timestamp

This API returns the current simulation timestamp, allowing your logic to access the exact simulation time at any given moment during execution.

Cycle time

This API returns the cycle time for this activity, based on the scheduling configuration you have provided for simulation.

Simulation output directory

This API returns the directory path where the outputs of the simulation are stored.

4. Customized parameter from comamnd line

This API returns the customized parameters for the simulation as a map.
In Simulation Framework Autonomy, three common input files, i.e. open scenario, driver input and user settings are assigned as “customized parameters” to the whole simulation and they can be retrieved by above API without any issue if the solver settings are correctly provided. The predefined names of these three common inputs can be found here autonomy/simulation/sim_instance/simulation_input_definition.h. To ensure any other custom input files or parameters are available via this API, they must be provided through CLI arguments using the pattern “name:value”. For more instructions, please see command line tool