YARP
Yet Another Robot Platform
Loading...
Searching...
No Matches
Ros2Subscriber.h
Go to the documentation of this file.
1
/*
2
* SPDX-FileCopyrightText: 2023 Istituto Italiano di Tecnologia (IIT)
3
* SPDX-License-Identifier: BSD-3-Clause
4
*/
5
6
#ifndef ROS2_SUBSCRIBER_H
7
#define ROS2_SUBSCRIBER_H
8
9
#include <iostream>
10
#include <cstring>
11
12
#include <
yarp/os/LogStream.h
>
13
14
#include <
yarp/os/LogComponent.h
>
15
#include <rclcpp/rclcpp.hpp>
16
17
18
19
template
<
class
CallbackClass,
typename
MsgClass>
20
class
Ros2Subscriber
21
{
22
public
:
23
Ros2Subscriber
(rclcpp::Node::SharedPtr node, CallbackClass* callbackClass);
24
25
void
subscribe_to_topic
(std::string topic_name);
26
private
:
27
rclcpp::Node::SharedPtr m_node;
28
CallbackClass* m_callbackClass;
29
std::vector<typename rclcpp::Subscription<MsgClass>::SharedPtr> m_subscription;
30
};
31
32
template
<
class
CallbackClass,
typename
MsgClass>
33
Ros2Subscriber<CallbackClass, MsgClass>::Ros2Subscriber
(rclcpp::Node::SharedPtr node, CallbackClass* callbackClass)
34
{
35
m_node = node;
36
m_callbackClass = callbackClass;
37
}
38
39
40
template
<
class
CallbackClass,
typename
MsgClass>
41
void
Ros2Subscriber<CallbackClass, MsgClass>::subscribe_to_topic
(std::string topic_name) {
42
yInfo
() <<
"Ros2Subscriber creating topic: "
<< topic_name;
43
m_subscription.push_back(m_node->create_subscription<MsgClass>(
44
topic_name,
45
10,
46
[
this
, topic_name](
const
typename
MsgClass::SharedPtr msg) {
47
m_callbackClass->callback(msg, topic_name);
48
}));
49
}
50
#endif
//ROS2_SUBSCRIBER_H
LogStream.h
yInfo
#define yInfo(...)
Definition
Log.h:319
Ros2Subscriber
Definition
Ros2Subscriber.h:21
Ros2Subscriber::Ros2Subscriber
Ros2Subscriber(rclcpp::Node::SharedPtr node, CallbackClass *callbackClass)
Definition
Ros2Subscriber.h:33
Ros2Subscriber::subscribe_to_topic
void subscribe_to_topic(std::string topic_name)
Definition
Ros2Subscriber.h:41
LogComponent.h
YARP
3.11.100+20250603.4+gitaa77f8b5c
opt-modules
yarp-devices-ros2
src
devices
ros2Utils
Ros2Subscriber.h
Generated on Wed Jun 4 2025 02:39:56 for YARP by
1.9.8