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

create subscriber for /turtle1/pose data

asked 2019-07-30 11:58:20 -0500

requestadepache gravatar image

updated 2019-07-30 12:37:10 -0500

jayess gravatar image

i tried to subscribe /turtle1/pose values to the node i created using this :

#include "ros/ros.h"
#include "turtlesim/Pose.h"
#include "std_msgs/Float32.h"
#include <sstream>

void callback(const turtlesim::Pose::ConstPtr& lis)

{

 std_msgs::Float32 m;

m.data=lis.x;

 ROS_INFO("i heard %f \n",m.data);

}

int main(int argc, char * argv[])
{

turtlesim::Pose lis;


ros::init(argc,argv,"listen");

ros::NodeHandle n;

ros::Subscriber sub1=n.subscribe("/turtle1/pose",1000,callback);

  ros::spin();

  return 0;
}

but it doesn't seem to work , i guess the problem is with the pointer lis since turtlesim::Pose is multi-dimensional array .

edit retag flag offensive close merge delete

Comments

but it doesn't seem to work

What do you mean? What does happen?

jayess gravatar image jayess  ( 2019-07-30 12:37:56 -0500 )edit

Thanks i solved it out , I had first to copy data from pointer to another variable with data type turtlesim::Pose For example , turtlesim::Pose V=* lis;. Then I can access V.x

requestadepache gravatar image requestadepache  ( 2019-07-30 12:42:57 -0500 )edit
1

Perhaps you can write up your solution as an answer instead of a comment?

jayess gravatar image jayess  ( 2019-07-30 12:56:15 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-07-30 12:58:36 -0500

requestadepache gravatar image

Solved: I had first to copy data from pointer to another variable with data type turtlesim::Pose For example , turtlesim::Pose V=* lis;. Then I can access V.x

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-07-30 11:58:20 -0500

Seen: 1,034 times

Last updated: Jul 30 '19