rosnode kill in launch file
Hey there,
I would like to kill a specific rosnode by its name through calling a launch file
Anyone knows how this is possible?
Best, Markus
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
Hey there,
I would like to kill a specific rosnode by its name through calling a launch file
Anyone knows how this is possible?
Best, Markus
Edit (after a very long time):
I did not accept my own answer back then (as that's impossible), but somehow this question did get marked as answered. As my previous answer was wrong, here is a correct(ed) version.
this is indeed not working (not even in Noetic), and is caused by rosnode
not installing the rosnode
script in the /opt/ros/$ROS_DISTRO/lib/rosnode
directory, but only relying on its setup.py
to copy scripts/rosnode
to /opt/ros/$ROS_DISTRO/bin
.
Compare the CMakeLists.txt of rosservice with that of rosnode. Notice how the former (ie: rosservice
) has:
catkin_install_python(PROGRAMS scripts/rosservice
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
where the latter (ie: rosnode
) does not.
Manually creating /opt/ros/$ROS_DISTRO/lib/rosnode
and copying /opt/ros/$ROS_DISTRO/bin/rosnode
to it will make rosrun rosnode rosnode ...
work -- and also fixes the case reported by the OP (in 2018 ...).
Note: I really do not recommend manually creating directories and/or copying files around in /opt/ros/$ROS_DISTRO
. It will likely be reverted the next time you update your system anyway. I just wanted to show what the main difference is between ros*
binaries that do work with roslaunch
and those that don't.
Edit 2: I've submitted a PR to fix this: ros/ros_comm#2262. It's in ROS 1 though, so I'm not sure how likely it is to get merged.
Original answer:
Anyone knows how this is possible?
Like so?
<node name="<some_name>" pkg="rosnode" type="rosnode" args="kill /<name_of_your_node>" />
Identical to how you would start any other ROS program in a launch file (such as rosbag
, static_transform_publisher
, etc).
seems like there is no rosnode run file in the rosnode pkg
Do I understand you correctly that you did a rosls rosnode
and didn't see any binaries there? If so, that is normal and expected.
The node
line shown in the answer should work. If it doesn't, just stating "it doesn't work" for you is not enough to try and figure out what is going wrong.
Sorry for not being clear, I got this error:
ERROR: cannot launch node of type [rosnode/rosnode]: can't locate node [rosnode] in package [rosnode]
and the part of my launch file with the node line is:
<?xml version="1.0"?>
<launch>
<!-- kill default pointcloud_to_laserscan node -->
<node name="node_killer" pkg="rosnode" type="rosnode" args="kill /pointcloud_to_laserscan" />
<!-- run pointcloud_to_laserscan node with virtual obs -->
<node pkg="pointcloud_to_laserscan_virtual_obs" type="pointcloud_to_laserscan_virtual_obs_node" name="pointcloud_to_laserscan_virtual_obs">
<remap from="cloud_in" to="/pointcloud_unified"/>
<remap from="scan" to="/scan"/>
<rosparam>
Comment on the last edit: Another walkaround might be cloning ros_comm, or just its ros_node folder into catkin workspace, modifying and building it there. The good side is that you don't copy files in root folders. However, one has to follow the updates to the package manually then.
Asked: 2018-06-01 01:30:15 -0500
Seen: 1,622 times
Last updated: Aug 02 '22