Ask Your Question
0

ROS_INFO error in the subscriber package [closed]

asked 2016-07-13 16:01:10 -0500

skr_robo gravatar image

updated 2016-07-13 16:05:35 -0500

Hello, I am trying to build a subscriber package to listen to tf_static. Here is the subscriber code:

//#include <iostream>
#include "ros/ros.h"
//#include "std_msgs/String.h"
#include "tf2_msgs/TFMessage.h"
#include "geometry_msgs/TransformStamped.h"
#include "geometry_msgs/Transform.h"
#include "geometry_msgs/Vector3.h"

//using namespace std;

    void tfCallback(const tf2_msgs::TFMessage::ConstPtr& msg)
    {
        ROS_INFO("I heard: [%f]", msg->transforms.transform.translation.x);
}
int main(int argc, char **argv)
{
    //cout << "Hello world!" << endl;
    ros::init(argc, argv, "tf_subscriber_node");
    ros::NodeHandle ntf;
    ros::Subscriber sub = ntf.subscribe("/tf_static",1000, tfCallback);
    ros::spin ();
    return 0;
}

I am receiving the following error:

src/tf_subscriber_node.cpp:13:47: error: 'const _transforms_type' has no member named 'transform' ROS_INFO("I heard: [%f]", msg->transforms.transform.translation.x);

I believe the error could be due to the const keyword. Or am I doing anything wrong in the part:

msg->transforms.transform.translation.x

Can anyone kindly guide on how to fix this?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by skr_robo
close date 2016-07-14 12:35:13.592106

1 Answer

Sort by ยป oldest newest most voted
3

answered 2016-07-13 16:11:54 -0500

Thomas D gravatar image

You have an array of transforms in that message. So you could do something like msg->transforms[0].transform.translation.x. Or you could put that in a for loop and print out each transform in the array of transforms. Since they are doubles (not float) you also probably want to change %f to %lf.

edit flag offensive delete link more

Comments

How did you figure out that it is an array; does the [] after geometry_msgs/TransformStamped in the page indicate that?

skr_robo gravatar image skr_robo  ( 2016-07-13 16:43:40 -0500 )edit

Yes, the [] indicates an array.

Thomas D gravatar image Thomas D  ( 2016-07-13 16:44:29 -0500 )edit

Also, does float64 indicate double?

skr_robo gravatar image skr_robo  ( 2016-07-13 16:48:52 -0500 )edit

I haven't yet tried your solution. I shall let you know, once I do it.

skr_robo gravatar image skr_robo  ( 2016-07-13 16:50:22 -0500 )edit

Yes, float64 indicates double. A float would be float32.

Thomas D gravatar image Thomas D  ( 2016-07-13 17:15:28 -0500 )edit

Thank You.

skr_robo gravatar image skr_robo  ( 2016-07-14 10:33:49 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2016-07-13 16:01:10 -0500

Seen: 1,279 times

Last updated: Jul 13 '16