Go to the documentation of this file.00001
00002
00003
00004
00005 import sys
00006 import time
00007 sys.path.append(".")
00008
00009 import RTC
00010 import OpenRTM_aist
00011
00012 sensor_spec = ["implementation_id", "Sensor",
00013 "type_name", "Sensor",
00014 "description", "Sensor component",
00015 "version", "1.0",
00016 "vendor", "Noriaki Ando, AIST",
00017 "category", "example",
00018 "activity_type", "DataFlowComponent",
00019 "max_instance", "10",
00020 "language", "Python",
00021 "lang_type", "SCRIPT",
00022 ""]
00023
00024
00025 class Sensor(OpenRTM_aist.DataFlowComponentBase):
00026 def __init__(self, manager):
00027 OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
00028 return
00029
00030 def onInitialize(self):
00031 self._d_in = RTC.TimedLong(RTC.Time(0,0),0)
00032 self._inIn = OpenRTM_aist.InPort("in", self._d_in)
00033 self._d_out = RTC.TimedFloat(RTC.Time(0,0),0)
00034 self._outOut = OpenRTM_aist.OutPort("out", self._d_out)
00035
00036
00037 self.addInPort("in",self._inIn)
00038
00039
00040 self.addOutPort("out",self._outOut)
00041
00042 return RTC.RTC_OK
00043
00044
00045 def onExecute(self, ec_id):
00046 if self._inIn.isNew():
00047 data = self._inIn.read()
00048 print "Sensor Received data: ", data.data
00049 self._d_out.data = data.data *2
00050 self._outOut.write()
00051 return RTC.RTC_OK
00052
00053
00054
00055 def SensorInit(manager):
00056 profile = OpenRTM_aist.Properties(defaults_str=sensor_spec)
00057 manager.registerFactory(profile,
00058 Sensor,
00059 OpenRTM_aist.Delete)
00060
00061 def MyModuleInit(manager):
00062 SensorInit(manager)
00063
00064
00065 comp = manager.createComponent("Sensor")
00066
00067
00068 def main():
00069 mgr = OpenRTM_aist.Manager.init(sys.argv)
00070 mgr.setModuleInitProc(MyModuleInit)
00071 mgr.activateManager()
00072 mgr.runManager()
00073
00074 if __name__ == "__main__":
00075 main()
00076