Ejemplo n.º 1
0
def _test_timer_sub_container(controller):

    import pyctrl
    import numpy
    import pyctrl.block as block
    import pyctrl.block.system as system
    import pyctrl.block.random as blkrnd
    import pyctrl.block.container as container

    print('> * * * TEST TIMER SUB CONTAINER {} * * *'.format(
        controller.__class__))

    controller.reset()

    controller.add_signals('s1', 's2', 's3')

    # add subcontainer

    controller.add_timer('container1',
                         container.Container(), ['s1'], ['s2', 's3'],
                         period=1,
                         repeat=False)

    controller.add_signals('timer/container1/s1', 'timer/container1/s2',
                           'timer/container1/s3')

    controller.add_source('timer/container1/input1', container.Input(), ['s1'])

    controller.add_filter('timer/container1/gain1', system.Gain(gain=3),
                          ['s1'], ['s2'])

    controller.add_filter('timer/container1/gain2', system.Gain(gain=5),
                          ['s1'], ['s3'])

    controller.add_sink('timer/container1/output1', container.Output(), ['s2'])

    controller.add_sink('timer/container1/output2', container.Output(), ['s3'])

    assert controller.get_signal('s2') == 0
    assert controller.get_signal('s3') == 0

    with controller:
        controller.set_signal('s1', 1)
        time.sleep(.1)

    assert controller.get_signal('s2') == 0
    assert controller.get_signal('s3') == 0

    with controller:
        controller.set_signal('s1', 1)
        time.sleep(1.5)

    assert controller.get_signal('s2') == 3
    assert controller.get_signal('s3') == 5
Ejemplo n.º 2
0
    def run_test_sub_container_timer(self, controller):

        import pyctrl.block as block
        import pyctrl.block.system as system
        import pyctrl.block.container as container

        print('> * * * TEST SUB CONTAINER TIMER {} * * *'.format(
            controller.__class__))

        controller.reset()

        controller.add_signals('s1', 's2', 's3')

        # add subcontainer

        controller.add_filter('container1', container.Container(), ['s1'],
                              ['s2', 's3'])

        controller.add_signals('container1/s1', 'container1/s2',
                               'container1/s3')

        controller.add_source('container1/input1', container.Input(), ['s1'])

        controller.add_filter('container1/gain1', system.Gain(gain=3), ['s1'],
                              ['s2'])

        controller.add_timer('container1/constant1',
                             block.Constant(value=5),
                             None, ['s3'],
                             period=1,
                             repeat=False)

        controller.add_sink('container1/output1', container.Output(), ['s2'])

        controller.add_sink('container1/output2', container.Output(), ['s3'])

        with controller:
            controller.set_signal('s1', 1)
            time.sleep(.1)

        self.assertTrue(controller.get_signal('s2') == 3)
        self.assertTrue(controller.get_signal('s3') == 0)

        with controller:
            controller.set_signal('s1', 1)
            time.sleep(1.5)

        self.assertTrue(controller.get_signal('s2') == 3)
        self.assertTrue(controller.get_signal('s3') == 5)
Ejemplo n.º 3
0
def _test_sub_container(controller):

    import pyctrl
    import numpy
    import pyctrl.block as block
    import pyctrl.block.system as system
    import pyctrl.block.random as blkrnd
    import pyctrl.block.container as container

    print('> * * * TEST SUB CONTAINER {} * * *'.format(controller.__class__))

    controller.reset()

    # add subcontainer

    controller.add_signals('s1', 's2', 's3')

    controller.add_filter('container1', container.Container(), ['s1'],
                          ['s2', 's3'])

    controller.add_signals('container1/s1', 'container1/s2', 'container1/s3')

    controller.add_source('container1/input1', container.Input(), ['s1'])

    controller.add_filter('container1/gain1', system.Gain(gain=3), ['s1'],
                          ['s2'])

    controller.add_sink('container1/output1', container.Output(), ['s2'])

    controller.set_signal('s2', 0)
    with controller:
        controller.set_signal('s1', 1)
        time.sleep(.2)

    assert controller.get_signal('s2') == 3

    # add subsubcontainer

    controller.add_filter('container1/container2', container.Container(),
                          ['s1'], ['s3'])

    controller.add_signals('container1/container2/s1',
                           'container1/container2/s2')

    controller.add_sink('container1/output2', container.Output(), ['s3'])

    controller.add_source('container1/container2/input1', container.Input(),
                          ['s1'])

    controller.add_filter('container1/container2/gain1', system.Gain(gain=5),
                          ['s1'], ['s2'])

    controller.add_sink('container1/container2/output1', container.Output(),
                        ['s2'])

    controller.set_signal('s2', 0)
    controller.set_signal('s3', 0)
    with controller:
        controller.set_signal('s1', 1)
        time.sleep(.2)

    assert controller.get_signal('s2') == 3
    assert controller.get_signal('s3') == 5