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 from . 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()
OpenRTM_aist.examples.Slider_and_Motor.TkMotorPosComp.main
def main()
Definition: TkMotorPosComp.py:93
OpenRTM_aist.examples.Slider_and_Motor.tkmotor.TkMotor
Definition: tkmotor.py:10
OpenRTM_aist.examples.Slider_and_Motor.TkMotorPosComp.TkMotorPosComp.onActivated
def onActivated(self, ec_id)
Definition: TkMotorPosComp.py:47
OpenRTM_aist.examples.Slider_and_Motor.TkMotorPosComp.TkMotorPosComp.onShutdown
def onShutdown(self, ec_id)
Definition: TkMotorPosComp.py:72
OpenRTM_aist.examples.Slider_and_Motor.TkMotorPosComp.TkMotorPosComp._tkIn
_tkIn
Definition: TkMotorPosComp.py:41
OpenRTM_aist.examples.Slider_and_Motor.TkMotorPosComp.TkMotorPosComp.onInitialize
def onInitialize(self)
Definition: TkMotorPosComp.py:39
OpenRTM_aist.DataFlowComponentBase.DataFlowComponentBase
DataFlowComponentBase class.
Definition: DataFlowComponentBase.py:35
OpenRTM_aist.examples.Slider_and_Motor.TkMotorPosComp.TkMotorPosComp._num
_num
Definition: TkMotorPosComp.py:35
OpenRTM_aist.examples.Slider_and_Motor.TkMotorPosComp.TkMotorPosComp
Definition: TkMotorPosComp.py:31
OpenRTM_aist.examples.Slider_and_Motor.TkMotorPosComp.TkMotorPosComp._v
_v
Definition: TkMotorPosComp.py:52
OpenRTM_aist.examples.Slider_and_Motor.TkMotorPosComp.TkMotorPosComp._cnt
_cnt
Definition: TkMotorPosComp.py:34
OpenRTM_aist.examples.Slider_and_Motor.TkMotorPosComp.TkMotorPosComp._tk_data
_tk_data
Definition: TkMotorPosComp.py:40
OpenRTM_aist.InPort.InPort
InPort template class.
Definition: InPort.py:58
OpenRTM_aist.examples.Slider_and_Motor.TkMotorPosComp.TkMotorPosCompInit
def TkMotorPosCompInit(manager)
Definition: TkMotorPosComp.py:78
OpenRTM_aist.examples.Slider_and_Motor.TkMotorPosComp.MyModuleInit
def MyModuleInit(manager)
Definition: TkMotorPosComp.py:84
OpenRTM_aist.examples.Slider_and_Motor.TkMotorPosComp.TkMotorPosComp.onExecute
def onExecute(self, ec_id)
Definition: TkMotorPosComp.py:56
OpenRTM_aist.Properties.Properties
Definition: Properties.py:83
OpenRTM_aist.examples.Slider_and_Motor.TkMotorPosComp.TkMotorPosComp.__init__
def __init__(self, manager)
Constructor.
Definition: TkMotorPosComp.py:32
OpenRTM_aist.RTObject.RTObject_impl.addInPort
def addInPort(self, name, inport)
Definition: RTObject.py:2721


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Mon Apr 21 2025 02:45:07