ROS 发布、订阅话题自带node名前缀
ROS node主程序
ros::init(argc, argv, "laserMapping");
ros::NodeHandle nh("~"); //加上这个~
//注意topic名前没有/
ros::Subscriber sub_imu = nh.subscribe<sensor_msgs::Imu>("imu", 200000, imu_cbk);
ros::Publisher pubPath = nh.advertise<nav_msgs::Path> ("path", 100000);
对应的launch中,可以修改node名字
pkg为node所在的package;type是可执行文件的本名,不可修改;name可以修改
<node pkg="multi_uav_lio" type="fastlio_mapping" name="laserMapping_quad1" output="screen" >
<rosparam command="load" file="$(find multi_uav_lio)/config/simulation.yaml" />
<param name="point_filter_num" type="int" value="5"/>
......
</node>
这样订阅和接受的话题名称就会变成
/laserMapping_quad1/imu
/laserMapping_quad1/path
运行两个相同节点
只需修改launch文件,设置不同的name即可
需要将ros参数写在node内部,才会传递给对应的node,不会互相影响
<node pkg="multi_uav_lio" type="fastlio_mapping" name="laserMapping_quad1" output="screen" >
<rosparam command="load" file="$(find multi_uav_lio)/config/simulation.yaml" />
<param name="point_filter_num" type="int" value="5"/>
......
</node>
<node pkg="multi_uav_lio" type="fastlio_mapping" name="laserMapping_quad2" output="screen" >
<rosparam command="load" file="$(find multi_uav_lio)/config/simulation.yaml" />
<param name="point_filter_num" type="int" value="5"/>
......
</node>