install_robot_description.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 '''
4  Software License Agreement (MIT License)
5 
6  @copyright Copyright (c) 2017 DENSO WAVE INCORPORATED
7 
8  Permission is hereby granted, free of charge, to any person obtaining a copy
9  of this software and associated documentation files (the "Software"), to deal
10  in the Software without restriction, including without limitation the rights
11  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  copies of the Software, and to permit persons to whom the Software is
13  furnished to do so, subject to the following conditions:
14 
15  The above copyright notice and this permission notice shall be included in
16  all copies or substantial portions of the Software.
17 
18  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24  THE SOFTWARE.
25 '''
26 
27 import os
28 import re
29 import sys
30 import rospy
31 import shutil
32 import roslib.packages
33 
34 __BRINGUP_TEXT = """<launch>
35  <!-- the "sim" argument controls whether we connect to a Simulated or Real robot -->
36  <!-- - if sim=false, a ip_address argument is required -->
37  <arg name="sim" default="true" />
38  <arg name="ip_address" default="192.168.0.1" />
39 
40  <include file=\"$(find denso_robot_bringup)/launch/denso_robot_bringup.launch">
41  <arg name=\"robot_name\" value=\"{rob_name}\"/>
42  <arg name=\"sim\" value=\"$(arg sim)\"/>
43  <arg name=\"ip_address\" value=\"$(arg ip_address)\"/>
44  </include>
45 </launch>"""
46 
47 if __name__ == "__main__":
48  args = sys.argv
49 
50  # Check num of arguments
51  if len(args) < 2:
52  print("Usage: install_robot_description \"path of description folder\"")
53  sys.exit()
54 
55  path_desc = args[1]
56 
57  # Check path format
58  m = re.search("([\w\d_]+)_description/?$", path_desc)
59  if m == None:
60  print("Invalid path format: it have to be *_description")
61  sys.exit()
62 
63  rob_name = m.group(1)
64 
65  # Check path exists
66  if not os.path.isdir(path_desc):
67  print(path_desc + " does not exists")
68  sys.exit()
69 
70  # Check config directory
71  conf_dir = path_desc
72  if conf_dir[-1] != "/":
73  conf_dir += "/"
74  conf_dir += rob_name + "_config"
75  if not os.path.isdir(conf_dir):
76  print(conf_dir + " does not exists")
77  sys.exit()
78 
79  # Get package directory
80  try:
81  descs_pkg = roslib.packages.get_pkg_dir("denso_robot_descriptions")
82  conf_pkg = roslib.packages.get_pkg_dir("denso_robot_moveit_config")
83  bringup_pkg = roslib.packages.get_pkg_dir("denso_robot_bringup")
84  except roslib.packages.InvalidROSPkgException as e:
85  print(e)
86  sys.exit()
87 
88  if os.path.isdir(descs_pkg + "/" + rob_name + "_description"):
89  print(rob_name + "_description is already in the denso_robot_descriptions package")
90  sys.exit()
91 
92  if os.path.isdir(conf_pkg + "/config/" + rob_name + "_config"):
93  print(rob_name + "_config is already in the denso_robot_moveit_config package")
94  sys.exit()
95 
96  # Move config directory
97  shutil.move(conf_dir, conf_pkg + "/config")
98 
99  # Move description directory
100  shutil.move(path_desc, descs_pkg)
101 
102  # Make bringup launch file
103  f = open(bringup_pkg + "/launch/" + rob_name + "_bringup.launch", "w")
104  f.write(__BRINGUP_TEXT.replace("{rob_name}", rob_name))
105  f.close()


denso_robot_bringup
Author(s): DENSO WAVE INCORPORATED
autogenerated on Mon Jun 10 2019 13:12:25