ConfigSample.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 
8 import RTC
9 import OpenRTM_aist
10 
11 # Module specification
12 configsample_spec = ["implementation_id", "ConfigSample",
13  "type_name", "ConfigSample",
14  "description", "Configuration example component",
15  "version", "1.0",
16  "vendor", "Shinji Kurihara",
17  "category", "example",
18  "activity_type", "DataFlowComponent",
19  "max_instance", "10",
20  "language", "Python",
21  "lang_type", "script",
22  "conf.default.int_param0", "0",
23  "conf.default.int_param1", "1",
24  "conf.default.double_param0", "0.11",
25  "conf.default.double_param1", "9.9",
26  "conf.default.str_param0", "hoge",
27  "conf.default.str_param1", "dara",
28  "conf.default.vector_param0", "0.0,1.0,2.0,3.0,4.0",
29  ""]
30 
31 i = 0
32 maxlen = 0
33 
34 def ticktack():
35  global i
36  str_ = "/-\\|"
37  i = (i+1) % 4
38  return str_[i]
39 
40 
42  # class constructor
43  def __init__(self, manager):
44  OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
45  print "ConfigSample constructor."
46  self._int_param0 = [0]
47  self._int_param1 = [1]
48  self._double_param0 = [0.11]
49  self._double_param1 = [9.9]
50  self._str_param0 = ["hoge"]
51  self._str_param1 = ["dara"]
52  self._vector_param0 = [[0.0, 1.0, 2.0, 3.0, 4.0]]
53 
54  # The initialize action (on CREATED->ALIVE transition)
55  def onInitialize(self):
56  self.bindParameter("int_param0", self._int_param0, "0")
57  self.bindParameter("int_param1", self._int_param1, "1")
58  self.bindParameter("double_param0", self._double_param0, "0.11")
59  self.bindParameter("double_param1", self._double_param1, "9.9")
60  self.bindParameter("str_param0", self._str_param0, "hoge")
61  self.bindParameter("str_param1", self._str_param1, "dara")
62  self.bindParameter("vector_param0", self._vector_param0, "0.0,1.0,2.0,3.0,4.0")
63 
64 
65  print "\n Please change configuration values from RtcLink"
66 
67  return RTC.RTC_OK
68 
69  # The execution action that is invoked periodically
70  def onExecute(self, ec_id):
71  global maxlen
72  curlen = 0
73  c = " "
74 
75  print "---------------------------------------"
76  print " Active Configuration Set: ", self._configsets.getActiveId(),c
77  print "---------------------------------------"
78 
79  print "int_param0: ", self._int_param0, c
80  print "int_param1: ", self._int_param1, c
81  print "double_param0: ", self._double_param0, c
82  print "double_param1: ", self._double_param1, c
83  print "str_param0: ", self._str_param0, c
84  print "str_param1: ", self._str_param1, c
85 
86  for idx in range(len(self._vector_param0[0])):
87  print "vector_param0[", idx, "]: ", self._vector_param0[0][idx], c
88 
89  print "---------------------------------------"
90 
91  curlen = len(self._vector_param0[0])
92 
93  if maxlen > curlen:
94  maxlen = maxlen
95  else:
96  maxlen = curlen
97 
98  for idx in range(maxlen - curlen):
99  print c, c
100 
101  print "Updating.... ", ticktack(), c
102 
103  str_ = ""
104  for idx in range(12 + maxlen):
105  str_ += "\r"
106  print str_
107 
108 
109  if self._int_param0 > 1000 and self._int_param0 < 1000000:
110  time.sleep(self._int_param0/1000000.0)
111  else:
112  time.sleep(0.1)
113 
114  return RTC.RTC_OK
115 
116 
117 def ConfigSampleInit(manager):
118  profile = OpenRTM_aist.Properties(defaults_str=configsample_spec)
119  manager.registerFactory(profile,
120  ConfigSample,
121  OpenRTM_aist.Delete)
122 
123 def MyModuleInit(manager):
124  ConfigSampleInit(manager)
125 
126  # Create a component
127  comp = manager.createComponent("ConfigSample")
128 
129  # Activate component
130  poa = manager.getPOA()
131  obj = comp._default_POA().servant_to_reference(comp)
132  rtobj = obj._narrow(RTC.RTObject)
133 
134  ecs = rtobj.get_owned_contexts()
135  ecs[0].activate_component(rtobj)
136 
137 
138 def main():
139  # Initialize manager
140  mgr = OpenRTM_aist.Manager.init(sys.argv)
141 
142  # Set module initialization proceduer
143  # This procedure will be invoked in activateManager() function.
144  mgr.setModuleInitProc(MyModuleInit)
145 
146  # Activate manager and register to naming service
147  mgr.activateManager()
148 
149  # run the manager in blocking mode
150  # runManager(False) is the default
151  mgr.runManager()
152 
153  # If you want to run the manager in non-blocking mode, do like this
154  # mgr.runManager(True)
155 
156 if __name__ == "__main__":
157  main()
def bindParameter(self, param_name, var, def_val, trans=None)
template <typename vartype>=""> bool bindParameter(const char* param_name, VarType& var...
Definition: RTObject.py:2588
The Properties class represents a persistent set of properties.
Definition: Properties.py:83


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Jun 6 2019 19:11:34