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  <!-- If you want to change send and recieve format of denso_robot_control, -->
41  <!-- you can specify the send_format and recv_format parameters -->
42  <arg name=\"send_format\" default=\"288\" />
43  <arg name=\"recv_format\" default=\"292\" />
44 
45  <arg name="bcap_slave_control_cycle_msec" default="8" />
46 
47  <include file=\"$(find denso_robot_bringup)/launch/denso_robot_bringup.launch\">
48  <arg name=\"robot_name\" value=\"{rob_name}\"/>
49  <arg name=\"sim\" value=\"$(arg sim)\"/>
50  <arg name=\"ip_address\" value=\"$(arg ip_address)\"/>
51  <arg name=\"send_format\" value=\"$(arg send_format)\" />
52  <arg name=\"recv_format\" value=\"$(arg recv_format)\" />
53  </include>
54 </launch>"""
55 
56 if __name__ == "__main__":
57  args = sys.argv
58 
59  # Check num of arguments
60  if len(args) < 2:
61  print("Usage: install_robot_description \"path of description folder\"")
62  sys.exit()
63 
64  path_desc = args[1]
65 
66  # Check path format
67  m = re.search("([\w\d_]+)_description/?$", path_desc)
68  if m == None:
69  print("Invalid path format: it have to be *_description")
70  sys.exit()
71 
72  rob_name = m.group(1)
73 
74  # Check path exists
75  if not os.path.isdir(path_desc):
76  print(path_desc + " does not exists")
77  sys.exit()
78 
79  # Check config directory
80  conf_dir = path_desc
81  if conf_dir[-1] != "/":
82  conf_dir += "/"
83  conf_dir += rob_name + "_config"
84  if not os.path.isdir(conf_dir):
85  print(conf_dir + " does not exists")
86  sys.exit()
87 
88  # Get package directory
89  try:
90  descs_pkg = roslib.packages.get_pkg_dir("denso_robot_descriptions")
91  conf_pkg = roslib.packages.get_pkg_dir("denso_robot_moveit_config")
92  bringup_pkg = roslib.packages.get_pkg_dir("denso_robot_bringup")
93  except roslib.packages.InvalidROSPkgException as e:
94  print(e)
95  sys.exit()
96 
97  if os.path.isdir(descs_pkg + "/" + rob_name + "_description"):
98  print(rob_name + "_description is already in the denso_robot_descriptions package")
99  sys.exit()
100 
101  if os.path.isdir(conf_pkg + "/config/" + rob_name + "_config"):
102  print(rob_name + "_config is already in the denso_robot_moveit_config package")
103  sys.exit()
104 
105  # Move config directory
106  shutil.move(conf_dir, conf_pkg + "/config")
107 
108  # Move description directory
109  shutil.move(path_desc, descs_pkg)
110 
111  # Make bringup launch file
112  f = open(bringup_pkg + "/launch/" + rob_name + "_bringup.launch", "w")
113  f.write(__BRINGUP_TEXT.replace("{rob_name}", rob_name))
114  f.close()


denso_robot_bringup
Author(s): DENSO WAVE INCORPORATED
autogenerated on Sat Feb 18 2023 04:06:00