generate_load_moveit_config.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Software License Agreement (BSD License)
3 #
4 # Copyright (c) 2015, CITEC, Bielefeld University
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 #
11 # * Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above
14 # copyright notice, this list of conditions and the following
15 # disclaimer in the documentation and/or other materials provided
16 # with the distribution.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
30 
31 # Author: Guillaume Walck <gwalck@techfak.uni-bielefeld.de>
32 
33 """
34  generate and load one the following moveit yaml config file
35  based on srdf on parameter server
36  syntax : generate_load_moveit_config command [template_file]
37  fake_controllers (no template)
38  ompl_planning (template required)
39  kinematics (template required)
40  joint_limits (template required)
41  """
42 
43 import sys
44 import time
45 
46 import rospy
47 import rospkg
48 
49 from srdfdom.srdf import SRDF
50 
51 from generate_moveit_config import generate_fake_controllers, generate_real_controllers, \
52  generate_ompl_planning, generate_kinematics, generate_joint_limits
53 
54 if __name__ == '__main__':
55 
56  # detect the command to be executed
57  if len(sys.argv) > 1:
58  save_file = False
59  command = sys.argv[1]
60  rospy.init_node('moveit_config_generator', anonymous=True)
61  if command in ['fake_controllers', 'real_controllers', 'ompl_planning', 'kinematics', 'joint_limits']:
62  NS = rospy.get_namespace()
63  # wait for parameters
64  while (not rospy.search_param('robot_description_semantic') and not rospy.is_shutdown()):
65  time.sleep(0.5)
66  rospy.loginfo("waiting for robot_description_semantic")
67  # load the srdf from the parameter server
68  full_param_name = rospy.search_param('robot_description_semantic')
69  srdf_str = rospy.get_param(full_param_name)
70  # parse it
71  robot = SRDF.from_xml_string(srdf_str)
72  output_path = None
73  # generate the desired yaml and load it.
74  if command == "fake_controllers":
75  if save_file:
76  output_path = (rospkg.RosPack().get_path('sr_moveit_hand_config') + "/config/" +
77  "fake_controllers.yaml")
78  generate_fake_controllers(robot, output_path=output_path, ns_=NS)
79  elif command == "real_controllers":
80  if save_file:
81  output_path = (rospkg.RosPack().get_path('sr_moveit_hand_config') + "/config/" +
82  "controllers.yaml")
83  generate_real_controllers(robot, output_path=output_path, ns_=NS)
84  elif command == "ompl_planning":
85  # get the template file
86  if len(sys.argv) > 2:
87  template_path = sys.argv[2]
88  # reject ROS internal parameters and detect termination
89  if (template_path.startswith("_") or template_path.startswith("--")):
90  template_path = None
91  if save_file:
92  output_path = (rospkg.RosPack().get_path('sr_moveit_hand_config') + "/config/" +
93  "ompl_planning.yaml")
94  generate_ompl_planning(robot, template_path=template_path, output_path=output_path, ns_=NS)
95  else:
96  rospy.logerr("ompl_planning generation requires a template file, none provided")
97 
98  elif command == "kinematics":
99  # get the template file
100  if len(sys.argv) > 2:
101  template_path = sys.argv[2]
102  if (template_path.startswith("_") or template_path.startswith("--")):
103  template_path = None
104  if save_file:
105  output_path = (rospkg.RosPack().get_path('sr_moveit_hand_config') + "/config/" +
106  "kinematics.yaml")
107  generate_kinematics(robot, template_path=template_path, output_path=output_path, ns_=NS)
108  else:
109  rospy.logerr("kinematics generation requires a template file, none provided")
110  sys.exit(1)
111  elif command == "joint_limits":
112  # get the template file
113  if len(sys.argv) > 2:
114  template_path = sys.argv[2]
115  if (template_path.startswith("_") or template_path.startswith("--")):
116  template_path = None
117  if save_file:
118  output_path = (rospkg.RosPack().get_path('sr_moveit_hand_config') + "/config/" +
119  "joint_limits.yaml")
120  generate_joint_limits(robot, template_path=template_path, output_path=output_path, ns_=NS)
121  else:
122  rospy.logerr("joint_limits generation requires a template file, none provided")
123  else:
124  rospy.logerr("Wrong argument " + command)
125 
126  rospy.loginfo("Successfully loaded " + command + " params")
127  else:
128  rospy.logerr("Unrecognized command " + command +
129  ". Choose among fake_controllers, real_controllers, ompl_planning, kinematics, joint_limits")
130  else:
131  rospy.logerr("Argument needed. Choose among fake_controllers, ompl_planning, kinematics, joint_limits")
def generate_real_controllers(robot, output_path=None, ns_=None)
def generate_ompl_planning(robot, template_path="ompl_planning_template.yaml", output_path=None, ns_=None)
def generate_kinematics(robot, template_path="kinematics_template.yaml", output_path=None, ns_=None)
def generate_fake_controllers(robot, output_path=None, ns_=None)
def generate_joint_limits(robot, template_path="joint_limits_template.yaml", output_path=None, ns_=None)


sr_moveit_hand_config
Author(s): MoveIt Setup Assistant , Guillaume Walck
autogenerated on Wed Oct 14 2020 04:05:17