hironx.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 # Software License Agreement (BSD License)
5 #
6 # Copyright (c) 2013, JSK Lab, University of Tokyo
7 # All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
12 #
13 # * Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # * Redistributions in binary form must reproduce the above
16 # copyright notice, this list of conditions and the following
17 # disclaimer in the documentation and/or other materials provided
18 # with the distribution.
19 # * Neither the name of JSK Lab, University of Tokyo. nor the
20 # names of its contributors may be used to endorse or promote products
21 # derived from this software without specific prior written permission.
22 #
23 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 # POSSIBILITY OF SUCH DAMAGE.
35 
36 import socket
37 
38 from rospy import ROSInitException
39 
40 try: # catkin does not requires load_manifest
41  import hironx_ros_bridge
42 except:
43  import roslib
44  roslib.load_manifest('hironx_ros_bridge')
45 
46 from hironx_ros_bridge import hironx_client
47 from hironx_ros_bridge.ros_client import ROS_Client
48 
49 # See 'https://github.com/tork-a/rtmros_nextage/commit/' +
50 # 'd4268d81ec14a514bb4b3b52614c81e708dd1ecc#' +_
51 # 'diff-20257dd6ad60c0892cfb122c37a8f2ba'
52 from hrpsys import rtm
53 import argparse
54 
55 errormsg_noros = 'No ROS Master found. Without it, you cannot use ROS from' \
56  ' this script, but can use RTM. To use ROS, do not forget' \
57  ' to run rosbridge. How to do so? --> http://wiki.ros.org/rtmros_nextage/Tutorials/Operating%20Hiro%2C%20NEXTAGE%20OPEN'
58 
59 if __name__ == '__main__':
60  parser = argparse.ArgumentParser(description='hiro command line interpreters')
61  parser.add_argument('--host', help='corba name server hostname')
62  parser.add_argument('--port', help='corba name server port number')
63  parser.add_argument('--modelfile', help='robot model file nmae')
64  parser.add_argument('--robot', help='robot modlule name (RobotHardware0 for real robot, Robot()')
65  args, unknown = parser.parse_known_args()
66  unknown = [u for u in unknown if u[:2] != '__'] # filter out ros arguments
67 
68  if args.host:
69  rtm.nshost = args.host
70  if args.port:
71  rtm.nsport = args.port
72  if not args.robot:
73  args.robot = "RobotHardware0" if args.host else "HiroNX(Robot)0"
74  if not args.modelfile:
75  args.modelfile = "/opt/jsk/etc/HIRONX/model/main.wrl" if args.host else ""
76 
77  # support old style format
78  if len(unknown) >= 2:
79  args.robot = unknown[0]
80  args.modelfile = unknown[1]
81  robot = hiro = hironx_client.HIRONX()
82  robot.init(robotname=args.robot, url=args.modelfile)
83 
84  # ROS Client
85  try:
86  ros = ROS_Client()
87  except ROSInitException as e:
88  print('[nextage.py] {}'.format(e))
89  except socket.error as e:
90  print("\033[31m%s\n%s\033[0m" % (e.strerror, errormsg_noros))
91 
92 # for simulated robot
93 # $ ./hironx.py
94 #
95 # for real robot
96 # ../script/hironx.py -- --host hiro014
97 # ./ipython -i hironx.py -- --host hiro014
98 # for real robot with custom model file
99 # ../script/hironx.py -- --host hiro014 --modelfile /opt/jsk/etc/HIRONX/model/main.wrl
100 #
101 # See http://unix.stackexchange.com/questions/11376/what-does-double-dash-mean
102 # for the use of double-dash on unix/linux.
bool init()


hironx_ros_bridge
Author(s): Kei Okada , Isaac I.Y. Saito
autogenerated on Thu May 14 2020 03:52:05