urdf_remove_pedestal.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Software License Agreement (BSD License)
4 #
5 # Copyright (c) 2014-2017, Dataspeed Inc.
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without modification,
9 # are permitted provided that the following conditions are met:
10 #
11 # * Redistributions of source code must retain the above copyright notice,
12 # this list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
16 # * Neither the name of Dataspeed Inc. nor the names of its
17 # contributors may be used to endorse or promote products derived from this
18 # software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 import rospy
32 import re
33 
34 match_link = "(.*)<link[^>]*name\s*=\s*\"pedestal\"[^>]*>.*?[^<]<\/link>(.*)"
35 match_joint = "(.*)<joint[^>]*name\s*=\s*\"pedestal_fixed\"[^>]*>.*?[^<]<\/joint>(.*)"
36 
37 if __name__ == '__main__':
38  try:
39  rospy.init_node('urdf_remove_pedestal', anonymous=True)
40  param_src = rospy.get_param('~param_src', "/robot_description")
41  param_dest = rospy.get_param('~param_dest', "/robot_description_mod")
42  urdf = rospy.get_param(param_src, "")
43  changed = False
44  if urdf:
45  obj = re.match(match_link, urdf, re.S)
46  if obj:
47  urdf = obj.group(1) + obj.group(2)
48  changed = True
49  rospy.loginfo("Removed link 'pedestal'")
50  else:
51  rospy.logwarn("Failed to find link 'pedestal'")
52 
53  obj = re.match(match_joint, urdf, re.S)
54  if obj:
55  urdf = obj.group(1) + obj.group(2)
56  changed = True
57  rospy.loginfo("Removed joint 'pedestal_fixed'")
58  else:
59  rospy.logwarn("Failed to find joint 'pedestal_fixed'")
60 
61  rospy.set_param(param_dest, urdf)
62  if changed:
63  rospy.loginfo("Updated parameter '%s'", param_dest)
64  else:
65  rospy.loginfo("Copied parameter '%s' to '%s'", param_src, param_dest)
66  else:
67  rospy.logwarn("Parameter '%s' not found", param_src)
68  except rospy.ROSInterruptException: pass
69 
70 


mobility_base_tools
Author(s): Dataspeed Inc.
autogenerated on Sun Oct 6 2019 03:40:06