Connector.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 # -*- Python -*-
00004 
00005 import sys
00006 
00007 from omniORB import CORBA
00008 
00009 import RTC
00010 import OpenRTM
00011 import OpenRTM_aist
00012 
00013 
00014 def main():
00015 
00016   # subscription type
00017   subs_type = "Flush"
00018 
00019   # initialization of ORB
00020   orb = CORBA.ORB_init(sys.argv)
00021 
00022   # get NamingService
00023   naming = OpenRTM_aist.CorbaNaming(orb, "localhost")
00024     
00025   conin = OpenRTM_aist.CorbaConsumer()
00026   conout = OpenRTM_aist.CorbaConsumer()
00027 
00028   ec0 = OpenRTM_aist.CorbaConsumer(interfaceType=OpenRTM.ExtTrigExecutionContextService)
00029   ec1 = OpenRTM_aist.CorbaConsumer(interfaceType=OpenRTM.ExtTrigExecutionContextService)
00030 
00031   # find ConsoleIn0 component
00032   conin.setObject(naming.resolve("ConsoleIn0.rtc"))
00033 
00034   # get ports
00035   inobj = conin.getObject()._narrow(RTC.RTObject)
00036   pin = inobj.get_ports()
00037   pin[0].disconnect_all()
00038 
00039   # activate ConsoleIn0
00040   eclisti = inobj.get_owned_contexts()
00041   eclisti[0].activate_component(inobj)
00042   ec0.setObject(eclisti[0])
00043 
00044 
00045   # find ConsoleOut0 component
00046   conout.setObject(naming.resolve("ConsoleOut0.rtc"))
00047 
00048   # get ports
00049   outobj = conout.getObject()._narrow(RTC.RTObject)
00050   pout = outobj.get_ports()
00051   pout[0].disconnect_all()
00052   
00053   # activate ConsoleOut0
00054   eclisto = outobj.get_owned_contexts()
00055   eclisto[0].activate_component(outobj)
00056   ec1.setObject(eclisto[0])
00057 
00058 
00059   # connect ports
00060   conprof = RTC.ConnectorProfile("connector0", "", [pin[0],pout[0]], [])
00061   OpenRTM_aist.CORBA_SeqUtil.push_back(conprof.properties,
00062                                        OpenRTM_aist.NVUtil.newNV("dataport.interface_type",
00063                                                                  "corba_cdr"))
00064 
00065   OpenRTM_aist.CORBA_SeqUtil.push_back(conprof.properties,
00066                                        OpenRTM_aist.NVUtil.newNV("dataport.dataflow_type",
00067                                                                  "push"))
00068 
00069   OpenRTM_aist.CORBA_SeqUtil.push_back(conprof.properties,
00070                                        OpenRTM_aist.NVUtil.newNV("dataport.subscription_type",
00071                                                                  subs_type))
00072 
00073   ret = pin[0].connect(conprof)
00074 
00075     
00076   while 1:
00077     try:
00078       print "\n\n"
00079       print "0: tick ConsoleIn component"
00080       print "1: tick ConsoleOut component"
00081       print "2: tick both components"
00082       print "q: exit"
00083       print "cmd? >",
00084       cmd = str(sys.stdin.readline())
00085       if cmd == "0\n":
00086         ec0._ptr().tick()
00087       elif cmd == "1\n":
00088         ec1._ptr().tick()
00089       elif cmd == "2\n":
00090         ec0._ptr().tick()
00091         ec1._ptr().tick()
00092       elif cmd == "q\n":
00093         print "exit"
00094         break
00095                 
00096     except:
00097       print "Exception."
00098       pass
00099 
00100 if __name__ == "__main__":
00101   main()


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