hironx.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 
00004 # Software License Agreement (BSD License)
00005 #
00006 # Copyright (c) 2013, JSK Lab, University of Tokyo
00007 # All rights reserved.
00008 #
00009 # Redistribution and use in source and binary forms, with or without
00010 # modification, are permitted provided that the following conditions
00011 # are met:
00012 #
00013 # * Redistributions of source code must retain the above copyright
00014 # notice, this list of conditions and the following disclaimer.
00015 # * Redistributions in binary form must reproduce the above
00016 # copyright notice, this list of conditions and the following
00017 # disclaimer in the documentation and/or other materials provided
00018 # with the distribution.
00019 # * Neither the name of JSK Lab, University of Tokyo. nor the
00020 # names of its contributors may be used to endorse or promote products
00021 # derived from this software without specific prior written permission.
00022 #
00023 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034 # POSSIBILITY OF SUCH DAMAGE.
00035 
00036 import socket
00037 
00038 from rospy import ROSInitException
00039 
00040 try:  # catkin does not requires load_manifest
00041     import hironx_ros_bridge
00042 except:
00043     import roslib
00044     roslib.load_manifest('hironx_ros_bridge')
00045 
00046 from hironx_ros_bridge import hironx_client
00047 from hironx_ros_bridge.ros_client import ROS_Client
00048 
00049 # See 'https://github.com/tork-a/rtmros_nextage/commit/' +
00050 #     'd4268d81ec14a514bb4b3b52614c81e708dd1ecc#' +_
00051 #     'diff-20257dd6ad60c0892cfb122c37a8f2ba'
00052 from hrpsys import rtm
00053 import argparse
00054 
00055 errormsg_noros = 'No ROS Master found. Without it, you cannot use ROS from' \
00056                  ' this script, but can use RTM. To use ROS, do not forget' \
00057                  ' to run rosbridge. How to do so? --> http://wiki.ros.org/rtmros_nextage/Tutorials/Operating%20Hiro%2C%20NEXTAGE%20OPEN'
00058 
00059 if __name__ == '__main__':
00060     parser = argparse.ArgumentParser(description='hiro command line interpreters')
00061     parser.add_argument('--host', help='corba name server hostname')
00062     parser.add_argument('--port', help='corba name server port number')
00063     parser.add_argument('--modelfile', help='robot model file nmae')
00064     parser.add_argument('--robot', help='robot modlule name (RobotHardware0 for real robot, Robot()')
00065     args, unknown = parser.parse_known_args()
00066     unknown = [u for u in unknown if u[:2] != '__'] # filter out ros arguments
00067 
00068     if args.host:
00069         rtm.nshost = args.host
00070     if args.port:
00071         rtm.nsport = args.port
00072     if not args.robot:
00073         args.robot = "RobotHardware0" if args.host else "HiroNX(Robot)0"
00074     if not args.modelfile:
00075         args.modelfile = "/opt/jsk/etc/HIRONX/model/main.wrl" if args.host else ""
00076 
00077     # support old style format
00078     if len(unknown) >= 2:
00079         args.robot = unknown[0]
00080         args.modelfile = unknown[1]
00081     robot = hiro = hironx_client.HIRONX()
00082     robot.init(robotname=args.robot, url=args.modelfile)
00083 
00084     # ROS Client
00085     try:
00086         ros = ROS_Client()
00087     except ROSInitException as e:
00088         print('[nextage.py] {}'.format(e))
00089     except socket.error as e: 
00090         print("\033[31m%s\n%s\033[0m" % (e.strerror, errormsg_noros))
00091 
00092 # for simulated robot
00093 # $ ./hironx.py
00094 #
00095 # for real robot
00096 # ../script/hironx.py -- --host hiro014
00097 # ./ipython -i hironx.py -- --host hiro014
00098 # for real robot with custom model file
00099 # ../script/hironx.py -- --host hiro014 --modelfile /opt/jsk/etc/HIRONX/model/main.wrl
00100 #
00101 # See http://unix.stackexchange.com/questions/11376/what-does-double-dash-mean
00102 # for the use of double-dash on unix/linux.


hironx_ros_bridge
Author(s): Kei Okada , Isaac I.Y. Saito
autogenerated on Thu Feb 21 2019 03:42:37