def declare_cells(_p): """ Implement the virtual function from the base class Only cells from which something is forwarded have to be declared """ cells = {} cells['throttle'] = ecto.TrueEveryN("Throttle", n=1) cells['mat2image'] = ecto_ros.Mat2Image("Mat2Image") cells['subscribed_mat2image'] = ecto.If( "Subscribed Mat2Image", input_tendril_name="has_subscribers", cell=cells['mat2image']) cells['throttled_mat2image'] = ecto.If( "Throttled Mat2Image", input_tendril_name="throttle", cell=cells['subscribed_mat2image']) cells['publisher'] = ecto_sensor_msgs.Publisher_Image( "Publisher", topic_name="/images/candidate_beans", queue_size=2, latched=True) cells['throttled_publisher'] = ecto.If("Throttled Publisher", input_tendril_name="throttle", cell=cells['publisher']) subscribers_input, subscribers_output = \ ecto.EntangledPair(value=cells['throttled_mat2image'].inputs.at('has_subscribers'), source_name="Has Subscribers Input", sink_name="Has Subscribers Output") cells['subscribers_input'] = subscribers_input cells['subscribers_output'] = subscribers_output return cells
def test_If(): plasm = ecto.Plasm() g = ecto_test.Generate("Generator", step=1.0, start=1.0) If = ecto.If(cell=g) truer = ecto.TrueEveryN(n=3, count=3) plasm.connect(truer['flag'] >> If['__test__']) plasm.execute(niter=27) assert g.outputs.out == 9 #should have only called execute 9 times.
def test_nested_if(): plasm = ecto.Plasm() g = ecto_test.Generate("Generator", step=1.0, start=1.0) inside_if = ecto.If(input_tendril_name="on_threes", cell=g) outside_if = ecto.If(input_tendril_name="on_twos", cell=inside_if) truer_on_threes = ecto.TrueEveryN(n=3,count=0) truer_on_twos = ecto.TrueEveryN(n=2,count=0) plasm.connect([ truer_on_threes['flag'] >> outside_if['on_threes'], truer_on_twos['flag'] >> outside_if['on_twos'] ]) #for x in range(0,18): # plasm.execute(niter=1) # print("No of times executed: %s of %s" % (g.outputs.out, x)) # executes on the very first iteration (count = 0) and once every 3*2 iterations thereafter plasm.execute(niter=18) assert g.outputs.out == 3 # should have only called execute 3 times. plasm.execute(niter=1) assert g.outputs.out == 4 # should have executed once more