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

Cannot ouput string service via ROS_INFO

asked 2012-11-24 16:45:01 -0500

kbedolla gravatar image

I have a service of type string, my server simply responds with a string. I am trying to implement my client to simply call the service and ROS_INFO out the response. However, when I try to compile I get an error on the line where I am doing the ROS_INFO output. The error is:

error: cannot pass objects of non-trivially-copyable type ‘struct std::basic_string<char>’ through ‘...’

Here is my code:

parallax_eddie_robot::get_version srv;

if(get_version_client_.call(srv))

{

ROS_INFO("%s",srv.response.version);

}

I don't know why it thinks my service is returning a struct because my service file (myservice.srv) is only for a string. It looks like this:


string version

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
15

answered 2012-11-24 17:40:32 -0500

Eric Perko gravatar image

In a nutshell, changing your print to ROS_INFO("%s", srv.response.version.c_str()) should fix your compile error.

A string type in a ROS message/service maps to a std::string in C++ (see the msg package for more details). std::string's are not printable with something like printf, unless you get access to the underlying const char* data which is what printf's "%s" format string is expecting. You can get access to the C-string via the c_str() member on std::string.

edit flag offensive delete link more

Comments

Thank you!

kbedolla gravatar image kbedolla  ( 2012-11-24 17:53:06 -0500 )edit
2

You can also use the C++ stream interface if you like: ROS_INFO_STREAM(srv.response.version)

joq gravatar image joq  ( 2012-11-26 04:58:35 -0500 )edit

Question Tools

Stats

Asked: 2012-11-24 16:45:01 -0500

Seen: 11,956 times

Last updated: Nov 24 '12