ros2的subscriber源代码我的

#include 
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
#include "string.h"
using std::placeholders::_1;
//we define a class to describe the specific node ,but if the node is simple ,we can use the node class directely
//timer callback function

using namespace rclcpp;//std::sharedPtr
std::shared_ptr  sp;  difference//
void fun2(const std_msgs::msg::String &msg)
{
  RCLCPP_INFO((*sp).get_logger(),"nice to meet you the msg i received is: '%s'",msg.data.c_str());
};
int main(int argc, char * argv[])
{
  rclcpp::init(argc, argv);
  sp=std::make_shared("subscriber"); //the 
  Subscription::SharedPtr subscription1=
      sp->create_subscription( "topic_x",10,fun2);  
  spin(sp);
  rclcpp::shutdown();
  return 0;
}

你可能感兴趣的:(c++,算法,开发语言)