Skip to content

Instantly share code, notes, and snippets.

@sagunms
Created July 2, 2013 12:21
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 sagunms/5908819 to your computer and use it in GitHub Desktop.
Save sagunms/5908819 to your computer and use it in GitHub Desktop.
Hello World ROS (Robot Operating System) - Talker and Listener
#include "ros/ros.h"
#include "std_msgs/String.h"
void callback(const std_msgs::String &msg) {
ROS_INFO("I heard: [%s]", msg.data.c_str());
}
int main(int argc, char **argv) {
ros::init(argv, argc, "listener");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("chatter", 1, callback);
ros::spin();
return 0;
}
// ROS Hello World (Talker)
#include "ros/ros.h"
#include "std_msgs/String.h"
int main(int argc, char **argv) {
ros::init(argc, argv, "talker");
ros::NodeHandle n;
ros:Publisher pub = n.advertise<std_msgs::String>("chatter", 1);
ros::Rate loop_rate(10);
while(ros::ok()) {
pub.publish("Hello, World");
ros::spinOnce();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment