#include <ros/ros.h>
#include <std_msgs/String.h>
int main(int argc, char *argv[])
{
ros::init(argc, argv, "hello_node");
printf("hello\n");
ros::NodeHandle nh;
ros::Publisher pub = nh.advertise<std_msgs::String>("test_topic", 10);
ros::Rate loop_rate(1); // 设置发布频率为1Hz
while (ros::ok())
{
printf("hello_node still run\n");
std_msgs::String message;
message.data = "hello_node's message";
pub.publish(message);
ros::spinOnce(); // 处理回调函数
loop_rate.sleep(); // 控制循环频率
}
return 0;
}