- #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_,但是一旦删除整个代码编译时候虽然不会报错,但是代码无法正常运行。
-
相关阅读:
ch03:算数运算(长沙师范学院)
【Rust 日报】2022-08-21 surrealdb端到端云原生数据库
Python可视化数据分析10、Matplotlib库
Vue.js入门教程(七)
多图详解:不停机分库分表五个步骤
IOC操作bean管理XML方式(注入空值和特殊符号)
扫描全能王文档矫正逆向记录
按字典序排序还是按长度排序
文件重命名自动化:批量处理让生活更简单
LeetCode解法汇总2560. 打家劫舍 IV
-
原文地址:https://blog.csdn.net/geniusChinaHN/article/details/133464176