Go to the documentation of this file.00001
00002
00003
00004
00005 import sys
00006 import time
00007 sys.path.append(".")
00008
00009
00010 import RTC
00011 import OpenRTM_aist
00012
00013 controller_spec = ["implementation_id", "Controller",
00014 "type_name", "Controller",
00015 "description", "Controller component",
00016 "version", "1.0",
00017 "vendor", "Shinji Kurihara, AIST",
00018 "category", "example",
00019 "activity_type", "DataFlowComponent",
00020 "max_instance", "10",
00021 "language", "Python",
00022 "lang_type", "SCRIPT",
00023 ""]
00024
00025 class Controller(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.TimedFloat(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 "Controller 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
00056 def ControllerInit(manager):
00057 profile = OpenRTM_aist.Properties(defaults_str=controller_spec)
00058 manager.registerFactory(profile,
00059 Controller,
00060 OpenRTM_aist.Delete)
00061
00062 def MyModuleInit(manager):
00063 ControllerInit(manager)
00064
00065
00066 comp = manager.createComponent("Controller")
00067
00068
00069
00070 def main():
00071 mgr = OpenRTM_aist.Manager.init(sys.argv)
00072 mgr.setModuleInitProc(MyModuleInit)
00073 mgr.activateManager()
00074 mgr.runManager()
00075
00076 if __name__ == "__main__":
00077 main()