bridge.hpp
Go to the documentation of this file.
1 // Copyright 2018 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef ROS_IGN_BRIDGE__BRIDGE_HPP_
16 #define ROS_IGN_BRIDGE__BRIDGE_HPP_
17 
18 #include <memory>
19 #include <string>
20 
21 // include ROS
22 #include <ros/console.h>
23 #include <ros/node_handle.h>
24 
25 // include Ignition Transport
26 #include <ignition/transport/Node.hh>
27 
28 #include "factories.hpp"
29 
30 namespace ros_ign_bridge
31 {
32 
34 {
36  ignition::transport::Node::Publisher ign_publisher;
37 };
38 
40 {
41  std::shared_ptr<ignition::transport::Node> ign_subscriber;
43 };
44 
46 {
49 };
50 
53  ros::NodeHandle ros_node,
54  std::shared_ptr<ignition::transport::Node> ign_node,
55  const std::string & ros_type_name,
56  const std::string & ros_topic_name,
57  size_t subscriber_queue_size,
58  const std::string & ign_type_name,
59  const std::string & ign_topic_name,
60  size_t publisher_queue_size)
61 {
62  auto factory = get_factory(ros_type_name, ign_type_name);
63  auto ign_pub = factory->create_ign_publisher(
64  ign_node, ign_topic_name, publisher_queue_size);
65 
66  auto ros_sub = factory->create_ros_subscriber(
67  ros_node, ros_topic_name, subscriber_queue_size, ign_pub);
68 
69  BridgeRosToIgnHandles handles;
70  handles.ros_subscriber = ros_sub;
71  handles.ign_publisher = ign_pub;
72  return handles;
73 }
74 
75 BridgeIgnToRosHandles
77  std::shared_ptr<ignition::transport::Node> ign_node,
78  ros::NodeHandle ros_node,
79  const std::string & ign_type_name,
80  const std::string & ign_topic_name,
81  size_t subscriber_queue_size,
82  const std::string & ros_type_name,
83  const std::string & ros_topic_name,
84  size_t publisher_queue_size)
85 {
86  auto factory = get_factory(ros_type_name, ign_type_name);
87  auto ros_pub = factory->create_ros_publisher(
88  ros_node, ros_topic_name, publisher_queue_size);
89 
90  factory->create_ign_subscriber(
91  ign_node, ign_topic_name, subscriber_queue_size, ros_pub);
92 
93  BridgeIgnToRosHandles handles;
94  handles.ign_subscriber = ign_node;
95  handles.ros_publisher = ros_pub;
96  return handles;
97 }
98 
99 BridgeHandles
101  ros::NodeHandle ros_node,
102  std::shared_ptr<ignition::transport::Node> ign_node,
103  const std::string & ros_type_name,
104  const std::string & ign_type_name,
105  const std::string & topic_name,
106  size_t queue_size = 10)
107 {
108  ROS_DEBUG_STREAM("Creating bidirectional bridge for topic" << topic_name
109  << " with ROS type [" << ros_type_name << "] and Ignition Transport"
110  << " type [" << ign_type_name << "]");
111 
112  BridgeHandles handles;
114  ros_node, ign_node,
115  ros_type_name, topic_name, queue_size, ign_type_name, topic_name, queue_size);
117  ign_node, ros_node,
118  ign_type_name, topic_name, queue_size, ros_type_name, topic_name, queue_size);
119  return handles;
120 }
121 
122 } // namespace ros_ign_bridge
123 
124 #endif // ROS_BRIDGE__BRIDGE_HPP_
ros_ign_bridge::BridgeIgnToRosHandles::ros_publisher
ros::Publisher ros_publisher
Definition: bridge.hpp:42
node_handle.h
ros::Publisher
ros_ign_bridge::get_factory
std::shared_ptr< FactoryInterface > get_factory(const std::string &ros_type_name, const std::string &ign_type_name)
Definition: factories.cpp:408
ros_ign_bridge::BridgeRosToIgnHandles::ros_subscriber
ros::Subscriber ros_subscriber
Definition: bridge.hpp:35
ros_ign_bridge::create_bridge_from_ros_to_ign
BridgeRosToIgnHandles create_bridge_from_ros_to_ign(ros::NodeHandle ros_node, std::shared_ptr< ignition::transport::Node > ign_node, const std::string &ros_type_name, const std::string &ros_topic_name, size_t subscriber_queue_size, const std::string &ign_type_name, const std::string &ign_topic_name, size_t publisher_queue_size)
Definition: bridge.hpp:52
ros_ign_bridge::create_bridge_from_ign_to_ros
BridgeIgnToRosHandles create_bridge_from_ign_to_ros(std::shared_ptr< ignition::transport::Node > ign_node, ros::NodeHandle ros_node, const std::string &ign_type_name, const std::string &ign_topic_name, size_t subscriber_queue_size, const std::string &ros_type_name, const std::string &ros_topic_name, size_t publisher_queue_size)
Definition: bridge.hpp:76
ROS_DEBUG_STREAM
#define ROS_DEBUG_STREAM(args)
console.h
ros_ign_bridge::BridgeRosToIgnHandles
Definition: bridge.hpp:33
ros_ign_bridge::BridgeHandles::bridgeIgnToRos
BridgeIgnToRosHandles bridgeIgnToRos
Definition: bridge.hpp:48
ros_ign_bridge::create_bidirectional_bridge
BridgeHandles create_bidirectional_bridge(ros::NodeHandle ros_node, std::shared_ptr< ignition::transport::Node > ign_node, const std::string &ros_type_name, const std::string &ign_type_name, const std::string &topic_name, size_t queue_size=10)
Definition: bridge.hpp:100
ros_ign_bridge
Definition: convert.hpp:59
factories.hpp
ros_ign_bridge::BridgeRosToIgnHandles::ign_publisher
ignition::transport::Node::Publisher ign_publisher
Definition: bridge.hpp:36
ros_ign_bridge::BridgeIgnToRosHandles
Definition: bridge.hpp:39
ros_ign_bridge::BridgeIgnToRosHandles::ign_subscriber
std::shared_ptr< ignition::transport::Node > ign_subscriber
Definition: bridge.hpp:41
ros_ign_bridge::BridgeHandles::bridgeRosToIgn
BridgeRosToIgnHandles bridgeRosToIgn
Definition: bridge.hpp:47
ros::NodeHandle
ros::Subscriber
ros_ign_bridge::BridgeHandles
Definition: bridge.hpp:45


ros_ign_bridge
Author(s):
autogenerated on Sat Mar 11 2023 04:02:16