Skip to content

Instantly share code, notes, and snippets.

@Tutorgaming
Created July 17, 2018 18:01
Show Gist options
  • Save Tutorgaming/97763617e66247b32b608b93591a2aa6 to your computer and use it in GitHub Desktop.
Save Tutorgaming/97763617e66247b32b608b93591a2aa6 to your computer and use it in GitHub Desktop.
chatter_subscriber_tutorial - Publisher
#include "ros/ros.h"
#include "std_msgs/String.h"
#include <sstream>
int main(int argc, char **argv)
{
ros::init(argc, argv, "talker");
ros::NodeHandle n;
ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 1000);
ros::Rate loop_rate(10);
int count = 0;
while (ros::ok())
{
std_msgs::String msg;
std::stringstream ss;
ss << "hello world " << count;
msg.data = ss.str();
ROS_INFO("%s", msg.data.c_str());
chatter_pub.publish(msg);
ros::spinOnce();
loop_rate.sleep();
++count;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment