00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 import threading
00020 import time
00021
00022 import OpenRTM
00023 import RTC, RTC__POA
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 class ExtTrigExecutionContext(OpenRTM.PeriodicExecutionContext):
00042 """
00043 """
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 def __init__(self):
00058 OpenRTM.PeriodicExecutionContext.__init__(self)
00059 self._worker = self.Worker()
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 def tick(self):
00074 if not self._worker._cond.acquire(0):
00075 return
00076 self._worker._called = True
00077 self._worker._cond.notify()
00078 self._worker._cond.release()
00079 return
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 def run(self):
00095 flag = True
00096
00097 while flag:
00098 flag = self._running
00099 sec_ = float(self._usec)/1000000.0
00100 self._worker._cond.acquire()
00101 while not self._worker._called and self._running:
00102 self._worker._cond.wait()
00103 if self._worker._called:
00104 self._worker._called = False
00105 for comp in self._comps:
00106
00107 comp._sm.worker()
00108 while not self._running:
00109 time.sleep(sec_)
00110 time.sleep(sec_)
00111 self._worker._cond.release()
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 class Worker:
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 def __init__(self):
00141 self._mutex = threading.RLock()
00142 self._cond = threading.Condition(self._mutex)
00143 self._called = False
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 def ExtTrigExecutionContextInit(manager):
00158 manager.registerECFactory("ExtTrigExecutionContext",
00159 OpenRTM.ExtTrigExecutionContext,
00160 OpenRTM.ECDelete)