generic_mapping_states.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
00014 # \note
00015 #   ROS stack name: cob_scenarios
00016 # \note
00017 #   ROS package name: cob_generic_states
00018 #
00019 # \author
00020 #   Georg Arbeiter, email:georg.arbeiter@ipa.fhg.de
00021 #
00022 # \date Date of creation: Aug 2011
00023 #
00024 # \brief
00025 #   Implements generic states which can be used in multiple scenarios.
00026 #
00027 #################################################################
00028 #
00029 # Redistribution and use in source and binary forms, with or without
00030 # modification, are permitted provided that the following conditions are met:
00031 #
00032 #     - Redistributions of source code must retain the above copyright
00033 #       notice, this list of conditions and the following disclaimer. \n
00034 #     - Redistributions in binary form must reproduce the above copyright
00035 #       notice, this list of conditions and the following disclaimer in the
00036 #       documentation and/or other materials provided with the distribution. \n
00037 #     - Neither the name of the Fraunhofer Institute for Manufacturing
00038 #       Engineering and Automation (IPA) nor the names of its
00039 #       contributors may be used to endorse or promote products derived from
00040 #       this software without specific prior written permission. \n
00041 #
00042 # This program is free software: you can redistribute it and/or modify
00043 # it under the terms of the GNU Lesser General Public License LGPL as
00044 # published by the Free Software Foundation, either version 3 of the
00045 # License, or (at your option) any later version.
00046 #
00047 # This program is distributed in the hope that it will be useful,
00048 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00049 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00050 # GNU Lesser General Public License LGPL for more details.
00051 #
00052 # You should have received a copy of the GNU Lesser General Public
00053 # License LGPL along with this program.
00054 # If not, see <http://www.gnu.org/licenses/>.
00055 #
00056 #################################################################
00057 
00058 import roslib
00059 roslib.load_manifest('cob_3d_mapping_pipeline')
00060 import rospy
00061 import smach
00062 import smach_ros
00063 import actionlib
00064 import operator
00065 
00066 from cob_3d_mapping_msgs.msg import *
00067 from cob_srvs.srv import Trigger
00068 
00069 from simple_script_server import *
00070 sss = simple_script_server()
00071 
00072 ## Initialize state
00073 #
00074 # This state will initialize all hardware drivers.
00075 class UpdateEnvMap(smach.State):
00076 
00077 
00078   def __init__(self):
00079 
00080     smach.State.__init__(
00081       self,
00082       outcomes=['succeeded', 'failed'],
00083       input_keys=['angle_range']) #good angle value: 0.4
00084     self.client = actionlib.SimpleActionClient('trigger_mapping', TriggerAction)
00085 
00086   def execute(self, userdata):
00087     #scan_position = [-1.3, -1.0, 3.14]
00088     #sss.move("torso","home")
00089     #sss.move("head","front")
00090     #sss.move("tray","down")
00091     #sss.move("base",scan_position)
00092     rospy.wait_for_service('point_map/clear_map',10)
00093     try:
00094       clear_point_map = rospy.ServiceProxy('point_map/clear_map', Trigger)
00095       resp1 = clear_point_map()
00096     except rospy.ServiceException, e:
00097       print "Service call failed: %s"%e
00098     rospy.wait_for_service('geometry_map/clear_map',10)
00099     try:
00100       clear_geom_map = rospy.ServiceProxy('geometry_map/clear_map', Trigger)
00101       resp1 = clear_geom_map()
00102     except rospy.ServiceException, e:
00103       print "Service call failed: %s"%e
00104     goal = TriggerGoal()
00105     goal.start = True
00106     if not self.client.wait_for_server():#rospy.Duration.from_sec(5.0)):
00107       rospy.logerr('server not available')
00108       return 'failed'
00109     self.client.send_goal(goal)
00110     if not self.client.wait_for_result():#rospy.Duration.from_sec(5.0)):
00111       return 'failed'
00112     angle_start = -userdata.angle_range/2
00113     angle_stop = userdata.angle_range/2
00114     sss.move("torso",[[-0.2,angle_start,-0.1]])
00115     sss.move("torso",[[-0.2,angle_stop,-0.1]])
00116     sss.move("torso",[[0,angle_stop,0]])
00117     sss.move("torso",[[0,angle_start,0]])
00118     goal.start = False
00119     self.client.send_goal(goal)
00120     self.client.wait_for_result(rospy.Duration.from_sec(5.0))
00121     sss.move("torso","home")
00122     #move neck/base
00123     #get map
00124 
00125     return 'succeeded'
00126 
00127 """experimental state, should be replaces by generic state for approach pose"""
00128 class ApproachScanPose(smach.State):
00129 
00130     def __init__(self):
00131 
00132         smach.State.__init__(
00133             self,
00134             outcomes=['succeeded', 'failed'],
00135             input_keys=['scan_pose']) #good angle value: 0.4
00136 
00137     def execute(self, userdata):
00138         scan_pose = userdata.scan_pose #[-1.3, -1.0, 3.14]
00139         sss.move("torso","home")
00140         sss.move("head","front")
00141         #sss.move("tray","down")
00142         sss.move("base",scan_pose)
00143 
00144         return 'succeeded'
00145 
00146 class Map360(smach.State):
00147 
00148   def __init__(self):
00149 
00150     smach.State.__init__(
00151       self,
00152       outcomes=['succeeded', 'failed'],
00153       input_keys=['angle_range']) #good angle value: 0.4
00154     self.client = actionlib.SimpleActionClient('trigger_mapping', TriggerAction)
00155 
00156   def execute(self, userdata):
00157     scan_pose = [0, -0.5, 0]
00158     sss.move("base",scan_pose)
00159     sss.move("torso","home")
00160     sss.move("head","front")
00161     sss.move("tray","down")
00162     #sss.move("base",scan_position)
00163     goal = TriggerGoal()
00164     goal.start = True
00165     if not self.client.wait_for_server():#rospy.Duration.from_sec(5.0)):
00166       rospy.logerr('server not available')
00167       return 'failed'
00168     self.client.send_goal(goal)
00169     if not self.client.wait_for_result():#rospy.Duration.from_sec(5.0)):
00170       return 'failed'
00171     i = 0.8
00172     ctr = 0
00173     while i <= 8:#6.2:
00174       scan_pose[2]=i
00175       sss.move("base",scan_pose)
00176       #sss.sleep(0.5)
00177       i = i+0.8
00178       ctr = ctr+1
00179     sss.move("torso",[[-0.2,0.0,-0.2]])
00180     while i > 0:#6.2:
00181       i = i-0.8
00182       scan_pose[2]=i
00183       sss.move("base",scan_pose)
00184     goal.start = False
00185     self.client.send_goal(goal)
00186     self.client.wait_for_result(rospy.Duration.from_sec(5.0))
00187     #sss.move("torso","home")
00188     #move neck/base
00189     #get map
00190 
00191     return 'succeeded'
00192 
00193 
00194 class Map180(smach.State):
00195 
00196   def __init__(self):
00197 
00198     smach.State.__init__(
00199       self,
00200       outcomes=['succeeded', 'failed'],
00201       input_keys=['angle_range']) #good angle value: 0.4
00202     self.client = actionlib.SimpleActionClient('trigger_mapping', TriggerAction)
00203 
00204   def execute(self, userdata):
00205     scan_pose = [0, -1, 0]
00206     sss.move("tray","down")
00207     sss.move("torso","home")
00208     sss.move("head","front")
00209     sss.move("base",scan_pose)
00210     #sss.move("base",scan_position)
00211     raw_input("Press any key")
00212     goal = TriggerGoal()
00213     goal.start = True
00214     if not self.client.wait_for_server():#rospy.Duration.from_sec(5.0)):
00215       rospy.logerr('server not available')
00216       return 'failed'
00217     self.client.send_goal(goal)
00218     if not self.client.wait_for_result():#rospy.Duration.from_sec(5.0)):
00219       return 'failed'
00220     i = 0.2
00221     ctr = 0
00222     while i <= 4:#6.2:
00223       scan_pose[2]=i
00224       sss.move("base",scan_pose)
00225       #if operator.mod(ctr,2) == 0:
00226       #  sss.move("torso",[[-0.2,0.0,-0.2]])
00227       #else:
00228       #  sss.move("torso","home")
00229       #sss.sleep(0.5)
00230       i = i+0.8
00231       #ctr = ctr+1
00232     sss.move("torso",[[-0.2,0.0,-0.2]])
00233     while i > 0:#6.2:
00234       i = i-0.8
00235       scan_pose[2]=i
00236       sss.move("base",scan_pose)
00237     goal.start = False
00238     self.client.send_goal(goal)
00239     self.client.wait_for_result(rospy.Duration.from_sec(5.0))
00240     #sss.move("torso","home")
00241     #move neck/base
00242     #get map
00243 
00244     return 'succeeded'
00245 
00246 class Map90(smach.State):
00247 
00248   def __init__(self):
00249 
00250     smach.State.__init__(
00251       self,
00252       outcomes=['succeeded', 'failed'],
00253       input_keys=['angle_range']) #good angle value: 0.4
00254     self.client = actionlib.SimpleActionClient('trigger_mapping', TriggerAction)
00255 
00256   def execute(self, userdata):
00257     scan_pose = [0.515, -1, 1.583]
00258     sss.move("tray","down")
00259     sss.move("torso","home")
00260     sss.move("head","front")
00261     sss.move("base",scan_pose)
00262     #sss.move("base",scan_position)
00263     goal = TriggerGoal()
00264     goal.start = True
00265     if not self.client.wait_for_server():#rospy.Duration.from_sec(5.0)):
00266       rospy.logerr('server not available')
00267       return 'failed'
00268     self.client.send_goal(goal)
00269     if not self.client.wait_for_result():#rospy.Duration.from_sec(5.0)):
00270       return 'failed'
00271     i = 1.8
00272     ctr = 0
00273     while ctr <= 2:#6.2:
00274       scan_pose[2]=i
00275       sss.move("base",scan_pose)
00276       #if operator.mod(ctr,2) == 0:
00277       #  sss.move("torso",[[-0.2,0.0,-0.2]])
00278       #else:
00279       #  sss.move("torso","home")
00280       #sss.sleep(0.5)
00281       i = i+0.8
00282       ctr = ctr+1
00283     sss.move("torso",[[-0.2,0.0,-0.2]])
00284     while ctr > 0:#6.2:
00285       i = i-0.9
00286       ctr = ctr-1
00287       scan_pose[2]=i
00288       sss.move("base",scan_pose)
00289     goal.start = False
00290     self.client.send_goal(goal)
00291     self.client.wait_for_result(rospy.Duration.from_sec(5.0))
00292     #sss.move("torso","home")
00293     #move neck/base
00294     #get map
00295 
00296     return 'succeeded'
00297 
00298 
00299 


cob_3d_mapping_pipeline
Author(s): Georg Arbeiter
autogenerated on Wed Aug 26 2015 11:03:28