ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
You cannot use a shared pointer to this
in the constructor. You should use this->shared_from_this()
but you cannot do that in the constructor.
You could try creating the tf_broadcaster
on the first time you use it (store nullptr
until then).
Also, ideally the tf2_ros::TransformBroadcaster
would take some of the node interfaces, allowing you to pass them in the constructor.
2 | No.2 Revision |
You cannot use a shared pointer to this
in the constructor. You should use this->shared_from_this()
but you cannot do that in the constructor.
You could try creating the tf_broadcaster
on the first time you use it (store nullptr
until then).
Also, ideally the tf2_ros::TransformBroadcaster
would take some of the node interfaces, allowing you to pass them in the constructor.
EDIT: with respect to your suggestion...
Wouldn't it be easier, if the
rclcpp::Node
would inherit the transformer methods from a TransformBroadcaster class instead of instantiating it manually? E.g.class MyNode : public rclcpp::Node, tf2_ros::TransformBroadcaster {}
and then just callthis->sendTransform(tf);
.
That doesn't resolve the issue because the tf2_ros::TransformBroadcaster
still needs to access the node, so you'd need to delegate to the constructor for it during the member initialization (e.g. class MyNode : public rclcpp::Node, tf2_ros::TransformBroadcaster : rclcpp::Node(...), tf2_ros::TransformBroadcaster(this) {}
) and that requires that you pass this
, just like you have the issue now.