Ask Your Question
0

Subscribe to endpoint_state, and save the pose position coordinates for later use

asked 2014-07-01 14:04:44 -0600

grisam gravatar image

updated 2014-07-01 14:33:01 -0600

On the terminal, I'm entering in

$ rostopic echo /robot/limb/left/endpoint_state

to get the position of the endpoints. The output comes out like this:

pose:  
position: x: 0.0881700859423
y: 0.666633918353
z: -0.25671871773  
...

Now, in my program, I want to subscribe to this topic and retrieve just the above coordinates: the pose x, y and z. My subscriber looks like this:

ros::Subscriber sub = n.subscribe("/robot/limb/left/endpoint_state", 1, leftEndpointCallback)

In my callback, I'm trying to get just these specific coordinates as floats or doubles or whatever data type they are, and be able to use them later in my code (i.e. use the x coordinate in an if statement, for example). How would I do this?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2014-07-15 14:29:09 -0600

Francisco gravatar image

The first thing to do is determine what is the message used in that topic, e.g:

$ rostopic info /robot/limb/left/endpoint_state
Type: baxter_core_msgs/EndpointState

Therefore, your function leftEndpointCallback should look like this:

void leftEndpointCallback(const baxter_core_msgs::EndpointStateConstPtr& _msg) 
{
  // The pose is within the _msg object
  ROS_INFO_STREAM("pose: " << _msg->pose);
  ROS_INFO_STREAM("pose.position.x: " << _msg->pose.position.x);
  ROS_INFO_STREAM("pose.position.y: " << _msg->pose.position.y);
  ROS_INFO_STREAM("pose.position.z: " << _msg->pose.position.z);
}

How to use these values somewhere else is scope of C/C++ callbacks. If you really need to process this data outside the callback you may consider implementing a Class. It seems that most people hate global variables (count me as well)

edit flag offensive delete link more

Comments

Is there a way I could do this and get only ONE specific point? I keep getting a stream of points but I only want the coordinates at one time instance. Also, what do you mean it's within the scope? If I save _msg->pose.position.x as a variable, how would I access that variable outside the callback?

grisam gravatar imagegrisam ( 2014-07-23 11:05:52 -0600 )edit
0

answered 2018-06-25 20:32:59 -0600

updated 2018-06-26 02:26:38 -0600

jayess gravatar image

Yout have to add pose.pose.position.x;

void leftEndpointCallback(const baxter_core_msgs::EndpointStateConstPtr& _msg) 
{
  // The pose is within the _msg object
  ROS_INFO_STREAM("pose: " << _msg->pose);
  ROS_INFO_STREAM("pose.position.x: " << _msg->pose.pose.position.x);
  ROS_INFO_STREAM("pose.position.y: " << _msg->pose.pose.position.y);
  ROS_INFO_STREAM("pose.position.z: " << _msg->pose.pose.position.z);
}
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2014-07-01 14:04:44 -0600

Seen: 654 times

Last updated: Jun 26 '18