$search
00001 #! /usr/bin/env python 00002 00003 import sys 00004 import yaml 00005 import roslib 00006 import re 00007 00008 # Expect robot name as argument 00009 if(len(sys.argv) != 2): 00010 print("Usage: create_launch_files <your_robot_name>") 00011 sys.exit(-1) 00012 00013 robotName = sys.argv[1] 00014 directoryName = roslib.packages.get_pkg_dir(robotName + "_arm_navigation") 00015 00016 if(not roslib.packages.is_pkg_dir(directoryName)): 00017 print(robotName + " package does not exist ") 00018 sys.exit(-2) 00019 00020 # Plnning description yaml file 00021 yamlFileName = directoryName + '/config/' + robotName + '_planning_description.yaml' 00022 00023 # Get dictionary of yaml defs 00024 data = yaml.safe_load(open(yamlFileName, 'r')) 00025 00026 #getting world frame for rviz 00027 multi_dof = data['multi_dof_joints'] 00028 world_joint = multi_dof[0] 00029 world_frame = world_joint['parent_frame_id'] 00030 00031 # List of groups 00032 groups = data['groups'] 00033 00034 if(len(groups) < 1) : 00035 print("Need at least 1 planning group in the robot to continue!") 00036 sys.exit(-1) 00037 00038 # Substitution strings 00039 left_arm = None 00040 right_arm = None 00041 left_arm_name = 'none' 00042 right_arm_name = 'none' 00043 left_arm_ik = 'none' 00044 right_arm_ik = 'none' 00045 00046 done_left = False 00047 done_right = False 00048 00049 for i in groups: 00050 if 'tip_link' in i: 00051 if not done_left: 00052 left_arm = i 00053 done_left = True 00054 else: 00055 done_right = True 00056 right_arm = i 00057 break 00058 00059 left_arm_name = left_arm['name'] 00060 left_arm_ik = left_arm['tip_link'] 00061 00062 if done_right: 00063 right_arm_name = right_arm['name'] 00064 right_arm_ik = right_arm['tip_link'] 00065 00066 # Switch left and right arms if we find any of the following strings in the left arm 00067 # this is a terrible hack, but by convention we assume one of these strings is in the right arm 00068 if(re.search("right | Right | RIGHT | ^r_ | _r$ | ^R_ | _R$", left_arm_name)) : 00069 temp = left_arm_name 00070 left_arm_name = right_arm_name 00071 right_arm_name = temp 00072 temp = left_arm_ik 00073 left_arm_ik = right_arm_ik 00074 right_arm_ik = temp 00075 00076 template = open(roslib.packages.get_pkg_dir('move_arm_warehouse')+'/scripts/planning_scene_warehouse_viewer_template.launch', 'r') 00077 text = template.read() 00078 00079 text = re.sub('__ROBOT_NAME__', sys.argv[1], text) 00080 text = re.sub('__LEFT_GROUP__', left_arm_name, text) 00081 text = re.sub('__RIGHT_GROUP__', right_arm_name, text) 00082 text = re.sub('__LEFT_IK__', left_arm_ik, text) 00083 text = re.sub('__RIGHT_IK__', right_arm_ik, text) 00084 00085 #interpolated ik will only work with two arms for now 00086 if right_arm_name == 'none': 00087 text = re.sub('/l_interpolated_ik_motion_plan', 'none', text) 00088 text = re.sub('/r_interpolated_ik_motion_plan', 'none', text) 00089 00090 launch = open(directoryName+'/launch/planning_scene_warehouse_viewer_'+sys.argv[1]+'.launch', 'w') 00091 launch.write(text) 00092 00093 launch.close() 00094 template.close() 00095 00096 #Now we do the rviz template 00097 00098 rviz_template = open(roslib.packages.get_pkg_dir('move_arm_warehouse')+'/scripts/planning_scene_warehouse_viewer_template.vcg', 'r') 00099 rviz_text = rviz_template.read() 00100 rviz_text = re.sub('__WORLD_FRAME__', world_frame, rviz_text) 00101 out_vcg = open(directoryName+'/config/planning_scene_warehouse_viewer.vcg', 'w') 00102 out_vcg.write(rviz_text) 00103 out_vcg.close() 00104 rviz_template.close() 00105 00106 exit(0)