TkMotorComp.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # -*- Python -*-
4 
5 import sys
6 sys.path.append(".")
7 
8 import RTC
9 import OpenRTM_aist
10 
11 import tkmotor
12 import time
13 
14 
15 mod_spec = ["implementation_id", "TkMotorComp",
16  "type_name", "TkMotorComp",
17  "description", "Tk Motor component (velocity control)",
18  "version", "1.0",
19  "vendor", "Noriaki Ando and Shinji Kurihara",
20  "category", "Generic",
21  "activity_type", "DataFlowComponent",
22  "max_instance", "10",
23  "language", "Python",
24  "lang_type""SCRIPT",
25  ""]
26 
27 
28 tkm = tkmotor.TkMotor(6, 40)
29 #thread.start_new_thread(tkm.mainloop, ())
30 
32  def __init__(self, manager):
33  OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
34  self._cnt = 0
35  self._num = 6
36  return
37 
38 
39  def onInitialize(self):
40  self._tk_data = RTC.TimedFloatSeq(RTC.Time(0,0), [])
41  self._tkIn = OpenRTM_aist.InPort("vel", self._tk_data)
42 
43  self.addInPort("vel", self._tkIn)
44  return RTC.RTC_OK
45 
46  def onActivated(self, ec_id):
47  val = [self._cnt] * self._num
48  tkm.set_angle(val)
49  time.sleep(0.01)
50  self._cnt += 1
51  self._v = [0] * 6
52  return RTC.RTC_OK
53 
54 
55  def onExecute(self, ec_id):
56  try:
57  indata = self._tkIn.read()
58  val = indata.data
59  print val
60  if len(val) == 6:
61  for i in range(6):
62  self._v[i] += val[i] / 2
63  tkm.set_angle(self._v)
64  except:
65  print "Exception cought in onExecute()"
66 
67  time.sleep(0.01)
68  return RTC.RTC_OK
69 
70 
71  def onShutdown(self, ec_id):
72  tkm.quit()
73  return RTC.RTC_OK
74 
75 
76 
77 def TkMotorCompInit(manager):
78  profile = OpenRTM_aist.Properties(defaults_str=mod_spec)
79  manager.registerFactory(profile,
80  TkMotorComp,
81  OpenRTM_aist.Delete)
82 
83 
84 def MyModuleInit(manager):
85  TkMotorCompInit(manager)
86 
87  # Create a component
88  comp = manager.createComponent("TkMotorComp")
89 
90  print "Componet created"
91 
92 
93 def main():
94  # Initialize manager
95  mgr = OpenRTM_aist.Manager.init(sys.argv)
96 
97  # Set module initialization proceduer
98  # This procedure will be invoked in activateManager() function.
99  mgr.setModuleInitProc(MyModuleInit)
100 
101  # Activate manager and register to naming service
102  mgr.activateManager()
103 
104  # run the manager in blocking mode
105  # runManager(False) is the default
106  #mgr.runManager()
107 
108  # If you want to run the manager in non-blocking mode, do like this
109  mgr.runManager(True)
110  tkm.mainloop()
111 
112 if __name__ == "__main__":
113  main()
The Properties class represents a persistent set of properties.
Definition: Properties.py:83
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 Mon Feb 28 2022 23:01:07