hrpPrep.py
Go to the documentation of this file.
1 #
2 # Prepare Scripting Environment Parameters
3 #
4 # This module can do with a little tidying up.
5 # ... perhaps with a Meta-class
6 #
7 
8 import time, string
9 
10 
14 def doNarrow4Jython(corbaClass, corbaObject):
15  return corbaClass.narrow(corbaObject)
16 
17 
18 def getORBJython(argv):
19  props = System.getProperties()
20  s = System.getenv("NS_OPT")
21  if(not s):
22  s = System.getenv("NS_OPT")
23 
24  if(s == ''):
25  args = argv
26  else:
27  args = string.split(s)
28  #
29  return CORBA.ORB.init(args, props)
30 
31 
33  #print 'getPluginObject2NarrowJython'
34  try:
35  exec('import Simulator.'+name+'Helper as localImport')
36  return localImport
37  except ImportError:
38  return None
39 
40 #def importJavaPlugins():
41 # pluginList = dir(Simulator)
42 # for p in pluginList:
43 # if p[-6:] == 'Helper':
44 # print 'import Simulator.'+p+' as '+p[:-6]
45 # #exec('import Simulator.'+p+' as '+p[:-6])
46 #
47 
48 
49 
50 
54 def doNarrow4Python(corbaClass, corbaObject):
55  #print 'corbaClass = ', corbaClass
56  #print 'corbaObject = ', corbaObject
57  try:
58  tmp = corbaObject._narrow(corbaClass)
59  #print 'narrowed result is', tmp
60  return tmp
61  except:
62  print('narrow exception:', corbaObject, 'to', corbaClass)
63 
64  return None
65 
66 
67 def getORBPython(argv):
68  return CORBA.ORB_init(argv, CORBA.ORB_ID)
69 
70 
72  print(name)
73  print('getPluginObject2NarrowPython('+name+')')
74  try:
75  exec('from _GlobalIDL import '+name+' as localImport')
76  return localImport
77  except ImportError:
78  return None
79 #
80 
81 
82 global doNarrow
83 doNarrow = None
84 
85 try: # platform is Jython
86  import java.lang.System as System
87  print('platform is probably Jython')
88  import org.omg.CORBA as CORBA
89 
90  from org.omg.CosNaming import NameComponent
91  from org.omg.CosNaming.NamingContextPackage import NotFound
92  from jp.go.aist.hrp import simulator as IDLBase
93 
94  Platform = 'J'
95 
96  # Naming Context
97  from org.omg.CosNaming import NamingContextHelper as NamingContext
98  # Plugin Manager (fails here...)
99  #from IDLBase import PluginManagerHelper as PluginManager
100  #import IDLBase.PluginManagerHelper as PluginManager
101  PluginManager = IDLBase.PluginManagerHelper
102  # Command Receiver
103  #from IDLBase import CommandReceiverHelper as CommandReceiver
104  CommandReceiver = IDLBase.CommandReceiverHelper
105  # Plugin
106  #from IDLBase import PluginHelper as Plugin
107  Plugin = IDLBase.PluginHelper
108  # Logger Plugin
109  #from IDLBase import LoggerPluginHelper as LoggerPlugin
110  LoggerPlugin = IDLBase.LoggerPluginHelper
111  # Sequence Player
112  #from IDLBase import SequencePlayerHelper as SequencePlayer
113  SequencePlayer = IDLBase.SequencePlayerHelper
114 
115  stateProvider = IDLBase.stateProviderHelper
116  IoControPlugin = IDLBase.IoControlPluginHelper
117  # set specialised function
118  doNarrow = doNarrow4Jython
119  getORB = getORBJython
120  getPluginObject2Narrow = getPluginObject2NarrowJython
121 
122 except ImportError: # platform is not Jython
123  print('platform is probably CPython')
124  import omniORB.CORBA as CORBA
125  import CosNaming
126  import _GlobalIDL as IDLBase
127 
128  NameComponent = CosNaming.NameComponent
129  NotFound = CosNaming.NamingContext.NotFound
130 
131  Platform = 'C'
132 
133  # Naming Context
134  NamingContext = CosNaming.NamingContext
135  # Plugin Manager
136  #from IDLBase import PluginManager
137  PluginManager = IDLBase.PluginManager
138  # Command Receiver
139  #from IDLBase import CommandReceiver
140  CommandReceiver = IDLBase.CommandReceiver
141  # Plugin
142  #from IDLBase import Plugin
143  Plugin = IDLBase.Plugin
144  # Logger Plugin
145  #from IDLBase import LoggerPlugin
146  LoggerPlugin = IDLBase.LoggerPlugin
147  # Sequence Player
148  #from IDLBase import SequencePlayer
149  SequencePlayer = IDLBase.SequencePlayer
150  # set specialised functions
151  stateProvider = IDLBase.stateProvider
152  IoControPlugin = IDLBase.IoControlPlugin
153 
154  doNarrow = doNarrow4Python
155  getORB = getORBPython
156  getPluginObject2Narrow = getPluginObject2NarrowPython
157 
158 #---------------------------------------------------#
159 
161  return NotFound, NamingContext, NameComponent, \
162  IDLBase, \
163  PluginManager, \
164  Plugin, \
165  CommandReceiver, \
166  stateProvider, \
167  IoControPlugin, \
168  LoggerPlugin, \
169  SequencePlayer
def getPluginObject2NarrowPython(name)
Definition: hrpPrep.py:71
def getORBPython(argv)
Definition: hrpPrep.py:67
def getPluginObject2NarrowJython(name)
Definition: hrpPrep.py:32
def getORBJython(argv)
Definition: hrpPrep.py:18
def doNarrow4Python(corbaClass, corbaObject)
Functions for Python+omniORB.
Definition: hrpPrep.py:54
def getCORBAObjects()
Definition: hrpPrep.py:160
def doNarrow4Jython(corbaClass, corbaObject)
Functions for Jython.
Definition: hrpPrep.py:14


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Sep 8 2022 02:24:03