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

Can't get data from topic

asked 2017-03-24 11:10:18 -0600

jsoley gravatar image

Hi, I am trying to get data from ar_pose_markers. I am running the package and I see the topic is refreshing with new data. I am using ar_tools and usb_cam.

I have to make a node that subscribe to this topic and it able to extract the information. I am subscribing to the topic but I can extract the position. This code give me a number but is the same number all the time.

The node code is the following one

#include "ros/ros.h"
#include "std_msgs/String.h"
#include <ar_pose/ARMarkers.h>

int yo=10;
int zo;
int i=0;
void ar_pose_markerCallback(const ar_pose::ARMarkers::ConstPtr& msg)
float xo=0;
ROS_INFO("hello world");
ar_pose::ARMarker ar_pose_marker;
ROS_INFO("%d", xo);


int main(int argc, char **argv)
ROS_INFO("hello world");
ros::init(argc, argv, "node_sub");
ros::NodeHandle n;
ros::Rate loop_rate(1);
ros::Subscriber sub = n.subscribe("ar_pose_marker", 1, ar_pose_markerCallback);
while (ros::ok())



} return 0; }

edit retag flag offensive close merge delete


Notice how you are not assigning anything with the received message msg.

nlamprian gravatar image nlamprian  ( 2017-03-24 12:30:25 -0600 )edit

Yes!!! You are not using the message at all!!! You have just declared a variable with that type of message. Now, you try using the msg.

saikishor gravatar image saikishor  ( 2017-03-25 04:41:10 -0600 )edit

Use this "msg->markers[0]" to fetch data in the function.

saikishor gravatar image saikishor  ( 2017-03-29 06:56:27 -0600 )edit

1 Answer

Sort by » oldest newest most voted

answered 2017-03-25 08:06:32 -0600

Man, like they say, use the msg to get the topic information. I can provide you some notes if you want.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2017-03-24 11:10:18 -0600

Seen: 202 times

Last updated: Mar 24 '17