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

Cannot insert values in custom message

asked 2022-03-31 08:31:18 -0500

AibohphobiA gravatar image

Hi and thanks for reading. I am trying to add a custom message to my project, but for some reason I cannot update the values. I simplified the message package to hold a simple String type which still doesn't work. the message catkin_pkg builds without any errors. features_msg.msg:

std_msgs/String tmp

in the .cpp file, I am calling:

    features_tracking_msg::features_msg features;
    features.tmp = "testing";

and getting: No viable overloaded '='

Any help would be appreciated!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-04-01 01:19:32 -0500

gvdhoorn gravatar image

updated 2022-04-01 01:20:01 -0500

std_msgs/String is not a std::string.

It's a class which has a std::string as one of its members. That member is called data.

So you'd need to assign "testing" to features.tmp.data, not to features.tmp directly (as that would require a suitable overload of = / conversion operator to be available, which would convert std::string to std_msgs::String).

However, having written that: if you're already creating a custom message, I would recommend to directly use the string primitive type for tmp, instead of std_msgs/String.

The former is the type to use for message fields. The latter is a type to use when directly publishing a string to a topic.

edit flag offensive delete link more

Comments

Thanks! I don't know how, but in the following tutorial(which I used) he uses std_msgs::String and then assigns an std::string to it (which works somehow): link text

Thanks for your help!

AibohphobiA gravatar image AibohphobiA  ( 2022-04-05 09:45:34 -0500 )edit

Question Tools

Stats

Asked: 2022-03-31 08:31:18 -0500

Seen: 121 times

Last updated: Apr 01 '22