ConfigSample.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 
00008 import RTC
00009 import OpenRTM_aist
00010 
00011 # Module specification
00012 configsample_spec = ["implementation_id", "ConfigSample",
00013                      "type_name",         "ConfigSample",
00014                      "description",       "Configuration example component",
00015                      "version",           "1.0",
00016                      "vendor",            "Shinji Kurihara",
00017                      "category",          "example",
00018                      "activity_type",     "DataFlowComponent",
00019                      "max_instance",      "10",
00020                      "language",          "Python",
00021                      "lang_type",         "script",
00022                      "conf.default.int_param0", "0",
00023                      "conf.default.int_param1", "1",
00024                      "conf.default.double_param0", "0.11",
00025                      "conf.default.double_param1", "9.9",
00026                      "conf.default.str_param0", "hoge",
00027                      "conf.default.str_param1", "dara",
00028                      "conf.default.vector_param0", "0.0,1.0,2.0,3.0,4.0",
00029                      ""]
00030 
00031 i = 0
00032 maxlen = 0
00033 
00034 def ticktack():
00035   global i
00036   str_ = "/-\\|"
00037   i = (i+1) % 4
00038   return str_[i]
00039 
00040 
00041 class ConfigSample(OpenRTM_aist.DataFlowComponentBase):
00042   # class constructor
00043   def __init__(self, manager):
00044     OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
00045     print "ConfigSample constructor."
00046     self._int_param0 = [0]
00047     self._int_param1 = [1]
00048     self._double_param0 = [0.11]
00049     self._double_param1 = [9.9]
00050     self._str_param0 = ["hoge"]
00051     self._str_param1 = ["dara"]
00052     self._vector_param0 = [[0.0, 1.0, 2.0, 3.0, 4.0]]
00053     
00054   # The initialize action (on CREATED->ALIVE transition)
00055   def onInitialize(self):
00056     self.bindParameter("int_param0", self._int_param0, "0")
00057     self.bindParameter("int_param1", self._int_param1, "1")
00058     self.bindParameter("double_param0", self._double_param0, "0.11")
00059     self.bindParameter("double_param1", self._double_param1, "9.9")
00060     self.bindParameter("str_param0", self._str_param0, "hoge")
00061     self.bindParameter("str_param1", self._str_param1, "dara")
00062     self.bindParameter("vector_param0", self._vector_param0, "0.0,1.0,2.0,3.0,4.0")
00063   
00064 
00065     print "\n Please change configuration values from RtcLink"
00066     
00067     return RTC.RTC_OK
00068 
00069   # The execution action that is invoked periodically
00070   def onExecute(self, ec_id):
00071     global maxlen
00072     curlen = 0
00073     c = "                    "
00074 
00075     print "---------------------------------------"
00076     print " Active Configuration Set: ", self._configsets.getActiveId(),c
00077     print "---------------------------------------"
00078     
00079     print "int_param0:       ", self._int_param0, c
00080     print "int_param1:       ", self._int_param1, c
00081     print "double_param0:    ", self._double_param0, c
00082     print "double_param1:    ", self._double_param1, c
00083     print "str_param0:       ", self._str_param0, c
00084     print "str_param1:       ", self._str_param1, c
00085 
00086     for idx in range(len(self._vector_param0[0])):
00087       print "vector_param0[", idx, "]: ", self._vector_param0[0][idx], c
00088 
00089     print "---------------------------------------"
00090 
00091     curlen = len(self._vector_param0[0])
00092 
00093     if maxlen > curlen:
00094       maxlen = maxlen
00095     else:
00096       maxlen = curlen
00097         
00098     for idx in range(maxlen - curlen):
00099       print c, c
00100 
00101     print "Updating.... ", ticktack(), c
00102 
00103     str_ = ""
00104     for idx in range(12 + maxlen):
00105       str_ += "\r"
00106     print str_
00107 
00108 
00109     if self._int_param0 > 1000 and self._int_param0 < 1000000:
00110       time.sleep(self._int_param0/1000000.0)
00111     else:
00112       time.sleep(0.1)
00113 
00114     return RTC.RTC_OK
00115 
00116 
00117 def ConfigSampleInit(manager):
00118   profile = OpenRTM_aist.Properties(defaults_str=configsample_spec)
00119   manager.registerFactory(profile,
00120                           ConfigSample,
00121                           OpenRTM_aist.Delete)
00122 
00123 def MyModuleInit(manager):
00124   ConfigSampleInit(manager)
00125 
00126   # Create a component
00127   comp = manager.createComponent("ConfigSample")
00128 
00129   # Activate component
00130   poa = manager.getPOA()
00131   obj = comp._default_POA().servant_to_reference(comp)
00132   rtobj = obj._narrow(RTC.RTObject)
00133 
00134   ecs = rtobj.get_owned_contexts()
00135   ecs[0].activate_component(rtobj)
00136     
00137 
00138 def main():
00139   # Initialize manager
00140   mgr = OpenRTM_aist.Manager.init(sys.argv)
00141 
00142   # Set module initialization proceduer
00143   # This procedure will be invoked in activateManager() function.
00144   mgr.setModuleInitProc(MyModuleInit)
00145 
00146   # Activate manager and register to naming service
00147   mgr.activateManager()
00148 
00149   # run the manager in blocking mode
00150   # runManager(False) is the default
00151   mgr.runManager()
00152 
00153   # If you want to run the manager in non-blocking mode, do like this
00154   # mgr.runManager(True)
00155 
00156 if __name__ == "__main__":
00157   main()


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