0
$\begingroup$

Rosanswers logo

Please modify or guide me to where I can learn to modify the talker.cpp and listener.cpp given in the beginner_tutorials to send the message Num.msg defined in the same series of tutorials. This is to help understand how to use complex msgs later on.

I replaced the example code by the following lines wherever I felt was necessary but this is not getting compiled.

talker.cpp

#include "beginner_tutorials/Num.h"
ros::Publisher chatter_pub = n.advertise<beginner_tutorials::Num>("chatter", 1000);
beginner_tutorials::Num num;
// std::stringstream ss;
// ss <<"hello world" << count;
num = 123456789;
ROS_INFO("%d",num);
chatter_pub.publish(num);

listener.cpp

#include "beginner_tutorials/Num.h"
void chatterCallback(const beginner_tutorials::ConstPtr &num)
{
    ROS_INFO("I heard: [%d]",  num->data);
}

Also please suggest a way to understand the Num.h, std_msgs/String.h file generated by ROS, if it is to be understood at the first place to use ROS.


Originally posted by arttp2 on ROS Answers with karma: 123 on 2015-11-19

Post score: 0


Original comments

Comment by dornhege on 2015-11-19:
What is the error message?

Comment by arttp2 on 2015-11-19:
In function ‘int main(int, char**)’: /home/catkin_ws/src/beginner_tutorials/src/talker.cpp:25:7: error: no match for ‘operator=’ (operand types are ‘beginner_tutorials::Num’ and ‘int’) num = 123456789;

one of the error messages, the first one.

Comment by arttp2 on 2015-11-19:
Thanks for editing my question.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

The type of the message is beginner_tutorials::Num, not int. However, it probably has a member of type in, usually named data or something. You need to set that instead of the message directly.

Usually you refer to the message definition file for that and not the ROS message headers. These can be read and understood, but are not meant to be.


Originally posted by dornhege with karma: 31395 on 2015-11-19

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by jarvisschultz on 2015-11-19:
In other words, the line num = 123456789; should probably be changed to something like num.data = 123456789;

Comment by arttp2 on 2015-11-19:
after adding num.data, it again says no member such as data (because .data may be defined for the String message) , so where can I find the members for the message, and a comprehensive usage details for the custom msg.

Comment by jarvisschultz on 2015-11-19:
As @dornhege said, you need to be looking at the "Num.msg" file to see the message definition. E.g. see how the std_msgs/String has a single field of type "string" named "data". You need to find the equivalent file for your message.

Comment by jarvisschultz on 2015-11-19:
If your workspace is setup correctly, you should be able to see the message definition at the command line using rosmsg show. E.g. rosmsg show std_msgs/String

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.