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 # Author: Shadow Robot Software Team <software@shadowrobot.com>
33 
34 import sys
35 import time
36 import yaml
37 import rospy
38 import rospkg
39 
40 from srdfdom.srdf import SRDF
41 
42 from generate_moveit_config import generate_fake_controllers, generate_real_controllers, \
43  generate_ompl_planning, generate_kinematics, generate_joint_limits
44 import generate_robot_srdf
45 
46 if __name__ == '__main__':
47 
48  # detect the command to be executed
49  if len(sys.argv) > 2:
50  save_file = False
51  command = sys.argv[1]
52  robot_config_file = sys.argv[2]
53  rospy.init_node('moveit_config_generator', anonymous=True)
54  if command in ['fake_controllers', 'real_controllers', 'ompl_planning', 'kinematics', 'joint_limits']:
55  NS = rospy.get_namespace()
56  # wait for parameters
57  while (not rospy.search_param('robot_description_semantic') and not rospy.is_shutdown()):
58  time.sleep(0.5)
59  rospy.loginfo("waiting for robot_description_semantic")
60  # load the srdf from the parameter server
61  full_param_name = rospy.search_param('robot_description_semantic')
62  srdf_str = rospy.get_param(full_param_name)
63  # parse it
64  robot = SRDF.from_xml_string(srdf_str)
65 
66  sh_config_path = rospkg.RosPack().get_path('sr_moveit_hand_config') + "/config/"
67 
68  with open(robot_config_file, "r") as stream:
69  yamldoc = yaml.load(stream)
70  robot_config = generate_robot_srdf.Robot()
71  robot_config.set_parameters(yamldoc)
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_multi_moveit_config') + "/config/" +
77  "fake_controllers.yaml")
78  generate_fake_controllers(robot, robot_config, output_path=output_path, ns_=NS)
79  elif command == "real_controllers":
80  if save_file:
81  output_path = rospkg.RosPack().get_path('sr_multi_moveit_config') + "/config/" + "controllers.yaml"
82  generate_real_controllers(robot, robot_config, output_path=output_path, ns_=NS)
83  elif command == "ompl_planning":
84  hand_template_path = sh_config_path + "ompl_planning_template.yaml"
85  if save_file:
86  output_path = (rospkg.RosPack().get_path('sr_multi_moveit_config') + "/config/" +
87  "ompl_planning.yaml")
88  generate_ompl_planning(robot, robot_config, hand_template_path, output_path=output_path, ns_=NS)
89  elif command == "kinematics":
90  # get the template file
91  hand_template_path = sys.argv[3]
92  if (hand_template_path.startswith("_") or hand_template_path.startswith("--")):
93  hand_template_path = None
94  if save_file:
95  output_path = (rospkg.RosPack().get_path('sr_multi_moveit_config') + "/config/" + "kinematics.yaml")
96  generate_kinematics(robot, robot_config, hand_template_path, output_path=output_path, ns_=NS)
97  elif command == "joint_limits":
98  hand_template_path = sh_config_path + "joint_limits_template.yaml"
99  if save_file:
100  output_path = (rospkg.RosPack().get_path('sr_multi_moveit_config') + "/config/" +
101  "joint_limits.yaml")
102  generate_joint_limits(robot, robot_config, hand_template_path, output_path=output_path, ns_=NS)
103  else:
104  rospy.logerr("Wrong argument " + command)
105 
106  rospy.loginfo("Successfully loaded " + command + " params")
107  else:
108  rospy.logerr("Unrecognized command " + command +
109  ". Choose among fake_controllers, ompl_planning, kinematics, joint_limits")
110  else:
111  rospy.logerr("Argument needed. Choose among fake_controllers, ompl_planning, kinematics, joint_limits")
def generate_kinematics(robot, robot_config, hand_template_path="kinematics_template.yaml", output_path=None, ns_=None)
def generate_ompl_planning(robot, robot_config, hand_template_path="ompl_planning_template.yaml", output_path=None, ns_=None)
def generate_real_controllers(robot, robot_config, output_path=None, ns_=None)
def generate_fake_controllers(robot, robot_config, output_path=None, ns_=None)
def generate_joint_limits(robot, robot_config, hand_template_path="joint_limits_template.yaml", output_path=None, ns_=None)


sr_multi_moveit_config
Author(s): MoveIt Setup Assistant
autogenerated on Wed Oct 14 2020 04:05:22