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

Updating Publishers from CTurtle to Diamondback

asked 2011-05-10 01:23:38 -0500

gammell gravatar image

Hi, I'm in the process of migrating some other people's CTurtle code to Diamondback (while learning ROS at the same time), and I'd like to confirm some behaviour that I haven't seen documented.

In the CTurtle code, there are a lot of simple publishers that use std_msgs, such as:

stringPublisher_ = nodeHandle_.advertise<std_msgs::String>("/string", 1);

or

floatPublisher_ = nodeHandle_.advertise<std_msgs::Float32>("/float", 1);

When these are called however, it's not with a std_msgs:: data type, but instead the base data type, e.g.:

 std::string state = "IDLE"
 stringPublisher_.publish(state);

or

 floatPublisher_.publish((float)3.14);

This code worked fine under CTurtle, but now that I'm trying to port it to Diamondback it treats the std::string/float32 as a ROS message and as a result throws an error. Specifically:

 /ros-diamondback/ros_comm/clients/cpp/roscpp_traits/include/ros/message_traits.h:121: error: request for member ‘__getMD5Sum’ in ‘m’, which is of non-class type ‘const float’

This is easily fixed by pushing the data into the message variable, for e.g.:

 std_msgs::String msgStr;
 msgStr.data = state;
 stringPublisher_.publish(msgStr);

But I'm just curious if this is an intended change or if I'm missing something?

Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2011-05-11 10:57:25 -0500

updated 2011-05-11 10:59:17 -0500

Looking at the cturtle code path. I don't see any constructor for std_msgs::String for instance which should have allowed for the conversion. Nor can I see any code path for for publisher::publish that would allow it separately.

I would expect that the code you posted would not work in CTurtle either. I would go back and double check that it worked in the first place.

If it really does work, if you're using eclipse, follow the publish function, back to its declaration, and see which invocation it's calling. Or, follow std_msgs::String's constructor back and see what constructor could possibly create a string message directly from a std::string.

edit flag offensive delete link more

Comments

I believe rospy can handle this situation, so perhaps this is just a case of confusion between features in rospy and roscpp.
Eric Perko gravatar image Eric Perko  ( 2011-05-11 13:09:11 -0500 )edit
Eric, I agree that rospy is probably the reason someone wrote this code in the first place, but I can confirm that it absolutely does work in roscpp in CTurtle. I will see if I can track down the invocation or something similar.
gammell gravatar image gammell  ( 2011-05-12 02:23:39 -0500 )edit
Ok. So I haven't tracked down how it *works* in CTurtle yet, but I know why it doesn't work in Diamondback. It's the ROS_ASSERT_MSG at line 111 of publisher.h that throws the error. Those ROS_ASSERT_MSG were not present in the publisher.h in CTurtle...
gammell gravatar image gammell  ( 2011-05-12 06:27:53 -0500 )edit

Question Tools

Stats

Asked: 2011-05-10 01:23:38 -0500

Seen: 430 times

Last updated: May 11 '11