Rosanswers logo

hello everyone I'm just trying to write a simple C++ client of Stage package. Just to make a test, i want to write a short code to receive some odometry data from /odom topic and print it onto screen:

#include "ros/ros.h"
#include "nav_msgs/Odometry.h"
#include "geometry_msgs/Pose.h"
#include "geometry_msgs/Point.h"
/* #include "geometry_msgs/Point" */
void chatter (const nav_msgs::Odometry mes){
    geometry_msgs::Pose robot_pose = mes.pose;
    geometry_msgs::Point robot_point = robot_pose.position; 
    float xCoord = robot_point.x;
    float yCoord = robot_point.y;
    float zCoord = robot_point.z;
    ROS_INFO("I received %f %f %f/n", xCoord, yCoord, zCoord);  
int main(int argc, char **argv){
    ros::init(argc,argv, "listener");
    ros::NodeHandle n;
    ros::Subscriber sub = n.subscribe("/odom", 1000, chatter);
    return 0;

Sadly ROS compiler gives me an error:

/home/ubisum/fuerte_workspace/beginner/src/listener.cpp: In function ‘void chatter(nav_msgs::Odometry)’:
/home/ubisum/fuerte_workspace/beginner/src/listener.cpp:8:39: error: conversion from ‘const _pose_type {aka const geometry_msgs::PoseWithCovariance_ >}’ to non-scalar type ‘geometry_msgs::Pose’ requested
make[3]: *** [CMakeFiles/listener.dir/src/listener.o] Errore 1
make[3]: uscita dalla directory "/home/ubisum/fuerte_workspace/beginner/build"
make[2]: *** [CMakeFiles/listener.dir/all] Errore 2
make[2]: uscita dalla directory "/home/ubisum/fuerte_workspace/beginner/build"
make[1]: *** [all] Errore 2
make[1]: uscita dalla directory "/home/ubisum/fuerte_workspace/beginner/build"
make: *** [all] Errore 2

Could you help me? I'm both a ROS and C++ newbie. Thanks

Originally posted by ubisum on ROS Answers with karma: 23 on 2012-11-08

Post score: 0

Original comments

Comment by jbohren on 2012-11-08:
Can you edit your question and add the exact error that you're getting?

Comment by ubisum on 2012-11-08:
Done. And I corrected which is the error I got

Comment by ubisum on 2012-11-08:
Sorry for disorder


1 Answer 1


Rosanswers logo


geometry_msgs::Pose robot_pose = mes.pose;


geometry_msgs::Pose robot_pose = mes.pose.pose;

Check the definition of nav_msg/Odometry carefully - mes.pose is PoseWithCovariance.

Originally posted by mmedvede with karma: 221 on 2012-11-08

This answer was ACCEPTED on the original site

Post score: 3


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.