寫ros節點時,最忌諱寫絕對路徑或相對路徑,有以下幾種方式解決
1、調用系統路徑
std::string home = getenv("HOME")
2、用ros自帶
轉載自創客智造:https://www.ncnynl.com/archives/201702/1300.html
1 ros::this_node::getName(),獲取此節點的完全限定名稱。 2 ros::this_node::getNamespace(),獲取此節點的完全限定命名空間。
3、其他
3.1 代碼里使用ros::package
ros::package::getPath() //需要添加依賴roslib
3.2 roslaunch里使用系統路徑
1 方式一 <rosparam command="load" file="$(env HOME)/....yaml"/> 2 3 方式二 <rosparam file="$(env HOME)/.ame.yaml" command="load" /> 4 5 方式三 <include file="$(find ${package_name}})/launch/main.launch"/>