Robotics StackExchange | Archived questions

Type of NodeT

Hello,

If we compare the TF2 static broadcaster tutorial to the TF2 broadcaster tutorial, the broadcaster in the former takes this as an argument, while the latter takes *this:

f_static_broadcaster_ = std::make_shared<tf2_ros::StaticTransformBroadcaster>(this);

tf_broadcaster_ =  std::make_unique<tf2_ros::TransformBroadcaster>(*this);

I tried to add and remove the * and it turns out that both compile and run fine, with and without the *.

In contrast, other code does specifically require a pointer, e.g. the action server tutorial does not compile if this is changed to *this:

this->action_server_ = rclcpp_action::create_server<Fibonacci>(
  this,
  "fibonacci",
  std::bind(&FibonacciActionServer::handle_goal, this, _1, _2),
  std::bind(&FibonacciActionServer::handle_cancel, this, _1),
  std::bind(&FibonacciActionServer::handle_accepted, this, _1));

Is there some specific rationale wrt to choosing to pass either a pointer or an object? And how to know which functions take what? Since both the TransformBroadcaster as well as the create_server functions take a template class NodeT (so afaik not distinguishable whether this could/should be an object or a pointer?).

Asked by jrtg on 2022-11-23 04:04:18 UTC

Comments

Answers