ROS学习——通信机制(话题通信③—注意事项)

2.1.2 话题通信基本操作A(C++) · Autolabor-ROS机器人入门课程《ROS理论与实践》零基础教程 

 043话题通信(C++)4_注意事项_Chapter2-ROS通信机制_哔哩哔哩_bilibili

1. int main(int argc, char const *argv[]){}

vscode 中的 main 函数 声明 int main(int argc, char const *argv[]){},默认生成 argv 被 const 修饰,需要去除该修饰符

2.头文件ros.h不存在

ros/ros.h No such file or directory .....

检查 CMakeList.txt find_package 出现重复,删除内容少的即可

参考资料:fatal error: ros/ros.h: No such file or directory - ROS Answers: Open Source Q&A Forum

3.未添加roscpp rospy std_msgs相关的依赖包

find_package 不添加一些包,也可以运行啊, ros.wiki 答案如下

You may notice that sometimes your project builds fine even if you did not call find_package with all dependencies. This is because catkin combines all your projects into one, so if an earlier project calls find_package, yours is configured with the same values. But forgetting the call means your project can easily break when built in isolation.
Copy

4.数据丢失

订阅时,第一条数据丢失

原因: 发送第一条数据时, publisher 还未在 roscore 注册完毕(先订阅,后发布的问题)

解决: 注册后,加入休眠 ros::Duration(3.0).sleep(); 延迟第一条数据的发送

 

 5.回调函数

相当于单片机的中断,满足了触发条件就执行这个函数

普通函数在语句中出现就执行,时机可控;

回调函数在语句中出现了不马上执行,而是等到外部消息过来了再执行,需要外部触发,时机不可控;

PS:可以使用 rqt_graph 查看节点关系。

猜你喜欢

转载自blog.csdn.net/qq_50645064/article/details/131135079