hrpsys_tools_config.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import roslib; roslib.load_manifest("hrpsys")
00003 import OpenRTM_aist.RTM_IDL # for catkin
00004 import sys
00005 
00006 from hrpsys import rtm
00007 from hrpsys.hrpsys_config import *
00008 import OpenHRP
00009 
00010 # copy from hrpsys/lib/python2.7/dist-packages/hrpsys_config.py
00011 import argparse, code
00012 if __name__ == '__main__':
00013     parser = argparse.ArgumentParser(description="hrpsys command line interpreters, try `./hrpsys_tools_config.py--host xxxx --port xxxx  -i` or `ipython ./hrpsys_tools_config.py -- --host xxxx --port xxxx` for robot debugging, we recommend to use ipython")
00014     parser.add_argument('--host', help='corba name server hostname')
00015     parser.add_argument('--port', help='corba name server port number')
00016     parser.add_argument('-i', help='interactive mode',  action='store_true')
00017     parser.add_argument('-c', help='execute command',  nargs='*')
00018     parser.add_argument('--use-unstable-rtc', help='use unstable rtc', action='store_true')
00019     args, unknown = parser.parse_known_args()
00020 
00021     if args.i: # interactive
00022         sys.argv.remove('-i')
00023     if args.c:
00024         sys.argv.remove('-c')
00025         [sys.argv.remove(a) for a in args.c] # remove command from sys.argv
00026     if args.host:
00027         rtm.nshost = args.host; sys.argv = [sys.argv[0]] + sys.argv[3:]
00028     if args.port:
00029         rtm.nsport = args.port; sys.argv = [sys.argv[0]] + sys.argv[3:]
00030 
00031     # ipython ./hrpsys_tools_config.py -i -- --port 2809
00032     hcf = HrpsysConfigurator()
00033     if args.use_unstable_rtc: # use Unstable RTC
00034         hcf.getRTCList = hcf.getRTCListUnstable; sys.argv = [sys.argv[0]] + sys.argv[2:]
00035     if args.i or '__IPYTHON__' in vars(__builtins__):
00036         hcf.waitForModelLoader()
00037         if len(sys.argv) > 1 and not sys.argv[1].startswith('-'):
00038             hcf.waitForRTCManagerAndRoboHardware(robotname=sys.argv[1])
00039             sys.argv = [sys.argv[0]] + sys.argv[2:]
00040         hcf.findComps()
00041         print >> sys.stderr, "[hrpsys.py] #\n[hrpsys.py] # use `hcf` as robot interface, for example hcf.getJointAngles()\n[hrpsys.py] #"
00042         while args.c != None:
00043             print >> sys.stderr, ">>", args.c[0]
00044             exec(args.c[0])
00045             args.c.pop(0)
00046         if not (args.i and '__IPYTHON__' in vars(__builtins__)):
00047             code.interact(local=locals()) #drop in shell if invoke from python, or ipython without -i option
00048     elif len(sys.argv) > 2 :
00049         hcf.init(sys.argv[1], sys.argv[2])
00050     elif len(sys.argv) > 1 :
00051         hcf.init(sys.argv[1])
00052     else :
00053         hcf.init()
00054 


hrpsys_tools
Author(s): Kei Okada
autogenerated on Mon Oct 6 2014 07:18:00