simfwk_cli, but is able to connect with the simfwk core and communicate with other activities.
Interfaces and topic definition in RefSim
To implement one customized standalone activity, you need to have a look on essential interfaces:core/lifecycle/activity/base_activity.h , core/service/standalone_activity_service/standalone_activity_service.h , core/service/standalone_activity_service/standalone_activity_creator/i_standalone_activity_creator.h and topic definitions core/communication/topic_registry.h .
BaseActivity is the basic implementation of IActivity interface and used as base class of all customized activities. Inheriting classes, i.e. a concrete simulation activity, should implement their logic in ExecuteStep() and add needed pub/sub in AddPublisherAndSubscriber() method to achieve communications between others.
IStandaloneActivityCreator is the interface class for creating a standalone activity service. It defines how a customized activity needs to be instantiated through or not through StandaloneInitData.
StandaloneActivityService provides a running process of desired activity returned by interface IStandaloneActivityCreator and keeps it communicating and being scheduled by Simulation Framework core process.
topic_registry is a dedicated namespace where defines list of concrete Topics that can be used for creation of communication channels with given underlying message. As default, DDS message/communication type will be applied. The name of Topic ( TopicId ), which is passed into constructor to Topic, is globally unique and represents one single Topic, the underlying message could be the same though.
Currently following Topics and Message Type are available to use with Simulation Framework core library:
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 message type which allows users to put any content as a serialized byte array. E.g. GenericBytesTopicType, which stores the OSI protobuf message as underlying payload, is a good example to show how this mechanism works out. If you have a protobuf message which you want to send, you only need to call protobuf C++ API like following:
GenericBytesMessage generic_msg with your desired content and can publish it into the Topic defined with “YourTopicId”.
On the subscriber side, you just need to decode the message from bytes array.
/example/my_customized_topic/my_activities.h after installation.
Example standalone activity
There is an example implementation ofStandalone Activity provided by the Simulation Framework delivery, namely simulation_framework/example/my_activity/my_activity.h . This Activity can be executed independently from simfwk_cli , and they will wait for simulation requests from simfwk_cli if they are selected in the simulation config.
Following the code API documentation and instruction in the comments of this example implementation, you can learn how to build your own Activity step by step and use it in a simulation.
Use one standalone activity
You can use the example standalone activitymy_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:
This API returns the current simulation timestamp, allowing your logic to access the exact simulation time at any given moment during execution.
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