ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
1

rosnode kill in launch file

asked 2018-06-01 01:30:15 -0600

Markus gravatar image

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 retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2018-06-01 01:38:34 -0600

gvdhoorn gravatar image

updated 2022-08-02 03:40:44 -0600

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).

edit flag offensive delete link more

Comments

this doesn't work for me. seems like there is no rosnode run file in the rosnode pkg. I have to resort to using a bash script to do the killing

haito gravatar image haito  ( 2019-09-24 08:27:43 -0600 )edit

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.

gvdhoorn gravatar image gvdhoorn  ( 2019-09-24 09:11:50 -0600 )edit
1

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>
haito gravatar image haito  ( 2019-09-24 10:38:36 -0600 )edit

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.

hansolo gravatar image hansolo  ( 2022-08-02 03:23:27 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-06-01 01:30:15 -0600

Seen: 1,193 times

Last updated: Aug 02