remove_object.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 #################################################################
00003 ##\file
00004 #
00005 # \note
00006 # Copyright (c) 2010 \n
00007 # Fraunhofer Institute for Manufacturing Engineering
00008 # and Automation (IPA) \n\n
00009 #
00010 #################################################################
00011 #
00012 # \note
00013 # Project name: Care-O-bot Research
00014 # \note
00015 # ROS stack name: cob_environments
00016 # \note
00017 # ROS package name: cob_gazebo_objects
00018 #
00019 # \author
00020 # Author: Florian Weisshardt, email:florian.weisshardt@ipa.fhg.de
00021 # \author
00022 # Supervised by: Florian Weisshardt, email:florian.weisshardt@ipa.fhg.de
00023 #
00024 # \date Date of creation: Feb 2012
00025 #
00026 # \brief
00027 # Implements script server functionalities.
00028 #
00029 #################################################################
00030 #
00031 # Redistribution and use in source and binary forms, with or without
00032 # modification, are permitted provided that the following conditions are met:
00033 #
00034 # - Redistributions of source code must retain the above copyright
00035 # notice, this list of conditions and the following disclaimer. \n
00036 # - Redistributions in binary form must reproduce the above copyright
00037 # notice, this list of conditions and the following disclaimer in the
00038 # documentation and/or other materials provided with the distribution. \n
00039 # - Neither the name of the Fraunhofer Institute for Manufacturing
00040 # Engineering and Automation (IPA) nor the names of its
00041 # contributors may be used to endorse or promote products derived from
00042 # this software without specific prior written permission. \n
00043 #
00044 # This program is free software: you can redistribute it and/or modify
00045 # it under the terms of the GNU Lesser General Public License LGPL as
00046 # published by the Free Software Foundation, either version 3 of the
00047 # License, or (at your option) any later version.
00048 #
00049 # This program is distributed in the hope that it will be useful,
00050 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00051 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00052 # GNU Lesser General Public License LGPL for more details.
00053 #
00054 # You should have received a copy of the GNU Lesser General Public
00055 # License LGPL along with this program.
00056 # If not, see < http://www.gnu.org/licenses/>.
00057 #
00058 #################################################################
00059 import sys
00060 import roslib
00061 roslib.load_manifest('cob_bringup_sim')
00062 
00063 import rospy
00064 import os
00065 
00066 from gazebo.srv import *
00067 from geometry_msgs.msg import *
00068 import tf.transformations as tft
00069 
00070 if __name__ == "__main__":
00071         if len(sys.argv) < 2:
00072                 print '[remove_object.py] Please specify the names of the objects to be removed'
00073                 sys.exit()
00074         
00075         rospy.init_node("object_remover")
00076 
00077         # check for all objects on parameter server
00078         if not rospy.has_param("/objects"):
00079                 rospy.logerr("No objects uploaded to /objects")
00080                 all_object_names = []
00081         else:
00082                 all_object_names = rospy.get_param("/objects").keys()
00083 
00084         # if keyword all is in list of object names we'll load all models uploaded to parameter server
00085         if "all" in sys.argv:
00086                 object_names = all_object_names
00087         else:
00088                 object_names = sys.argv
00089                 object_names.pop(0) # remove first element of sys.argv which is file name
00090 
00091         rospy.loginfo("Trying to remove %s",object_names)
00092         
00093         for name in object_names:
00094                 # check if object is already spawned
00095                 srv_delete_model = rospy.ServiceProxy('gazebo/delete_model', DeleteModel)
00096                 req = DeleteModelRequest()
00097                 req.model_name = name
00098                 exists = True
00099                 try:
00100                         res = srv_delete_model(name)
00101                 except rospy.ServiceException, e:
00102                         exists = False
00103                         rospy.logdebug("Model %s does not exist in gazebo.", name)
00104 
00105                 if exists:
00106                         rospy.loginfo("Model %s removed.", name)
00107                 else:
00108                         rospy.logerr("Model %s not found in gazebo.", name)


cob_bringup_sim
Author(s): Florian Weisshardt
autogenerated on Sun Oct 5 2014 23:13:44