Skip to content

Instantly share code, notes, and snippets.

@sipah00
Created August 16, 2017 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sipah00/0a0a4742f0cf9959017545304edaa760 to your computer and use it in GitHub Desktop.
Save sipah00/0a0a4742f0cf9959017545304edaa760 to your computer and use it in GitHub Desktop.
#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