@@ -33,7 +33,8 @@ namespace dynamic_graph_bridge {
3333/* *
3434 * @brief Shortcut.
3535 */
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;
3738
3839/* *
3940 * @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;
5758 */
5859class Executor {
5960 public:
60- Executor () : ros_executor_(rclcpp::ExecutorOptions(), 4 ) {
61+ Executor () : ros_executor_(rclcpp::ExecutorOptions(), 30 ) {
6162 is_thread_running_ = false ;
6263 is_spinning_ = false ;
6364 list_node_added_.clear ();
@@ -234,7 +235,7 @@ bool ros_node_exists(std::string node_name) {
234235 GLOBAL_LIST_OF_ROS_NODE.end ()) {
235236 return false ;
236237 }
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 ) {
238239 return false ;
239240 }
240241 return true ;
@@ -248,19 +249,29 @@ ExecutorPtr get_ros_executor() {
248249 return EXECUTOR;
249250}
250251
251- RosNodePtr get_ros_node (std::string node_name) {
252- ros_init ();
252+ void create_ros_node (std::string& node_name) {
253253 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 =
260255 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);
261261 }
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);
262273 /* * 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]) ;
264275}
265276
266277void ros_add_node_to_executor (const std::string& node_name) {
@@ -290,8 +301,8 @@ void ros_display_list_of_nodes() {
290301 while (ros_node_it != GLOBAL_LIST_OF_ROS_NODE.end ()) {
291302 RCLCPP_INFO (rclcpp::get_logger (" dynamic_graph_bridge" ),
292303 " 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 ());
295306 ros_node_it++;
296307 }
297308}
0 commit comments