ExtTrigger/Connector.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # -*- Python -*-
4 
5 import sys
6 
7 from omniORB import CORBA
8 
9 import RTC
10 import OpenRTM
11 import OpenRTM_aist
12 
13 
14 def main():
15 
16  # subscription type
17  subs_type = "Flush"
18 
19  # initialization of ORB
20  orb = CORBA.ORB_init(sys.argv)
21 
22  # get NamingService
23  naming = OpenRTM_aist.CorbaNaming(orb, "localhost")
24 
27 
28  ec0 = OpenRTM_aist.CorbaConsumer(interfaceType=OpenRTM.ExtTrigExecutionContextService)
29  ec1 = OpenRTM_aist.CorbaConsumer(interfaceType=OpenRTM.ExtTrigExecutionContextService)
30 
31  # find ConsoleIn0 component
32  conin.setObject(naming.resolve("ConsoleIn0.rtc"))
33 
34  # get ports
35  inobj = conin.getObject()._narrow(RTC.RTObject)
36  pin = inobj.get_ports()
37  pin[0].disconnect_all()
38 
39  # activate ConsoleIn0
40  eclisti = inobj.get_owned_contexts()
41  eclisti[0].activate_component(inobj)
42  ec0.setObject(eclisti[0])
43 
44 
45  # find ConsoleOut0 component
46  conout.setObject(naming.resolve("ConsoleOut0.rtc"))
47 
48  # get ports
49  outobj = conout.getObject()._narrow(RTC.RTObject)
50  pout = outobj.get_ports()
51  pout[0].disconnect_all()
52 
53  # activate ConsoleOut0
54  eclisto = outobj.get_owned_contexts()
55  eclisto[0].activate_component(outobj)
56  ec1.setObject(eclisto[0])
57 
58 
59  # connect ports
60  conprof = RTC.ConnectorProfile("connector0", "", [pin[0],pout[0]], [])
61  OpenRTM_aist.CORBA_SeqUtil.push_back(conprof.properties,
62  OpenRTM_aist.NVUtil.newNV("dataport.interface_type",
63  "corba_cdr"))
64 
65  OpenRTM_aist.CORBA_SeqUtil.push_back(conprof.properties,
66  OpenRTM_aist.NVUtil.newNV("dataport.dataflow_type",
67  "push"))
68 
69  OpenRTM_aist.CORBA_SeqUtil.push_back(conprof.properties,
70  OpenRTM_aist.NVUtil.newNV("dataport.subscription_type",
71  subs_type))
72 
73  ret = pin[0].connect(conprof)
74 
75 
76  while 1:
77  try:
78  print "\n\n"
79  print "0: tick ConsoleIn component"
80  print "1: tick ConsoleOut component"
81  print "2: tick both components"
82  print "q: exit"
83  print "cmd? >",
84  cmd = str(sys.stdin.readline())
85  if cmd == "0\n":
86  ec0._ptr().tick()
87  elif cmd == "1\n":
88  ec1._ptr().tick()
89  elif cmd == "2\n":
90  ec0._ptr().tick()
91  ec1._ptr().tick()
92  elif cmd == "q\n":
93  print "exit"
94  break
95 
96  except:
97  print "Exception."
98  pass
99 
100 if __name__ == "__main__":
101  main()
def push_back(seq, elem)
Push the new element back to the CORBA sequence.
CORBA Naming Service helper class.
Definition: CorbaNaming.py:61
def newNV(name, value)
Create NameVale.
Definition: NVUtil.py:50


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