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

Callback for integer message

asked 2017-02-16 09:25:07 -0600

krl101 gravatar image

updated 2017-02-16 11:30:06 -0600

Thomas D gravatar image

Hello Folks,

i am just leanring roscpp and i want to re-write the Simple Publisher and Subscriber) Tutorial with an integer instead of a string. So how have i to write the callback function?

void chatterCallback(const std_msgs::UInt16 msg)
{
     ROS_INFO("I heard: [%d]", msg->data);}
}

But catkin_make says:

error: ‘UInt16’ was not declared in this scope

Have i missed some additional headers so std_msgs/UInt16 message isn't declared yet?

The same problem also appears also for ros::Publisher chatter_pub = n.advertise<UInt16>("test", 5);.

Someone has a hint for me?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
3

answered 2017-02-16 11:34:04 -0600

Thomas D gravatar image

You are missing a header file.

For the callback, in the tutorial there is a line containing

#include "std_msgs/String.h"

You should replace that with

#include "std_msgs/UInt16.h"

For the publisher you will want to replace the line containing

ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 1000);

with

ros::Publisher chatter_pub = n.advertise<std_msgs::UInt16>("chatter", 1000);
edit flag offensive delete link more

Comments

Oh x.x yes, this is logical. Thank you very much.

krl101 gravatar image krl101  ( 2017-02-21 07:00:26 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-02-16 09:25:07 -0600

Seen: 881 times

Last updated: Feb 16 '17