SliderComp.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 import slider
13 
14 
15 channels = (
16  ("motor0", -360, 360, 0.1, 200),
17  ("motor1", -360, 360, 0.1, 200),
18  ("motor2", -360, 360, 0.1, 200),
19  ("motor3", -360, 360, 0.1, 200),
20  ("motor4", -360, 360, 0.1, 200),
21  ("motor5", -360, 360, 0.1, 200))
22 
23 mod_spec = ["implementation_id", "SliderComp",
24  "type_name", "SliderComp",
25  "description", "slider component",
26  "version", "1.0",
27  "vendor", "Noriaki Ando and Shinji Kurihara",
28  "category", "Generic",
29  "activity_type", "DataFlowComponent",
30  "max_instance", "10",
31  "language", "Python",
32  "lang_type""SCRIPT",
33  ""]
34 
35 sl = slider.SliderMulti(channels)
36 # thread.start_new_thread(sl.mainloop, ())
37 
39  def __init__(self, manager):
40  OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
41  return
42 
43 
44  def onInitialize(self):
45  self._sl_data = RTC.TimedFloatSeq(RTC.Time(0,0), [])
46  self._slOut = OpenRTM_aist.OutPort("slider", self._sl_data)
47 
48  self.addOutPort("slider", self._slOut)
49  return RTC.RTC_OK
50 
51  def onActivated(self, ec_id):
52  print sl.get()
53  time.sleep(1)
54  return RTC.RTC_OK
55 
56 
57  def onExecute(self, ec_id):
58  self._sl_data.data = sl.get()
59  self._slOut.write()
60  time.sleep(0.01)
61  return RTC.RTC_OK
62 
63 
64  def onShutdown(self, ec_id):
65  sl.quit()
66  return RTC.RTC_OK
67 
68 
69 
70 def SliderCompInit(manager):
71  profile = OpenRTM_aist.Properties(defaults_str=mod_spec)
72  manager.registerFactory(profile,
73  SliderComp,
74  OpenRTM_aist.Delete)
75 
76 def MyModuleInit(manager):
77  SliderCompInit(manager)
78 
79  # Create a component
80  comp = manager.createComponent("SliderComp")
81 
82  print "Componet created"
83 
84 
85 def main():
86  # Initialize manager
87  mgr = OpenRTM_aist.Manager.init(sys.argv)
88 
89  # Set module initialization proceduer
90  # This procedure will be invoked in activateManager() function.
91  mgr.setModuleInitProc(MyModuleInit)
92 
93  # Activate manager and register to naming service
94  mgr.activateManager()
95 
96  # run the manager in blocking mode
97  # runManager(False) is the default
98  #mgr.runManager()
99 
100  # If you want to run the manager in non-blocking mode, do like this
101  mgr.runManager(True)
102  sl.mainloop()
103 
104 if __name__ == "__main__":
105  main()
The Properties class represents a persistent set of properties.
Definition: Properties.py:83
def addOutPort(self, name, outport)
Definition: RTObject.py:2765


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Mon Feb 28 2022 23:01:06