@@ -33,7 +33,8 @@ namespace dynamic_graph_bridge {
33
33
/* *
34
34
* @brief Shortcut.
35
35
*/
36
- typedef std::map<std::string, RosNodePtr> GlobalListOfRosNodeType;
36
+ typedef std::tuple<RosNodePtr, rclcpp::CallbackGroup::SharedPtr> NodeInfo;
37
+ typedef std::map<std::string, NodeInfo> GlobalListOfRosNodeType;
37
38
38
39
/* *
39
40
* @brief GLOBAL_LIST_OF_ROS_NODE is global variable that acts as a singleton on
@@ -57,7 +58,7 @@ static GlobalListOfRosNodeType GLOBAL_LIST_OF_ROS_NODE;
57
58
*/
58
59
class Executor {
59
60
public:
60
- Executor () : ros_executor_(rclcpp::ExecutorOptions(), 4 ) {
61
+ Executor () : ros_executor_(rclcpp::ExecutorOptions(), 30 ) {
61
62
is_thread_running_ = false ;
62
63
is_spinning_ = false ;
63
64
list_node_added_.clear ();
@@ -234,7 +235,7 @@ bool ros_node_exists(std::string node_name) {
234
235
GLOBAL_LIST_OF_ROS_NODE.end ()) {
235
236
return false ;
236
237
}
237
- if (GLOBAL_LIST_OF_ROS_NODE.at (node_name) == nullptr ) {
238
+ if (std::get< 0 >( GLOBAL_LIST_OF_ROS_NODE.at (node_name) ) == nullptr ) {
238
239
return false ;
239
240
}
240
241
return true ;
@@ -248,19 +249,29 @@ ExecutorPtr get_ros_executor() {
248
249
return EXECUTOR;
249
250
}
250
251
251
- RosNodePtr get_ros_node (std::string node_name) {
252
- ros_init ();
252
+ void create_ros_node (std::string& node_name) {
253
253
if (!ros_node_exists (node_name)) {
254
- GLOBAL_LIST_OF_ROS_NODE[node_name] = RosNodePtr (nullptr );
255
- }
256
- if (!GLOBAL_LIST_OF_ROS_NODE[node_name] ||
257
- GLOBAL_LIST_OF_ROS_NODE[node_name].get () == nullptr ) {
258
- /* * RosNode instanciation */
259
- GLOBAL_LIST_OF_ROS_NODE[node_name] =
254
+ RosNodePtr a_ros_node_ptr =
260
255
std::make_shared<RosNode>(node_name, " dynamic_graph_bridge" );
256
+ rclcpp::CallbackGroup::SharedPtr a_cb_group =
257
+ a_ros_node_ptr->create_callback_group (
258
+ rclcpp::CallbackGroupType::Reentrant);
259
+ /* * RosNode instanciation */
260
+ GLOBAL_LIST_OF_ROS_NODE[node_name] = NodeInfo (a_ros_node_ptr, a_cb_group);
261
261
}
262
+ }
263
+ RosNodePtr get_ros_node (std::string node_name) {
264
+ ros_init ();
265
+ create_ros_node (node_name);
266
+ /* * Return a reference to the node handle so any function can use it */
267
+ return std::get<0 >(GLOBAL_LIST_OF_ROS_NODE[node_name]);
268
+ }
269
+
270
+ rclcpp::CallbackGroup::SharedPtr get_callback_group (std::string node_name) {
271
+ ros_init ();
272
+ create_ros_node (node_name);
262
273
/* * Return a reference to the node handle so any function can use it */
263
- return GLOBAL_LIST_OF_ROS_NODE[node_name];
274
+ return std::get< 1 >( GLOBAL_LIST_OF_ROS_NODE[node_name]) ;
264
275
}
265
276
266
277
void ros_add_node_to_executor (const std::string& node_name) {
@@ -290,8 +301,8 @@ void ros_display_list_of_nodes() {
290
301
while (ros_node_it != GLOBAL_LIST_OF_ROS_NODE.end ()) {
291
302
RCLCPP_INFO (rclcpp::get_logger (" dynamic_graph_bridge" ),
292
303
" ros_display_list_of_nodes: %s/%s" ,
293
- ros_node_it->second ->get_namespace (),
294
- ros_node_it->second ->get_name ());
304
+ std::get< 0 >( ros_node_it->second ) ->get_namespace (),
305
+ std::get< 0 >( ros_node_it->second ) ->get_name ());
295
306
ros_node_it++;
296
307
}
297
308
}
0 commit comments