Sensor.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 RTC
10 import OpenRTM_aist
11 
12 sensor_spec = ["implementation_id", "Sensor",
13  "type_name", "Sensor",
14  "description", "Sensor component",
15  "version", "1.0",
16  "vendor", "Noriaki Ando, AIST",
17  "category", "example",
18  "activity_type", "DataFlowComponent",
19  "max_instance", "10",
20  "language", "Python",
21  "lang_type", "SCRIPT",
22  ""]
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.TimedLong(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 "Sensor 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 def SensorInit(manager):
56  profile = OpenRTM_aist.Properties(defaults_str=sensor_spec)
57  manager.registerFactory(profile,
58  Sensor,
59  OpenRTM_aist.Delete)
60 
61 def MyModuleInit(manager):
62  SensorInit(manager)
63 
64  # Create a component
65  comp = manager.createComponent("Sensor")
66 
67 
68 def main():
69  mgr = OpenRTM_aist.Manager.init(sys.argv)
70  mgr.setModuleInitProc(MyModuleInit)
71  mgr.activateManager()
72  mgr.runManager()
73 
74 if __name__ == "__main__":
75  main()
76 
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