Skip to content

Instantly share code, notes, and snippets.

@lucasw
Last active May 13, 2023 13:55
Show Gist options
  • Save lucasw/292dc8d7dc82d6c4e99350498e173181 to your computer and use it in GitHub Desktop.
Save lucasw/292dc8d7dc82d6c4e99350498e173181 to your computer and use it in GitHub Desktop.
Restart an already running ros node with same remappings
#!/usr/bin/env bash
# Lucas Walter
# source rosrerun.sh my_node_name
# https://answers.ros.org/question/378981/is-it-possible-to-stop-or-restart-a-node-at-run-time/
node_name=$1
echo $node_name
# only take first match
orig_cmd=`ps -eo args | grep "__name:=$node_name" | grep __name | head -n 1`
# get the namespace
# (why don't roslaunched nodes have namespaces in the ps output?)
node_path=`rosnode list | grep $node_name$ | sed 's:/[^/]*$::'`
echo $node_path
echo "press ctrl-c then up arrow to run this again (only works if running this with source)"
cmd="$orig_cmd __ns:=$node_path"
history -s $cmd
# echo "running node first attempt, it may fail with 'shutdown request: [...$node_name...] Reason: new node registered with same name'"
# $cmd
# set -x
$cmd
@lucasw
Copy link
Author

lucasw commented Jul 10, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment