Ask Your Question
0

Why can't I send a string message through my program?

asked 2017-03-08 01:04:33 -0500

sharan100 gravatar image

Currently I am trying to build a simple node where I send a string using the std_msgs::String.h message class. What I do understand is, why I get these particular errors.

##Code ##

Includes:

// NORMAL INCLUDES 
#include <stdio.h>
#include <iostream>
#include <string>

// ROS INCLUDES 
#include <ros/ros.h>
#include <std_msgs/String.h>

Declaration:

ros::Publisher command;
command = node.advertise<std_msgs::String>("/command", 1);

While loop:

while (ros::ok()) { 

    std::cout << std::endl << std::endl;
    std::cout << "Type your Command Below:" << std::endl << std::endl; 
    getline(std::cin, input);

    command.publish(input); 

}

##Errors ##

In file included from /opt/ros/kinetic/include/ros/serialization.h:37:0,
                 from /opt/ros/kinetic/include/ros/publisher.h:34,
                 from /opt/ros/kinetic/include/ros/node_handle.h:32,
                 from /opt/ros/kinetic/include/ros/ros.h:45,
                 from /home/sharan/catkin_ws/src/zlab_drone/src/demo_usr_input.cpp:9:
/opt/ros/kinetic/include/ros/message_traits.h: In instantiation of ‘static const char* ros::message_traits::MD5Sum<M>::value(const M&) [with M = std::__cxx11::basic_string<char>]’:
/opt/ros/kinetic/include/ros/message_traits.h:255:102:   required from ‘const char* ros::message_traits::md5sum(const M&) [with M = std::__cxx11::basic_string<char>]’
/opt/ros/kinetic/include/ros/publisher.h:112:7:   required from ‘void ros::Publisher::publish(const M&) const [with M = std::__cxx11::basic_string<char>]’
/home/sharan/catkin_ws/src/zlab_drone/src/demo_usr_input.cpp:45:30:   required from here
/opt/ros/kinetic/include/ros/message_traits.h:126:34: error: ‘const class std::__cxx11::basic_string<char>’ has no member named ‘__getMD5Sum’
     return m.__getMD5Sum().c_str();
                                  ^
/opt/ros/kinetic/include/ros/message_traits.h: In instantiation of ‘static const char* ros::message_traits::DataType<M>::value(const M&) [with M = std::__cxx11::basic_string<char>]’:
/opt/ros/kinetic/include/ros/message_traits.h:264:104:   required from ‘const char* ros::message_traits::datatype(const M&) [with M = std::__cxx11::basic_string<char>]’
/opt/ros/kinetic/include/ros/publisher.h:112:7:   required from ‘void ros::Publisher::publish(const M&) const [with M = std::__cxx11::basic_string<char>]’
/home/sharan/catkin_ws/src/zlab_drone/src/demo_usr_input.cpp:45:30:   required from here
/opt/ros/kinetic/include/ros/message_traits.h:143:36: error: ‘const class std::__cxx11::basic_string<char>’ has no member named ‘__getDataType’
     return m.__getDataType().c_str();
                                    ^

String,msg ## Link is here

string data

Since they are the same type looking at String.h, I do not understand why I am getting this error.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2017-03-08 01:29:08 -0500

NEngelhard gravatar image

You should send an std_msgs/String not an std::string.

std_msgs::String msg;
msg.data = input;
command.publish(msg);
edit flag offensive delete link more

Comments

That's it! Thanks!

sharan100 gravatar image sharan100  ( 2017-03-08 01:34:21 -0500 )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: 2017-03-08 01:04:33 -0500

Seen: 4,245 times

Last updated: Mar 08 '17