(C++版本)ros2发布者节点publisher示例源代码(改良版)

#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 message;
     rclcpp::TimerBase::SharedPtr timer_;	
    //define a publisher
//define a ros2 timer_process function
class mynode:public Node
{
public:
std::shared_ptr> ppublisher;
mynode(string str ):Node(str)
{
    std::cout<<"enter mynode structure"<create_publisher("topicName",10);
    
    timer_=this->create_wall_timer(100ms, bind(&mynode::timer_callback,this) ); 
    std::cout<<"leave mynode structure"<publish(message);
    std::cout<<"leave timer_callback"<("nodeName"));    //execute the timer_proc//
    std::cout<<"after spin"<

说明:上面这个代码里面有个变量看来是没有用的timer_,但是一旦删除整个代码编译时候虽然不会报错,但是代码无法正常运行。

(C++版本)ros2发布者节点publisher示例源代码(改良版)_第1张图片

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