Controller.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # -*- Python -*-
4 
5 import sys
6 import time
7 sys.path.append(".")
8 
9 # Import RTM module
10 import RTC
11 import OpenRTM_aist
12 
13 controller_spec = ["implementation_id", "Controller",
14  "type_name", "Controller",
15  "description", "Controller component",
16  "version", "1.0",
17  "vendor", "Shinji Kurihara, AIST",
18  "category", "example",
19  "activity_type", "DataFlowComponent",
20  "max_instance", "10",
21  "language", "Python",
22  "lang_type", "SCRIPT",
23  ""]
24 
26  def __init__(self, manager):
27  OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
28  return
29 
30  def onInitialize(self):
31  self._d_in = RTC.TimedFloat(RTC.Time(0,0),0)
32  self._inIn = OpenRTM_aist.InPort("in", self._d_in)
33  self._d_out = RTC.TimedFloat(RTC.Time(0,0),0)
34  self._outOut = OpenRTM_aist.OutPort("out", self._d_out)
35 
36  # Set InPort buffers
37  self.addInPort("in",self._inIn)
38 
39  # Set OutPort buffers
40  self.addOutPort("out",self._outOut)
41 
42  return RTC.RTC_OK
43 
44 
45  def onExecute(self, ec_id):
46  if self._inIn.isNew():
47  data = self._inIn.read()
48  print "Controller Received data: ", data.data
49  self._d_out.data = data.data *2
50  self._outOut.write()
51  return RTC.RTC_OK
52 
53 
54 
55 
56 def ControllerInit(manager):
57  profile = OpenRTM_aist.Properties(defaults_str=controller_spec)
58  manager.registerFactory(profile,
59  Controller,
60  OpenRTM_aist.Delete)
61 
62 def MyModuleInit(manager):
63  ControllerInit(manager)
64 
65  # Create a component
66  comp = manager.createComponent("Controller")
67 
68 
69 
70 def main():
71  mgr = OpenRTM_aist.Manager.init(sys.argv)
72  mgr.setModuleInitProc(MyModuleInit)
73  mgr.activateManager()
74  mgr.runManager()
75 
76 if __name__ == "__main__":
77  main()
The Properties class represents a persistent set of properties.
Definition: Properties.py:83
def addOutPort(self, name, outport)
Definition: RTObject.py:2765
def addInPort(self, name, inport)
Definition: RTObject.py:2721
InPort template class.
Definition: InPort.py:58


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Jun 6 2019 19:11:34