How to start and kill a node on parameter value change?
I want to write a script that runs a node when a particular parameter is set to true
and kills it (if it is running) when the parameter is set to false
. I'm not sure how best to implement this and I'm wondering if some kind of param listener
command line functionality exists? I've been playing around with while
loops but I'm unsure how best to implement the logic to constantly react to changes in my_param
value. Here's what I have so far:
#!/bin/bash
rosparam set my_param false # Initialise my_param (this is changed as the rest of my ROS system runs)
while [ ROS_IS_RUNNING == true ]; do
if [ $(rosparam get my_param) == false ]
then
echo "kill my_node if running"
else
echo "start my_node if not running and keep listening for changes in my_param value"
fi
done
How does this look and how might I build on this? All ideas welcome!