Confusion about move_group node creation (ROS2, C++) in Open Class #148

Hi,

in the ROS2 Motion Planning using C++ | ROS2 Developers Open Class [#148], the main looks as follows:

int main(int argc, char **argv) {
  rclcpp::init(argc, argv);
  rclcpp::NodeOptions node_options;
  node_options.automatically_declare_parameters_from_overrides(true);
  auto move_group_node =
      rclcpp::Node::make_shared("move_group_demo", node_options);

  rclcpp::executors::SingleThreadedExecutor planner_executor;
  std::shared_ptr<TestTrajectory> planner_node =
      std::make_shared<TestTrajectory>(move_group_node);
  planner_executor.add_node(planner_node);
  planner_executor.spin();

  rclcpp::shutdown();
  return 0;
}

I’m mainly confused about what exactly happens in the node creation. Why are we first creating the move_group_node and then the planner_node? Are they two separate nodes or what is their relation since we’re only adding the latter to the executor?

Thanks in advance!

Hello @comala ,

The planner_node is an instance of the class TestTrajectory, as you can see:

std::shared_ptr<TestTrajectory> planner_node

And from the constructor, you can see that the class constructor is expecting to receive a node on initialization:

TestTrajectory(std::shared_ptr<rclcpp::Node> move_group_node)

This is why we need to create first the move_group_node in order to provide it to the class:

std::make_shared<TestTrajectory>(move_group_node);

Hope this helps clarify it.

Thanks! It actually makes a lot of sense now :wink:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.