Created
July 2, 2013 12:21
-
-
Save sagunms/5908819 to your computer and use it in GitHub Desktop.
Hello World ROS (Robot Operating System) - Talker and Listener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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