Motor.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 motor_spec = ["implementation_id", "Motor",
14  "type_name", "Motor",
15  "description", "Motor component",
16  "version", "1.0",
17  "vendor", "Noriaki Ando, AIST",
18  "category", "example",
19  "activity_type", "DataFlowComponent",
20  "max_instance", "10",
21  "language", "Python",
22  "lang_type", "SCRIPT",
23  "conf.default.motor_id", "0",
24  ""]
25 
27  def __init__(self, manager):
28  OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
29  return
30 
31  def onInitialize(self):
32  self._d_in = RTC.TimedFloat(RTC.Time(0,0),0)
33  self._inIn = OpenRTM_aist.InPort("in", self._d_in)
34  self._d_out = RTC.TimedLong(RTC.Time(0,0),0)
35  self._outOut = OpenRTM_aist.OutPort("out", self._d_out)
36 
37  # Set InPort buffers
38  self.addInPort("in",self._inIn)
39 
40  # Set OutPort buffers
41  self.addOutPort("out",self._outOut)
42 
43  self._motor_id = [0]
44 
45  # Bind variables and configuration variable
46  self.bindParameter("motor_id", self._motor_id, "0")
47  self._configsets.update("default")
48  return RTC.RTC_OK
49 
50 
51  def onExecute(self, ec_id):
52  if self._inIn.isNew():
53  data = self._inIn.read()
54  print "Motor Received data: ", data.data
55  self._d_out.data = long(data.data *2)
56  self._outOut.write()
57  return RTC.RTC_OK
58 
59 
60 
61 
62 def MotorInit(manager):
63  profile = OpenRTM_aist.Properties(defaults_str=motor_spec)
64  manager.registerFactory(profile,
65  Motor,
66  OpenRTM_aist.Delete)
67 
68 def MyModuleInit(manager):
69  MotorInit(manager)
70 
71  # Create a component
72  comp = manager.createComponent("Motor")
73 
74 
75 
76 def main():
77  mgr = OpenRTM_aist.Manager.init(sys.argv)
78  mgr.setModuleInitProc(MyModuleInit)
79  mgr.activateManager()
80  mgr.runManager()
81 
82 if __name__ == "__main__":
83  main()
84 
def bindParameter(self, param_name, var, def_val, trans=None)
template <typename vartype>=""> bool bindParameter(const char* param_name, VarType& var...
Definition: RTObject.py:2588
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