- #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"<
- ppublisher=this->create_publisher
("topicName",10); -
- timer_=this->create_wall_timer(100ms, bind(&mynode::timer_callback,this) );
- std::cout<<"leave mynode structure"<
-
- }
- void timer_callback()
- {
- std::cout<<"enter timer_callback"<
- ss.str()="";
- ss<<"hi im glad to see you"<
- message.data=ss.str();
- cout<
- //publish a topic
- // Publisher2.publish(message);
- ppublisher->publish(message);
- std::cout<<"leave timer_callback"<
- }
- };
-
- //define a node
- //define a publisher
- //utility publiser to publish a topic
- int main(int argc,char ** argv)
- {
- rclcpp::init(argc,argv);
- // Rate rate(1);
- std::cout<<"before spin"<
- spin(std::make_shared
("nodeName")); //execute the timer_proc// - std::cout<<"after spin"<
- rclcpp::shutdown();
- return 0;
-
- }
说明:上面这个代码里面有个变量看来是没有用的timer_,但是一旦删除整个代码编译时候虽然不会报错,但是代码无法正常运行。

-
相关阅读:
14:00面试,14:06就出来了,问的问题有点变态。。。
JUC学习笔记——进程与线程
RabbitMQ(六)仲裁队列、流式队列、异地容灾(联邦队列Federation Queue)
征文:中秋,你愿意和她一起打地(月)鼠(饼)吗?
《痞子衡嵌入式半月刊》 第 49 期
java计算机毕业设计水质监测数据采集系统源码+系统+数据库+lw文档+mybatis+运行部署
求臻人故事 | 在求臻医学的沃土中,我像竹子般茁壮成长
DETR精读笔记
如何在 Nginx Proxy Manager(NPM)上部署静态网站
IDEA设置方法分割线
-
原文地址:https://blog.csdn.net/geniusChinaHN/article/details/133464176
-
最新文章
-
沪漂五周年了:我越来越迷茫了
Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
MySQL-Seconds_behind_master的精度误差
[MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
Agent OS :五种驯服不确定性的范式
PortSwigger SQL注入LAB11
数据库即时编译JIT
[Begin]AI Learn Data Day 0
深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU