You can process data that you receive in two ways:
If data is read synchronously, the user might be interested in the most recent data only. For most of our own data types, we use a self-created header that contains timing information:
The Reader class can be used to create a data reader from which only the most recent valid data can be requested, using
get_sample. Data is valid if its
valid_after_stamp is lower than the current timestamp
t_now that is passed to the function with which you can obtain the most recent data (the .hpp should contain all required information). You can use it for data types like trajectories or vehicle data.
The Reader stores all received data in a ring buffer. The order in which data arrives is not regarded when data gets overwritten. Thus, some slightly newer samples might get lost if
If you only need a basic DDS reader, then you should preferably use this class. It only offers information regarding matched publications and a take() function. It does not require the user to know or understand DDS implementation details - please only used more advanced concepts if you really need to. Setting QoS parameters is available through the constructor.
Data received by a DDS Reader can either be read synchronously or asynchronously. The latter requires the usage of e.g. a StatusCondition, an AsyncWaitSet and a callback function. To save the users the time to look up which StatusCondition is (mostly) required and to write the > 10 lines of code required for every single reader that relies on a callback function, AsyncReader is provided as a sort of wrapper that performs the set-up.
The class must be passed a callback function. Please be aware that your callback function will be called within the AsyncReader's own thread, so you need to use e.g. a mutex to protect your data, and you might have to use lambda captures or std::bind to be able to access e.g. your class members from within the function. It also requires a domain participant (or none, the default then is ParticipantSingleton) and a topic (or a filtered topic) or topic string (for the topic name). Reliable communication can be turned on / off with a boolean parameter.
Like Reader.hpp, but for multiple vehicles at once: Gather all received messages of type T by all vehicles that publish on the (filtered) topic my_topic, then return all newest samples when
get_samples is used. For more information on the implementation, refer to Reader.hpp. An example for a MultiVehicleReader is provided at the central routing example.
The reader in MultiVehicleReader uses a history of up to 2000 samples (it only buffers the most recent 2000 samples). This is due to performance reasons and because take() might not return all received messages immediately (it sometimes needs to be called more than once internally). The value of 2000 samples might not be enough depending on your scenario. In that case, i.e. if messages of some vehicles are sometimes missing because the buffer is not large enough, you might have to increase this value.
This is a basic DDS Writer, which only offers information regarding matched subscriptions and a write() function. It does not require the user to know or understand DDS implementation details and is thus recommended whenever a basic writer is required in your application. Setting QoS parameters is available through the constructor. You can find examples for a writer-implementation in every provided example as it is essential to transmit the trajectory to the vehicles.