$search
00001 #!/usr/bin/env python 00002 ################################################################# 00003 ##\file 00004 # 00005 # \note 00006 # Copyright (c) 2011-2012 \n 00007 # Fraunhofer Institute for Manufacturing Engineering 00008 # and Automation (IPA) \n\n 00009 # 00010 ################################################################# 00011 # 00012 # \note 00013 # Project name: care-o-bot 00014 # \note 00015 # ROS stack name: cob_calibration 00016 # \note 00017 # ROS package name: cob_calibration_executive 00018 # 00019 # \author 00020 # Author: Sebastian Haug, email:sebhaug@gmail.com 00021 # \author 00022 # Supervised by: Florian Weisshardt, email:florian.weisshardt@ipa.fhg.de 00023 # 00024 # \date Date of creation: January 2012 00025 # 00026 ################################################################# 00027 # 00028 # Redistribution and use in source and binary forms, with or without 00029 # modification, are permitted provided that the following conditions are met: 00030 # 00031 # - Redistributions of source code must retain the above copyright 00032 # notice, this list of conditions and the following disclaimer. \n 00033 # - Redistributions in binary form must reproduce the above copyright 00034 # notice, this list of conditions and the following disclaimer in the 00035 # documentation and/or other materials provided with the distribution. \n 00036 # - Neither the name of the Fraunhofer Institute for Manufacturing 00037 # Engineering and Automation (IPA) nor the names of its 00038 # contributors may be used to endorse or promote products derived from 00039 # this software without specific prior written permission. \n 00040 # 00041 # This program is free software: you can redistribute it and/or modify 00042 # it under the terms of the GNU Lesser General Public License LGPL as 00043 # published by the Free Software Foundation, either version 3 of the 00044 # License, or (at your option) any later version. 00045 # 00046 # This program is distributed in the hope that it will be useful, 00047 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00048 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00049 # GNU Lesser General Public License LGPL for more details. 00050 # 00051 # You should have received a copy of the GNU Lesser General Public 00052 # License LGPL along with this program. 00053 # If not, see <http://www.gnu.org/licenses/>. 00054 # 00055 ################################################################# 00056 PKG = 'cob_calibration_executive' 00057 NODE = 'collect_robot_calibration_data_node' 00058 import roslib; roslib.load_manifest(PKG) 00059 import rospy 00060 00061 from simple_script_server import simple_script_server 00062 from cob_calibration_srvs.srv import Capture 00063 00064 def capture_loop_arm(positions, sss, capture): 00065 ''' 00066 Moves arm to all positions using script server instance sss 00067 and calls capture() to capture samples 00068 ''' 00069 for pos in positions: 00070 print "--> moving arm to pos %s sample" % pos 00071 sss.move("arm", pos) 00072 sss.sleep(1.5) 00073 capture() 00074 00075 def capture_loop_torso(positions, sss, capture): 00076 ''' 00077 Moves torso to all positions using script server instance sss 00078 and calls capture() to capture samples 00079 ''' 00080 for pos in positions: 00081 print "--> moving torso to pos %s sample" % pos 00082 sss.move("torso", pos) 00083 sss.sleep(1.5) 00084 capture() 00085 00086 def main(): 00087 rospy.init_node(NODE) 00088 print "==> %s started " % NODE 00089 00090 # service client 00091 image_capture_service_name = "/collect_data/capture" 00092 capture = rospy.ServiceProxy(image_capture_service_name, Capture) 00093 rospy.wait_for_service(image_capture_service_name, 1) 00094 print "--> service client for capture images initialized" 00095 00096 # init 00097 print "--> initializing sss" 00098 sss = simple_script_server() 00099 sss.init("base") 00100 sss.init("torso") 00101 sss.init("head") 00102 sss.recover("base") 00103 sss.recover("torso") 00104 sss.recover("head") 00105 00106 print "--> setup care-o-bot for capture" 00107 sss.move("head", "back") 00108 00109 # get position from parameter server 00110 positions_back = rospy.get_param("/script_server/arm/all_robot_back") 00111 positions_center = rospy.get_param("/script_server/arm/all_robot_center") 00112 positions_right = rospy.get_param("/script_server/arm/all_robot_right") 00113 positions_left = rospy.get_param("/script_server/arm/all_robot_left") 00114 torso_positions = ["calib_front_left2", "calib_front_right2", "calib_right2", "calib_left2", "calib_back_left2", "calib_back_right2", "home"] 00115 00116 print "==> capturing images BACK" 00117 sss.move("torso", "back") 00118 capture_loop_arm(positions_back, sss, capture) 00119 00120 print "==> capturing images LEFT" 00121 sss.move("torso", "left") 00122 capture_loop_arm(positions_left, sss, capture) 00123 00124 print "==> capturing images RIGHT" 00125 sss.move("torso", "right") 00126 capture_loop_arm(positions_right, sss, capture) 00127 00128 print "==> capturing images CENTER" 00129 sss.move("torso", "home") 00130 capture_loop_arm(positions_center, sss, capture) 00131 00132 print "==> capturing TORSO samples" 00133 sss.move("arm", "calibration") 00134 capture_loop_torso(torso_positions, sss, capture) 00135 00136 if __name__ == '__main__': 00137 main() 00138 print "==> done exiting"