create subscriber for /turtle1/pose data
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 .
Asked by requestadepache on 2019-07-30 11:58:20 UTC
Answers
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
Asked by requestadepache on 2019-07-30 12:58:36 UTC
Comments
What do you mean? What does happen?
Asked by jayess on 2019-07-30 12:37:56 UTC
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
Asked by requestadepache on 2019-07-30 12:42:57 UTC
Perhaps you can write up your solution as an answer instead of a comment?
Asked by jayess on 2019-07-30 12:56:15 UTC