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

Revision history [back]

click to hide/show revision 1
initial version

First, I define my message type.

# MyCustomMsg.msg

Header header
float64 data

I then add my message's package to the manifest of my C++ node.

<depend package="my_custom_msg_package" />

Then, I import it into my C++ code.

#include <my_custom_msg_package/MyCustomMsg.h>

Set up a publisher:

my_msg_pub_ = n.advertise<my_custom_msg_package::MyCustomMsg>("topic", 1);

I then instantiate an instance of that message:

my_custom_msg_package::MyCustomMsg msg;

Finally, I fill it with data and publish it.

msg.header.stamp = ros::Time::now();
msg.header.frame_id = "/world";
msg.data = 0.0;

my_msg_pub_.publish(msg);