Created
December 9, 2018 13:32
-
-
Save TheProjectsGuy/da5ece6a666032c01560accf957d7fb2 to your computer and use it in GitHub Desktop.
Simple Subscriber made using C++ in ROS
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 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