Ask Your Question
0

Read variable from PoseStamped C++

asked 2018-01-30 03:38:53 -0600

Lauran gravatar image

Hello,

I am having some issues with reading a variable from the message PoseStamped. I can call the callback function and when I write something to read out the message I get the following error.

'const_pose_type' has no member named 'pose'
x_current = msg->pose.pose.position.x;

I get the message from another computer which is connected with an UTP cable as a slave to my computer which is the master. In the terminal I can echo the message and see that it is sending coordinates. The code that is running is as following.

#include "ros/ros.h"
#include <sstream>
#include "geometry_msgs/PoseStamped.h"

#include <vector>

std::vector<geometry_msgs::PoseStamped::ConstPtr> pose;

double x_current = 0;

void tf_callback(const geometry_msgs::PoseStamped::ConstPtr& msg) {
    ROS_INFO_STREAM("Received pose: " << msg);
    x_current = msg->pose.pose.position.x;
    ROS_INFO_STREAM(x_current);
    pose.push_back(msg);
}

int main(int argc, char **argv) {
    ros::init(argc, argv, "subscriberTF");
    ros::NodeHandle nh;
    ros::Subscriber subscribetf = nh.subscribe("/visp_auto_tracker1/object_position", 1000, tf_callback);
    ros::spin();
    return(0);
}

Could someone please have a look at my code to see what I do wrong so that I can import the variables from the function the proper way. I want to publish the coordinates to the tf afterwards.

Thank you.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-01-30 03:50:58 -0600

mgruhler gravatar image

updated 2018-01-30 04:03:32 -0600

gvdhoorn gravatar image

This is straightforward: You have one pose too much.

Check the docu of the message: http://docs.ros.org/api/geometry_msgs... So, correct would be: msg->pose.position.x.

edit flag offensive delete link more

Comments

Thank you. I just managed to find that as well :)

Lauran gravatar imageLauran ( 2018-01-30 03:52:03 -0600 )edit

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-01-30 03:38:53 -0600

Seen: 2,711 times

Last updated: Jan 30 '18