(C++版)ROS2发布者节点终极版--面向过程设计款式

#include 
#include 
#include 
#include 
#include 
#include "sys/time.h"
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
using namespace std;
using namespace rclcpp;

uint32_t count1=0;
stringstream ss;
std_msgs::msg::String MESSAGE1;
rclcpp::TimerBase::SharedPtr timer_;	
rclcpp::Node * pnode;
std::shared_ptr> ppublisher=0;

void timer_callback()
{
    ss.str("");
    ss<<"hello nice to meet you"<create_publisher("topicName",10);
    ppublisher->publish(MESSAGE1);
 
    //destroy the pointer
}
int main(int argc,char ** argv)
{
    rclcpp::init(argc,argv);
    Node node1("nodeName");
    pnode=&node1;
    timer_=pnode->create_wall_timer(500ms,timer_callback);
    shared_ptr p(pnode);
    spin(p);
    rclcpp::shutdown();
    return 0;

}

表现为:在终端内没有内容显示,但是在RQT里面可以看到内容在更新。我看你要怎么感谢我

你可能感兴趣的:(c++,机器人,ros2,ubuntu,嵌入式硬件)