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

Accessing translation data from geometry_msgs::TransformStamped

asked 2019-06-04 14:00:00 -0500

warriorUSP gravatar image

I want to access the x, y, z values and quaternion values in a geometry_msgs/TransformStamped.msg , so my subsrciber looks like:

#include "ros/ros.h"
#include <geometry_msgs/TransformStamped.h>

void geoCallback(const geometry_msgs::TransformStampedConstPtr& pose){
    ROS_INFO(pose->transform.translation.x);
}

int main(int argc, char **argv){
    ros::init(argc, argv, "tf_subscriber_node");
    ros::NodeHandle nh;
    ros::Subscriber sub = nh.subscribe("/tf_static",1000, geoCallback);
    ros::spin ();
    return 0;
}

So while printing float64 x using ROS_INFO , I am getting error during compilation like error in printing const _x_type& , in particular error looks like:

/opt/ros/kinetic/include/ros/console.h:346:176: error: no matching function for call to _print(int, void*&, ros::console::Level&, const char [58], int, const char [50], const _x_type&)

So why it is saying _x_type& , instead of float64 for x ? And how could I access the x, y and z value properly? And this is my included header file geometry_msgs/TransformStamped.h

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-06-04 14:33:36 -0500

gvdhoorn gravatar image

updated 2019-06-04 14:39:07 -0500

void geoCallback(const geometry_msgs::TransformStampedConstPtr& pose){
    ROS_INFO(pose->transform.translation.x);
}

There is a version of ROS_INFO(..) that takes only a single argument, but that argument must then be a string (well, a char* I believe, but basically a string), not a single double (float64 is the name of the rosmsg IDL type, not a C++ type).

This is not Python, so you cannot just do print (float(123)).

As mentioned in #q12837, ROS_INFO(..) and the other ROS_*(..) logging macros support printf arguments, so in order to print a single double, you'd do something like:

ROS_INFO("%f", pose->transform.translation.x);

See also wiki/roscpp/Overview/Logging - Log Statements.

edit flag offensive delete link more

Comments

Worked like a charm.
But why it cant say Expected argument is string but given double, then debugging would be a lot easier.

warriorUSP gravatar image warriorUSP  ( 2019-06-04 14:59:44 -0500 )edit
1

This is C++.

Additionally: ROS_INFO(..) is a macro, auto-generated and goes through a lot of layers before it comes to something that the compiler sees. At that point the context is completely different, making it hard to print such errors.

In any case: you should ask this of your C++ compiler team/oem/writer. Not on a ROS forum.

gvdhoorn gravatar image gvdhoorn  ( 2019-06-04 15:03:45 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2019-06-04 14:00:00 -0500

Seen: 1,226 times

Last updated: Jun 04 '19