nextage.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, Tokyo Opensource Robotics Kyokai Association
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 Tokyo Opensource Robotics Kyokai Association. 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 # Author: Isaac Isao Saito
37 
38 import socket
39 
40 from hironx_ros_bridge.ros_client import ROS_Client
41 # This should come earlier than later import.
42 # See http://code.google.com/p/rtm-ros-robotics/source/detail?r=6773
43 from nextage_ros_bridge import nextage_client
44 from rospy import ROSInitException
45 
46 from hrpsys import rtm
47 import argparse
48 
49 errormsg_noros = 'No ROS Master found. Without it, you cannot use ROS from' \
50  ' this script, but can use RTM. To use ROS, do not forget' \
51  ' to run rosbridge. How to do so? --> http://wiki.ros.org/rtmros_nextage/Tutorials/Operating%20Hiro%2C%20NEXTAGE%20OPEN'
52 
53 if __name__ == '__main__':
54  parser = argparse.ArgumentParser(description='hiro command line interpreters')
55  parser.add_argument('--host', help='corba name server hostname')
56  parser.add_argument('--port', help='corba name server port number')
57  parser.add_argument('--modelfile', help='robot model file nmae')
58  parser.add_argument('--robot', help='robot modlule name (RobotHardware0 for real robot, Robot()')
59  parser.add_argument('--dio_ver', help="Version of digital I/O. Only users "
60  "whose robot was shipped before Aug 2014 need to "
61  "define this, and the value should be '0.4.2'.")
62  args, unknown = parser.parse_known_args()
63 
64  if args.host:
65  rtm.nshost = args.host
66  if args.port:
67  rtm.nsport = args.port
68  if not args.robot:
69  args.robot = "RobotHardware0" if args.host else "HiroNX(Robot)0"
70  if not args.modelfile:
71  args.modelfile = "/opt/jsk/etc/NEXTAGE/model/main.wrl" if args.host else ""
72 
73  # support old style format
74  if len(unknown) >= 2:
75  args.robot = unknown[0]
76  args.modelfile = unknown[1]
77  robot = nxc = nextage_client.NextageClient()
78  # Use generic name for the robot instance. This enables users on the
79  # script commandline (eg. ipython) to run the same commands without asking
80  # them to specifically tell what robot they're using (eg. hiro, nxc).
81  # This is backward compatible so that users can still keep using `nxc`.
82  # See http://code.google.com/p/rtm-ros-robotics/source/detail?r=6926
83  robot.init(robotname=args.robot, url=args.modelfile)
84 
85  if args.dio_ver:
86  robot.set_hand_version(args.dio_ver)
87 
88  try:
89  ros = ROS_Client()
90  except ROSInitException as e:
91  print('[nextage.py] {}'.format(e))
92  except socket.error as e:
93  print("\033[31m%s\n%s\033[0m" % (e.strerror, errormsg_noros))
94 
95 # for simulated robot
96 # $ ./hironx.py
97 #
98 # for real robot
99 # ./hironx.py --host hiro014
100 # ./ipython -i hironx.py --host hiro014
101 # for real robot with custom model file
102 # ./hironx.py --host hiro014 --modelfile /opt/jsk/etc/NEXTAGE/model/main.wrl
bool init()


nextage_ros_bridge
Author(s): Isaac Isao Saito , Akio Ochiai
autogenerated on Wed Jun 17 2020 04:14:47