Controller.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 # -*- Python -*-
00004 
00005 import sys
00006 import time
00007 sys.path.append(".")
00008 
00009 # Import RTM module
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     # Set InPort buffers
00037     self.addInPort("in",self._inIn)
00038     
00039     # Set OutPort buffers
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   # Create a component
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()


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Aug 27 2015 14:17:28