00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 import threading
00019 from omniORB import any
00020
00021 import OpenRTM
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 class PublisherPeriodic(OpenRTM.PublisherBase):
00037 """
00038 """
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 def __init__(self, consumer, property):
00060 self._consumer = consumer
00061 self._running = True
00062 rate = property.getProperty("dataport.push_rate")
00063
00064 if type(rate) == str or type(rate) == float or type(rate) == long :
00065 rate = float(rate)
00066 else:
00067 rate = float(any.from_any(rate,keep_structs=True))
00068
00069 if rate:
00070 hz = rate
00071 if (hz == 0):
00072 hz = 1000.0
00073 else:
00074 hz = 1000.0
00075
00076 self._usec = int(1000000.0/hz)
00077
00078 self._running = True
00079 self._thread = threading.Thread(target=self.run)
00080 self._thread.start()
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 def __del__(self):
00095 self._running = False
00096 del self._consumer
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 def update(self):
00111 pass
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 def run(self):
00126 import time
00127 while self._running:
00128 self._consumer.push()
00129 time.sleep(self._usec/1000000.0)
00130
00131 return 0
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 def release(self):
00151 self._running = False