ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ROS2/C++ Creating multiple Nodes or Publisher dynamically?

asked 2022-12-20 15:42:29 -0500

gianalessio gravatar image

Hello! Follwing minimal example:

My ReceiverNode subscribes to a list with multiple objects, each Object has a Timestamp + Positon + Velocity + Orienation For each Object I wan to create a publisher which publishes its current Position.

What is the best way to create these multiple Publisher?

My Ideas

  1. Create somehow a node for each object? Can I create multiple Nodes from my ReceiverNode, I only know hot to start a ros node in the main using: rclcpp::init(argc, argv); rclcpp::spin(std::make_shared<test::ReceiverNode()); rclcpp::shutdown();
  2. Create a publisher for every Object inside my ReceiverNode? Since I am using classes I need to use a vector of publisher as a class member? And a vector of timer? Does that work?

What is the best way here?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-12-21 07:14:20 -0500

Per Edwardsson gravatar image

I would recommend using a custom message with all the data you require (timestamp, position, velocity, orientation, object type), and then have a single node with a single publisher which publishes many things onto this topic. If this, for some reason, is not advisable in your use case, create one publisher per object type and do some copy pasting. Or perhaps preferable, make a c++ template and just call that.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2022-12-20 15:42:29 -0500

Seen: 366 times

Last updated: Dec 21 '22