Why can't I send a string message through my program?
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.