ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
If you created a custom message then you need to create a Publisher that uses that custom message type. Right now your publisher is using a std_msgs/Int64
type which only has a single field named data
.
Let's say your custom message is in a package called my_custom_msgs
and that the file is named Custom.msg
. Then you would need to declare your publisher like
ros::NodeHandle n;
ros:Publisher pub = n.advertise<my_custom_msgs::Custom>("chatter", 1000);
Now you can declare a message using the custom data type, populate each of the fields in your message, and publish.
my_custom_msgs::Custom msg;
msg.intensity = 15;
msg.location = 100;
msg.duration = 37;
pub.publish(msg);
2 | No.2 Revision |
If you created a custom message then you need to create a Publisher that uses that custom message type. Right now your publisher is using a std_msgs/Int64
type which only has a single field named data
.
Let's say your custom message is in a package called my_custom_msgs
and that the file is named Custom.msg
. Then you would need to declare your publisher like
ros::NodeHandle n;
ros:Publisher pub = n.advertise<my_custom_msgs::Custom>("chatter", 1000);
Now you can declare a message using the custom data type, populate each of the fields in your message, and publish.
my_custom_msgs::Custom msg;
msg.intensity = 15;
msg.location = 100;
msg.duration = 37;
pub.publish(msg);
Later, if you change your message to include a string so that it becomes
int64 intensity
int64 location
int64 duration
string note
Then you will create the publisher the same way, but populating the fields and publishing will be
my_custom_msgs::Custom msg;
msg.intensity = 15;
msg.location = 100;
msg.duration = 37;
msg.note = "Hello";
pub.publish(msg);