SliderComp.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 # -*- Python -*-
00004 
00005 import sys
00006 import time
00007 sys.path.append(".")
00008 
00009 import RTC
00010 import OpenRTM_aist
00011 
00012 import slider
00013 
00014 
00015 channels = (
00016   ("motor0", -360, 360, 0.1, 200),
00017   ("motor1", -360, 360, 0.1, 200),
00018   ("motor2", -360, 360, 0.1, 200),
00019   ("motor3", -360, 360, 0.1, 200),
00020   ("motor4", -360, 360, 0.1, 200),
00021   ("motor5", -360, 360, 0.1, 200))
00022 
00023 mod_spec = ["implementation_id", "SliderComp", 
00024             "type_name", "SliderComp", 
00025             "description", "slider component", 
00026             "version", "1.0", 
00027             "vendor", "Noriaki Ando and Shinji Kurihara", 
00028             "category", "Generic", 
00029             "activity_type", "DataFlowComponent", 
00030             "max_instance", "10", 
00031             "language", "Python", 
00032             "lang_type""SCRIPT",
00033             ""]
00034 
00035 sl = slider.SliderMulti(channels)
00036 # thread.start_new_thread(sl.mainloop, ())
00037 
00038 class SliderComp(OpenRTM_aist.DataFlowComponentBase):
00039   def __init__(self, manager):
00040     OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
00041     return
00042         
00043 
00044   def onInitialize(self):
00045     self._sl_data = RTC.TimedFloatSeq(RTC.Time(0,0), [])
00046     self._slOut = OpenRTM_aist.OutPort("slider", self._sl_data)
00047 
00048     self.addOutPort("slider", self._slOut)
00049     return RTC.RTC_OK
00050 
00051   def onActivated(self, ec_id):
00052     print sl.get()
00053     time.sleep(1)
00054     return RTC.RTC_OK
00055 
00056 
00057   def onExecute(self, ec_id):
00058     self._sl_data.data = sl.get()
00059     self._slOut.write()
00060     time.sleep(0.01)
00061     return RTC.RTC_OK
00062 
00063 
00064   def onShutdown(self, ec_id):
00065     sl.quit()
00066     return RTC.RTC_OK
00067 
00068 
00069 
00070 def SliderCompInit(manager):
00071   profile = OpenRTM_aist.Properties(defaults_str=mod_spec)
00072   manager.registerFactory(profile,
00073                           SliderComp,
00074                           OpenRTM_aist.Delete)
00075 
00076 def MyModuleInit(manager):
00077   SliderCompInit(manager)
00078 
00079   # Create a component
00080   comp = manager.createComponent("SliderComp")
00081 
00082   print "Componet created"
00083 
00084 
00085 def main():
00086   # Initialize manager
00087   mgr = OpenRTM_aist.Manager.init(sys.argv)
00088 
00089   # Set module initialization proceduer
00090   # This procedure will be invoked in activateManager() function.
00091   mgr.setModuleInitProc(MyModuleInit)
00092 
00093   # Activate manager and register to naming service
00094   mgr.activateManager()
00095 
00096   # run the manager in blocking mode
00097   # runManager(False) is the default
00098   #mgr.runManager()
00099 
00100   # If you want to run the manager in non-blocking mode, do like this
00101   mgr.runManager(True)
00102   sl.mainloop()
00103 
00104 if __name__ == "__main__":
00105   main()


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Aug 27 2015 14:17:28