TkMotorPosComp.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", "TkMotorPosComp",
16  "type_name", "TkMotorPosComp",
17  "description", "Tk Motor component (position 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("pos", self._tk_data)
42 
43  self.addInPort("pos", self._tkIn)
44  return RTC.RTC_OK
45 
46 
47  def onActivated(self, ec_id):
48  val = [self._cnt] * self._num
49  tkm.set_angle(val)
50  time.sleep(0.01)
51  self._cnt += 1
52  self._v = [0] * 6
53  return RTC.RTC_OK
54 
55 
56  def onExecute(self, ec_id):
57  try:
58  indata = self._tkIn.read()
59  val = indata.data
60  print val
61  if len(val) == 6:
62  for i in range(6):
63  self._v[i] = val[i] * 10
64  tkm.set_angle(self._v)
65  except:
66  print "Exception cought in onExecute()"
67 
68  time.sleep(0.01)
69  return RTC.RTC_OK
70 
71 
72  def onShutdown(self, ec_id):
73  tkm.quit()
74  return RTC.RTC_OK
75 
76 
77 
78 def TkMotorPosCompInit(manager):
79  profile = OpenRTM_aist.Properties(defaults_str=mod_spec)
80  manager.registerFactory(profile,
81  TkMotorPosComp,
82  OpenRTM_aist.Delete)
83 
84 def MyModuleInit(manager):
85  TkMotorPosCompInit(manager)
86 
87  # Create a component
88  comp = manager.createComponent("TkMotorPosComp")
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