- #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_,但是一旦删除整个代码编译时候虽然不会报错,但是代码无法正常运行。

-
相关阅读:
【Linux】apt-get 命令
开始使用AspectJ-实现步骤@Aspect,@Before,还有其中的JoinPoint参数
Find My雨伞|苹果Find My技术与雨伞结合,智能防丢,全球定位
剑指offer(C++)-JZ59:滑动窗口的最大值(数据结构-队列 & 栈)
焊接--PCBA
MySQL-索引优化和查询优化
荐书丨《不可打扰》:我们如何保存专注
Pycharm远程debug代码,一直进入remote_sources
Codeforces Round 515
YOLOv7-Openvino和ONNXRuntime推理【CPU】
-
原文地址: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