Ask Your Question
0

How to properly shutdown a node from command coded in the script of the same node

asked 2017-12-10 04:09:47 -0500

Randerson gravatar image

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.

edit retag flag offensive close merge delete

Comments

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.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2017-12-10 11:59:34 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-12-10 05:19:14 -0500

gvdhoorn gravatar image

Can you try sys.exit(0) at the end of your script? Or make main(..) return an exit code and do something like sys.exit(main(..)).

edit flag offensive delete link more

Comments

The first option did not work, i.e sys.exit(0). About the second one, what could be this exit sign?

Randerson gravatar image Randerson  ( 2017-12-10 06:43:33 -0500 )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

2 followers

Stats

Asked: 2017-12-10 04:09:47 -0500

Seen: 619 times

Last updated: Dec 10 '17