예제 #1
0
def do_ecto():
    #Set up the ecto_ros subscribers, with a dict of output name -> subscriber cell
    subs = dict(image=ImageSub(topic_name='image',queue_size=0),
                depth=ImageSub(topic_name='depth',queue_size=0),
                )
    #The synchronizer expects this dict, and will have an output foreach key:value pair
    sync = ecto_ros.Synchronizer('Synchronizator', subs=subs)

    #some rosmsg ~> opencv type converters
    rgb = ecto_ros.Image2Mat()
    depth = ecto_ros.Image2Mat()

    #declare a graph that just shows the images using opencv highgui
    graph = [
                sync["image"] >> rgb["image"],
                sync["depth"] >> depth["image"],
                rgb["image"] >> imshow(name="rgb")["image"],
                depth["image"] >> imshow(name="depth")["image"]
            ]

    #add the graph to our ecto plasm
    plasm = ecto.Plasm()
    plasm.connect(graph)

    #We'll use a threadpool based scheduler to execute this one.
    sched = ecto.Scheduler(plasm)
    sched.execute() #execute forever
예제 #2
0
 def handle_look(self, req):
     print("in look service call back")
     self.sched = ecto.Scheduler(self.lookPlasm)
     lock.acquire()
     self.keepRun = self.sched.execute(niter=1)
     lock.release()
     return LookResponse(0)
예제 #3
0
 def handle_load(self, req):
     print "file name = ", req.fileName
     self.sched = ecto.Scheduler(self.loadPlasm)
     lock.acquire()
     self.sched.execute(niter=1)
     lock.release()
     return LoadPCLResponse(0)
예제 #4
0
 def __init__(self, plasm, parent=None):
     super(DynamicReconfigureForm, self).__init__(parent)
     self.plasm = plasm
     self.setWindowTitle("Dynamic Reconfigure")
     plasm.configure_all()
     self.generate_dialogs()
     self.sched = ecto.Scheduler(plasm)
예제 #5
0
def do_ecto(bag_name):
    baggers = dict(
        image=ImageBagger(topic_name='/camera/rgb/image_mono'),
        depth=ImageBagger(topic_name='/camera/depth/image_raw'),
    )

    bagwriter = ecto_ros.BagWriter(
        'Bag Writer',
        baggers=baggers,
        bag=bag_name,
    )
    subs = dict(
        image=ImageSub(topic_name='/camera/rgb/image_mono', queue_size=0),
        depth=ImageSub(topic_name='/camera/depth/image_raw', queue_size=0),
    )

    sync = ecto_ros.Synchronizer('Synchronizator', subs=subs)

    im2mat_rgb = ecto_ros.Image2Mat()
    im2mat_depth = ecto_ros.Image2Mat()

    graph = [
        sync["image"] >> im2mat_rgb["image"],
        im2mat_rgb["image"] >> highgui.imshow("rgb show", name="rgb")[:],
        sync[:] >> bagwriter[:], sync["depth"] >> im2mat_depth["image"],
        im2mat_depth["image"] >> highgui.imshow("depth show", name="depth")[:]
    ]
    plasm = ecto.Plasm()
    plasm.connect(graph)
    ecto.view_plasm(plasm)

    sched = ecto.Scheduler(plasm)
    sched.execute(niter=30)  # capture a second.
예제 #6
0
def do_ecto():
    baggers = dict(image=ImageBagger(topic_name='/camera/rgb/image_color'),
                   depth=ImageBagger(topic_name='/camera/depth/image'),
                   )

    bagreader = ecto_ros.BagReader('Bag Ripper',
                                    baggers=baggers,
                                    bag=sys.argv[1],
                                  )
    im2mat_rgb = ecto_ros.Image2Mat()
    im2mat_depth = ecto_ros.Image2Mat()

    graph = [
                bagreader["image"] >> im2mat_rgb["image"],
                im2mat_rgb["image"] >> highgui.imshow("rgb show", name="rgb")[:],
                bagreader["depth"] >> im2mat_depth["image"],
                im2mat_depth["image"] >> highgui.imshow("depth show", name="depth")[:]
            ]

    plasm = ecto.Plasm()
    plasm.connect(graph)
    ecto.view_plasm(plasm)

    sched = ecto.Scheduler(plasm)
    sched.execute()
예제 #7
0
def stoppable():
    def makeplasm():
        plasm = ecto.Plasm()
        ping = ecto_test.Ping("Ping")
        sleeps = [ecto_test.Sleep("Sleep_0", seconds=0.1) for x in range(20)]
        plasm.connect(ping[:] >> sleeps[0][:])
        for i in range(1, 19):
            print "i=", i
            plasm.connect(sleeps[i][:] >> sleeps[i + 1][:])
        return plasm

    p = makeplasm()

    st = ecto.Scheduler(p)
    assert not st.running()
    start = time.time()
    st.execute(1)
    elapsed = time.time() - start
    print "elapsed Scheduler:", elapsed
    assert elapsed > 2.0
    assert elapsed < 2.1
    assert st.running()

    start = time.time()
    st.execute_async(1)
    st.run()
    elapsed = time.time() - start
    print "elapsed Scheduler:", elapsed
    assert elapsed > 2.0
    assert elapsed < 2.1
예제 #8
0
def app():
    cd = ClusterDetector(n=20)
    cp = ClusterPrinter()
    plasm = ecto.Plasm()
    plasm.connect(cd['clusters'] >> cp['clusters'])
    sched = ecto.Scheduler(plasm)
    sched.execute(niter=3)
예제 #9
0
def scope():
    p = Printer(print_type='double')
    sink = Sink(url='localhost', port=2932)

    plasm2 = ecto.Plasm()
    plasm2.connect(sink[:] >> p[:])
    sched2 = ecto.Scheduler(plasm2)
    sched2.execute(10)
예제 #10
0
 def handle_clean(self, req):
     print "cleannig point cloude"
     self.pclFunsion.params.clean = True
     self.sched = ecto.Scheduler(self.cleanPlasm)
     lock.acquire()
     self.keepRun = self.sched.execute(niter=1)
     lock.release()
     self.pclFunsion.params.clean = False
     return CleanPCLResponse(0)
예제 #11
0
def test_tp(niter, n_nodes):

    (plasm, metrics) = makeplasm(n_nodes)

    sched = ecto.Scheduler(plasm)
    sched.execute(niter=niter)
    print "Hz:", metrics.outputs.hz, " Latency in seconds:", metrics.outputs.latency_seconds
    assert n_nodes * 0.95 < metrics.outputs.hz < n_nodes * 1.05
    assert 0.9 < metrics.outputs.latency_seconds < 1.1
예제 #12
0
def do_one_st(N):
    print "multithreaded test w/ quit after", N
    (gen, plasm) = makeplasm(N)

    sched = ecto.Scheduler(plasm)
    sched.execute(niter=N + 100)

    print "singlethreaded: actual out:", gen.outputs.out, " N:", N
    assert N == gen.outputs.out
    print "\n" * 5
예제 #13
0
 def __init__(self, plasm_dict={}, disable_qt_management=False):
     self.plasms = plasm_dict
     self.schedulers = {}
     self.threads = {}
     for plasm_name in self.plasms:
         self.schedulers[plasm_name] = ecto.Scheduler(self.plasms[plasm_name])
         self.threads[plasm_name] = threading.Thread(name=plasm_name, target=self.schedulers[plasm_name].execute)
     self.disable_qt_management = disable_qt_management
     self.timer = None if disable_qt_management else QTimer()
     self.counter = 0
예제 #14
0
 def handle_save(self, req):
     print("saving pcl to pcd file")
     print("file name = ", req.fileName)
     self.pclFunsion.params.save = True
     self.sched = ecto.Scheduler(self.savePlasm)
     lock.acquire()
     self.keepRun = self.sched.execute(niter=1)
     lock.release()
     self.pclFunsion.params.save = False
     return SavePCLResponse(0)
예제 #15
0
def test_tp(niter, n_nodes):
    (plasm, metrics) = makeplasm(n_nodes)

    sched = ecto.Scheduler(plasm)
    sched.execute(niter=niter)
    print "Hz:", metrics.outputs.hz, " Latency in seconds:", metrics.outputs.latency_seconds
    # FIXME: (JTF) This assert doesn't seem right - changing it for now.
    #assert n_nodes * 0.95 < metrics.outputs.hz < n_nodes * 1.05
    assert 0.95 < metrics.outputs.hz < 1.05
    assert 0.9 < metrics.outputs.latency_seconds < 1.1
예제 #16
0
def test_nodelay():
    plasm = ecto.Plasm()

    ping = ecto_test.Ping("Ping")
    metrics = ecto_test.Metrics("Metrics", queue_size=10)
    plasm.connect(ping[:] >> metrics[:])

    sched = ecto.Scheduler(plasm)
    sched.execute(niter=10000)
    print "Hz:", metrics.outputs.hz, " Latency in seconds: %f" % metrics.outputs.latency_seconds

    # these are kinda loose
    assert metrics.outputs.hz > 5000
    assert metrics.outputs.latency_seconds < 0.0001
예제 #17
0
    def handle_look(self, req):
        self.regionFilter.params.minX = -0.40
        self.regionFilter.params.maxX = 0.1
        self.regionFilter.params.minY = -0.15
        self.regionFilter.params.maxY = 1
        self.regionFilter.params.minZ = 0
        self.regionFilter.params.maxZ = 2.1

        print("in look service call back")
        self.sched = ecto.Scheduler(self.lookPlasm)
        lock.acquire()
        self.keepRun = self.sched.execute(niter=1)
        lock.release()
        return LookResponse(0)
예제 #18
0
파일: test_async.py 프로젝트: imclab/ecto
def test_async_stop_on_destructor():
    generate = ecto_test.Generate()
    param_watcher = ecto_test.ParameterWatcher(value=2)
    sleep = ecto_test.Sleep()
    printer = ecto_test.Printer()
    plasm = ecto.Plasm()
    plasm.connect(generate["out"] >> param_watcher["input"],
                  param_watcher['output'] >> printer[:])
    plasm.insert(sleep)
    #ecto.view_plasm(plasm)
    sched = ecto.Scheduler(plasm)
    sched.execute_async()
    for i in range(0, 10):
        sched.run_job()
예제 #19
0
    def __init__(self, ecto_plasm, ecto_cells):
        self.ecto_plasm = ecto_plasm
        self.ecto_cells = ecto_cells
        self.ecto_scheduler = ecto.Scheduler(self.ecto_plasm)
        self.outputgraph = None
        self.found_objects = None

        rospy.Subscriber('geometry_graph', Graph,
                         self.callback_vision_result_graph)
        rospy.loginfo('Subscribed to the geometry_graph topic.')

        rospy.Subscriber('objects', ObjectList,
                         self.callback_vision_result_objects)
        rospy.loginfo('Subscribed to the objects topic.')
예제 #20
0
def do_ecto(device_id=0, frame_id='base'):
    video_capture = highgui.VideoCapture('Video Camera',
                                         video_device=device_id)
    mat2image = ecto_ros.Mat2Image(frame_id=frame_id, encoding='bgr8')
    pub_rgb = ImagePub("image pub", topic_name='image')

    graph = [
        video_capture["image"] >> mat2image["image"],
        mat2image["image"] >> pub_rgb["input"]
    ]

    plasm = ecto.Plasm()
    plasm.connect(graph)
    sched = ecto.Scheduler(plasm)
    sched.execute()
예제 #21
0
def test_20hz():
    plasm = ecto.Plasm()

    ping = ecto_test.Ping("Ping")
    throttle = ecto_test.Throttle("Throttle", rate=20)
    metrics = ecto_test.Metrics("Metrics", queue_size=10)
    plasm.connect(ping[:] >> throttle[:], throttle[:] >> metrics[:])

    sched = ecto.Scheduler(plasm)
    sched.execute(niter=100)
    print "Hz:", metrics.outputs.hz, " Latency in seconds: %f" % metrics.outputs.latency_seconds

    # these are kinda loose
    assert 19 < metrics.outputs.hz < 21
    assert 0.04 < metrics.outputs.latency_seconds < 0.06
예제 #22
0
def test_circular():
    a1 = ecto_test.Add()
    a2 = ecto_test.Add()
    p = ecto.Plasm()
    p.connect(a1['out'] >> a2['left'],
              a2['out'] >> a1['right']
              )

    sched = ecto.Scheduler(p)
    try:
        sched.execute(niter=1)
        fail("that should have thrown")
    except ecto.EctoException as e: # Thrown when Lumberg's "BFS" is used.
        print "okay, threw"
    except ValueError as e: # Thrown when boost::topological_sort() is used.
        print "okay, threw"
예제 #23
0
        def __init__(self, plasm, whitelist=None, parent=None):
            '''
            Accepts a plasm for connecting tendrils to a frontend widget. Also
            takes an optional whitelist parameter so that you can selectively
            decide which parameters are for show.

            :param Plasm ecto.Plasm: live squelchy thing that contains the configuration of your system locked in its parameter tendrils.
            :param whitelist dic: dictionary of {cell name: [tendril_name]} to show
            '''
            super(DynamicReconfigureForm, self).__init__(parent)
            self.plasm = plasm
            self.whitelist = whitelist
            self.setWindowTitle("Dynamic Reconfigure")
            plasm.configure_all()
            self.generate_dialogs()
            self.sched = ecto.Scheduler(plasm)
예제 #24
0
파일: test_async.py 프로젝트: imclab/ecto
def test_parameter_callbacks():
    generate = ecto_test.Generate()
    param_watcher = ecto_test.ParameterWatcher(value=2)
    sleep = ecto_test.Sleep()
    printer = ecto_test.Printer()
    plasm = ecto.Plasm()
    plasm.connect(generate["out"] >> param_watcher["input"],
                  param_watcher['output'] >> printer[:])
    plasm.insert(sleep)
    #ecto.view_plasm(plasm)
    sched = ecto.Scheduler(plasm)
    sched.execute_async(1)
    sched.run_job()  # check plasm, init parms, and compute_stack
    number = 1000
    param_watcher.params.value = number
    sched.run()

    assert 1000 == param_watcher.outputs.value
예제 #25
0
def test_parameter_callbacks():
    generate = ecto_test.Generate()
    handle_holder = ecto_test.HandleHolder(value=2)
    plasm = ecto.Plasm()
    plasm.connect(generate, "out", handle_holder, "input")

    sched = ecto.Scheduler(plasm)
    for i in range(0, 5):
        value = handle_holder.params.value * (i + 1)
        handle_holder.params.value = value
        print "execute..."
        sched.execute(niter=1)
        print "parameter:", handle_holder.outputs.value

    result = handle_holder.outputs.output
    print result
    assert handle_holder.outputs.value == 240
    assert handle_holder.outputs.output == 1920
예제 #26
0
def test_one_to_many():
    plasm = ecto.Plasm()
    g = ecto_test.Generate(start=2, step=2)
    modules = []
    for x in range(0,5):
        m = ecto_test.Multiply(factor=2)
        plasm.connect(g,"out",m,"in")
        modules.append(m)
        
    sched = ecto.Scheduler(plasm)
    sched.execute(niter=1)
    for x in modules:
        #print x.outputs.out
        assert(x.outputs.out == 4)
    sched.execute(niter=1)
    for x in modules:
        #print x.outputs.out
        assert(x.outputs.out == 8)
예제 #27
0
def doit():
    print "**** pre import of ecto_lifecycle ********"
    import ecto.ecto_lifecycle as ecto_lifecycle
    print "**** post import of ecto_lifecycle *******"

    print "**** pre allocation of LifeCycle cell ********"
    lifecycle = ecto_lifecycle.LifeCycle() #allocate a cell
    print "**** post allocation of LifeCycle cell *******"

    plasm = ecto.Plasm()
    print "**** pre insert ********"
    plasm.insert(lifecycle)
    print "**** post insert *******"

    print "**** pre execute ********"
    sched = ecto.Scheduler(plasm)
    sched.execute(1)
    print "**** post execute *******"
예제 #28
0
def do_ecto():
    sub_rgb = ImageSub("image_sub",topic_name='/camera/rgb/image_mono')
    sub_depth = ImageSub("depth_sub",topic_name='/camera/depth/image')
    pub_rgb = ImagePub("image_pub", topic_name='my_image')
    pub_depth = ImagePub("depth_pub", topic_name='my_depth')

    graph = [
                sub_rgb["output"] >> pub_rgb["input"],
                sub_depth["output"] >> pub_depth["input"]
            ]

    plasm = ecto.Plasm()
    plasm.connect(graph)

    ecto.view_plasm(plasm)

    sched = ecto.Scheduler(plasm)
    sched.execute()
예제 #29
0
def do_ecto():
    sub_rgb = ImageSub("image_sub", topic_name='/camera/rgb/image_mono')
    sub_depth = ImageSub("depth_sub", topic_name='/camera/depth/image')

    im2mat_rgb = ecto_ros.Image2Mat()
    im2mat_depth = ecto_ros.Image2Mat()

    graph = [
        sub_rgb["output"] >> im2mat_rgb["image"],
        im2mat_rgb["image"] >> highgui.imshow("rgb show", name="rgb")[:],
        sub_depth["output"] >> im2mat_depth["image"],
        im2mat_depth["image"] >> highgui.imshow("depth show", name="depth")[:]
    ]
    plasm = ecto.Plasm()
    plasm.connect(graph)
    ecto.view_plasm(plasm)

    sched = ecto.Scheduler(plasm)
    sched.execute()
예제 #30
0
def test_plasm():
    plasm = ecto.Plasm()
    sps = []
    for i in range(0, 7):
        sps.append(ecto_test.SharedPass(x=i))

    plasm.connect(sps[6], "output", sps[1], "input")
    plasm.connect(sps[1], "output", sps[2], "input")
    plasm.connect(sps[6], "output", sps[0], "input")
    plasm.connect(sps[0], "output", sps[4], "input")
    plasm.connect(sps[4], "output", sps[5], "input")

    sched = ecto.Scheduler(plasm)
    sched.execute(niter=1)
    #ecto.view_plasm(plasm)

    print sps[2].outputs.value
    assert sps[2].outputs.value == 6
    assert sps[4].outputs.value == 6
    assert sps[6].outputs.value == 6