- #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"<
- MESSAGE1.data=ss.str();
- ppublisher=pnode->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里面可以看到内容在更新。我看你要怎么感谢我