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

Revision history [back]

The following error you reported seems correct:

error: no matching function for call to ‘toMsg(tf2::Vector3&, geometry_msgs::msg::Point&)’ 34 | toMsg(v_out, t_out);

The tf2_geometry_msgs.h page you are looking belongs to ROS Noetic. The tf2_geometry_msgs.h in ROS Galactic does not use tf2::toMsg function.

Anyway, lets go back to the question. Using tf2::toMsg(v_out, t_out), you are essentially converting tf2::Vector3 into geometry_msgs::msg::Point. Please see below the structure of geometry_msgs/msg/Point message:

# This contains the position of a point in free space

float64 x
float64 y
float64 z

The above definition has been take from here.

We can easily convert tf2::Vector3 into geometry_msgs::msg::Point using the following code:

tf2::Vector3 v_out(1.0, 2.0, 3.0);

geometry_msgs::msg::Point t_out;
t_out.x = v_out.getX();
t_out.y = v_out.getY();
t_out.z = v_out.getZ();