3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ROS2 ノードをkill する方法

Last updated at Posted at 2023-01-17

概要

ROS2 ノードをコマンドからkill したい場合があるが、ROS2にはROS のrosnode kill
にあたるコマンドは存在しないらしい
ROS2ノードのプロセスを終了させる方法のメモ

Lifecycleの機能を使う

代わりにros2 lifecycle コマンドを使用してノードを終了させる

ros2 lifecycle set <node name> shutdown

これではLifecycleで実装されているノードしか終了できず、lifecycleに対応してないノードだとエラーがでる

ros2 lifecycle set /gazebo shuttdown
Node not found

すべてのROS2 プロセスを終了させる

以下のようなスクリプトを作って実行する

#!/bin/bash
echo "Kill all ros nodes!"
ps aux | grep ros | grep -v grep | awk '{ print "kill -9", $2 }' | sh
exit 0
./kill_ros_nodes.sh

ノードが終了しているかの確認 実行して何もでなければOK

ros2 node list

おわりに

ROS2のノードを個別に終了するようなROS2の機能は見つからなかった。
ROS2ではLifecycleを用いてノードを実装することを推奨しているようだ。
launchから実行したノードの中から1つのノードだけ終了したいときがあるので、rosnode killにあたるコマンドは実装してほしいところである。

参考

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?