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 inExecuteStep()and add pub/sub inAddPublisherAndSubscriber().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 withoutStandaloneInitData).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::VariantMessageis an alias ofrtidds::FmuMessage(andVariantData/VariantDatatypealiasFmuData/FmuDatatype). Seecore/communication/topic_registry.h.- For
VariantMap, see native helpers and converters incore/communication/utils/variant_map.handcore/communication/utils/variant_map_converter.h.
Limitation of topic
As mentioned in the sections above, activities can exchange data using messages throughTopics. 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 bycore/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:
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.
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.hfor the canonical Topic type aliases, details, and examples - Topic type:
core::topic_registry::VariantDataTopicType(usesrtidds::VariantMessage)
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(usesrtidds::VariantMap)
VariantMap directly:
VariantMap and convert to/from DDS:
core/communication/topic_registry.hfor all Topic type aliases and examplescore/communication/utils/variant_map.handcore/communication/utils/variant_map_converter.hfor the native map API and converters
Examples
Following the API documentation and the many sample activities insimfwk_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.
simfwk_cli:
Access Global Static Parameters and Timestamp
TheIActivity 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.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