00001 #!/usr/bin/env python 00002 # -*- coding: utf-8 -*- 00003 00004 # Software License Agreement (BSD License) 00005 # 00006 # Copyright (c) 2013, Tokyo Opensource Robotics Kyokai Association 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 Tokyo Opensource Robotics Kyokai Association. 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 # Author: Isaac Isao Saito 00037 00038 import socket 00039 00040 from hironx_ros_bridge.ros_client import ROS_Client 00041 # This should come earlier than later import. 00042 # See http://code.google.com/p/rtm-ros-robotics/source/detail?r=6773 00043 from nextage_ros_bridge import nextage_client 00044 from rospy import ROSInitException 00045 00046 from hrpsys import rtm 00047 import argparse 00048 00049 errormsg_noros = 'No ROS Master found. Without it, you cannot use ROS from' \ 00050 ' this script, but can use RTM. To use ROS, do not forget' \ 00051 ' to run rosbridge. How to do so? --> http://wiki.ros.org/rtmros_nextage/Tutorials/Operating%20Hiro%2C%20NEXTAGE%20OPEN' 00052 00053 if __name__ == '__main__': 00054 parser = argparse.ArgumentParser(description='hiro command line interpreters') 00055 parser.add_argument('--host', help='corba name server hostname') 00056 parser.add_argument('--port', help='corba name server port number') 00057 parser.add_argument('--modelfile', help='robot model file nmae') 00058 parser.add_argument('--robot', help='robot modlule name (RobotHardware0 for real robot, Robot()') 00059 parser.add_argument('--dio_ver', help="Version of digital I/O. Only users " 00060 "whose robot was shipped before Aug 2014 need to " 00061 "define this, and the value should be '0.4.2'.") 00062 args, unknown = parser.parse_known_args() 00063 00064 if args.host: 00065 rtm.nshost = args.host 00066 if args.port: 00067 rtm.nsport = args.port 00068 if not args.robot: 00069 args.robot = "RobotHardware0" if args.host else "HiroNX(Robot)0" 00070 if not args.modelfile: 00071 args.modelfile = "/opt/jsk/etc/NEXTAGE/model/main.wrl" if args.host else "" 00072 00073 # support old style format 00074 if len(unknown) >= 2: 00075 args.robot = unknown[0] 00076 args.modelfile = unknown[1] 00077 robot = nxc = nextage_client.NextageClient() 00078 # Use generic name for the robot instance. This enables users on the 00079 # script commandline (eg. ipython) to run the same commands without asking 00080 # them to specifically tell what robot they're using (eg. hiro, nxc). 00081 # This is backward compatible so that users can still keep using `nxc`. 00082 # See http://code.google.com/p/rtm-ros-robotics/source/detail?r=6926 00083 robot.init(robotname=args.robot, url=args.modelfile) 00084 00085 if args.dio_ver: 00086 robot.set_hand_version(args.dio_ver) 00087 00088 try: 00089 ros = ROS_Client() 00090 except ROSInitException as e: 00091 print('[nextage.py] {}'.format(e)) 00092 except socket.error as e: 00093 print("\033[31m%s\n%s\033[0m" % (e.strerror, errormsg_noros)) 00094 00095 # for simulated robot 00096 # $ ./hironx.py 00097 # 00098 # for real robot 00099 # ./hironx.py --host hiro014 00100 # ./ipython -i hironx.py --host hiro014 00101 # for real robot with custom model file 00102 # ./hironx.py --host hiro014 --modelfile /opt/jsk/etc/NEXTAGE/model/main.wrl