How to properly shutdown a node from command coded in the script of the same node
I have a simple ros application that is used to create a .world file. Everything is working as expected unless the shutdown process. When the script ends the following message is retrieved:
================================================================================REQUIRED process [world_creation-2] has died!
process has finished cleanly
log file: /home/nut/.ros/log/452cd878-dd8f-11e7-9623-e02a82110940/world_creation-2*.log
Initiating shutdown!
================================================================================
[world_creation-2] killing on exit
[rosout-1] killing on exit
[master] killing on exit
shutting down processing monitor...
... shutting down processing monitor complete
I am unsatisfied with the fist part of the message which is appearing in the red color e may pass the felling the some thing is wrong. So, here is my question: How can I finish in a way clean way, from a command codded in the node script, this node. The node script is:
#!/usr/bin/env python
import sys
import rospy
import numpy as np
import road_generation_gazebo.roads as roads
import road_generation_gazebo.worlds as worlds
import road_generation_gazebo.utils as utils
import road_generation_gazebo.generates as generates
def main(road_pts, road_close, offset, offset_npts, offset_var, doplot ,model, file_name):
pass #there is some code here
if __name__ == '__main__':
# Initialize the node and name it.
rospy.init_node('world_creation', anonymous=True, disable_signals=True)
# Getting parameters
metadata = rospy.get_param('~metadata')
road_close=metadata['close']
if metadata['mode'] == 'function':
if metadata['geometry'] == 'ellipse':
road_pts = generates.ellipse(metadata['radius']
,metadata['RADIUS']
)
elif metadata['mode'] == 'waypoints':
road_pts = metadata['points']
else:
raise ValueError('Not expected mode...')
main(road_pts=road_pts
,road_close=road_close
,offset=rospy.get_param('~offset')
,offset_npts=rospy.get_param('~offset_npts')
,offset_var=rospy.get_param('~offset_var')
,doplot=rospy.get_param('~doplot')
,model=rospy.get_param('~model')
,file_name =rospy.get_param('~file_name')
)
and the launch file used is;
<launch>
<node name="world_creation" pkg="road_generation_gazebo" type="road_gazebo.py" required="true" output='screen'>
<!--node name="world_creation" pkg="road_generation_gazebo" type="road_gazebo.py"-->
<rosparam command="load" file="$(find road_generation_gazebo)/yaml/metadata.yaml" />
<param name="doplot" value="true" />
<param name="offset_road_add_noise" value="true" />
<param name="offset" value="5.0" />
<param name="offset_npts" value="100.0" />
<param name="offset_var" value="1.5" />
<param name="model" value="bush" />
<!--param name="model" value="cylinder"/-->
<param name="file_name" value="custom.world" />
</node>
</launch>
I tried the command rospy.signal_shutdown(reason)
, but the red message was not suppressed.
To be honest, this is all normal and doing what it should. There are no errors being reported. Personally I would say there is nothing to fix here.