-
Notifications
You must be signed in to change notification settings - Fork 1
Data Manager
The Manager class handle ROS messages to store and access them during an experiment. This class can listen to a ROS topic to store the incoming messages.
There are two version of Manager, the ManagerMap and the MangerQueue. Each version use a different standard C++ library container to store the data. Only the method to access the data are different between the two.
This paragraph explain how the Manager retrieve the data and append them in its storage. This part is common to ManagerMap and the ManagerQueue. To retrieve messages, the Manager subscribe to a topic. For this, you must use the listen_to method. The listen_to method connect the manager to a specific topic.
/**
* @brief Connects to a specific topic and listen to it.
* @param The topic to listen to.
*/
void listen_to(const std::string& topic, io type_io = ADD)
{
if (type_io == ADD) {
_subcriber.reset(new ros::Subscriber(ros_nh->subscribe(topic, 10, &ManagerBase::add_cb, this)));
}
}The callback function add_cb call the add method from the DerivedClass which is ManagerMap or ManagerQueue.
/**
* @brief The callback function used to process messages from the listened topic.
* @param msg
*/
void add_cb(const shared_ptr<Msg>& msg)
{
static_cast<DerivedClass *>(this)->add(*msg);
}ManagerMap and ManagerQueue have differents ways to access the stored data.
The ManagerMap store his data in an std::unordered_map. The keys are the header.seq provided in the message (std_msgs/header).
You can access the data in two different ways :
- The method get provide a random access to the data
- The method search provide a access to a specific data with a key
The ManagerMap is a typedef of Manager<Msg, std::unordered_map<u_int32_t, Msg>>. The both semantics are allowed but for a lighter and more readable code it is better to use the ManagerMap word.
The ManagerQueue store his data in a std::deque that is a double ended queue. You can append and access to both ends. But in this case, the ManagerQueue is use as a FIFO (First In First Out) container. So, this Data Manager behave like a buffer where stored the data only to use them in a short time scale. You can access the data by the method get. get return the first element added.
The ManagerQueue is a typedef of Manager<Msg, std::deque<Msg>>. The both semantics are allowed but for a lighter and more readable code it is better to use the ManagerQueue word.