Skip to content

Instantly share code, notes, and snippets.

@TheProjectsGuy
Created December 9, 2018 13:32
Show Gist options
  • Save TheProjectsGuy/da5ece6a666032c01560accf957d7fb2 to your computer and use it in GitHub Desktop.
Save TheProjectsGuy/da5ece6a666032c01560accf957d7fb2 to your computer and use it in GitHub Desktop.
Simple Subscriber made using C++ in ROS
// Include the ROS header file
#include "ros/ros.h"
// Message data type
#include "std_msgs/Float64.h"
// Caller function
void receivedMessage(const std_msgs::Float64::ConstPtr &msg) {
ROS_INFO("Number received: %f", msg->data);
}
int main(int argc, char **argv) {
// Initialize the ROS node
ros::init(argc, argv, "NumberSubscriber");
// Node Handler
ros::NodeHandle nodeHandler;
// Subscribe to the topic: "floating_numbers"
ros::Subscriber sub = nodeHandler.subscribe<std_msgs::Float64>("floating_numbers", 2, receivedMessage);
// Spin node
ros::spin();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment