Take the 2-minute tour ×
LEGO® Answers is a question and answer site for LEGO® and building block enthusiasts. It's 100% free, no registration required.

TL;DR = Is there any obvious reason why a MyBlock, added twice in parallel to a program, will only run one of them?


In my EV3-G program, I have a MyBlock which uses the Proximity Heading to control a motor so that the heading is always straight ahead. (It has some added complexity, as it slows down when getting close, etc.)

My robot-arm has two infrared sensors, one mounted horizontally, one mounted vertically, so the arm can always point at the beacon... and the MyBlock has been setup with parameters, so that the corresponding port/motor numbers are passed in.

Is there any reason why two MyBlocks, running in parallel, would only work on one of those blocks, and not the other? (When debugging, both blocks are "shimmering", show they are both apparently running.)

I have double-tripple-quadruple checked that all the flow-control, sensor and actions are working with the correct parameter values, and running each block individually works perfectly.

I have also replicated (at great length) the blocks in brand new programs, and they work without issue.

Why would two blocks running in parallel not work, when the same code replicated on the program does?


UPDATE

As requested (and I should have done originally).

Here is the MyBlock. It starts with 3 parameters, the sensor port, the motor port and an "offset" - all numeric. The loop starts, and a direction heading reading is taken. It then uses the "offset" value, and passes "offet - 5" and "offet + 5" into the range

MyBlock part 1

Based on the boolean value from the range, if the current heading value is within the range, then it runs the motor at a "graded" speed, based on the heading value. Therefore as it gets closer to 0 the slower the motor is run.

MyBlock part 2

If the current heading value is outside the range, then the motor is run at a non-variable speed... in this case if the value is below the "offset" value.

MyBlock part 3

And in this case if the value is above the "offset" value.

MyBlock part 4

The program simply calls two instances of the MyBlock. If I run the left one, the horizontal detection and movement works without issue - if I run the right one, the vertical detection and movement works without issue.

MyBlock part 5 MyBlock part 6

But, if I run the following, only the last MyBlock to be wired works. There is literally movement from just one direction motor.

MyBlock part 7

share|improve this question
    
Please, a screenshot or two. –  dfrevert Jul 20 at 19:33
    
Hi @dfrevert, of course - that is something I should have done up front - apologies. Hope the explanation is clear, please let me know any more clarification is needed –  freefaller Jul 21 at 8:26

1 Answer 1

up vote 3 down vote accepted

I could not find this in the help file, but according to this thread "Another little known characteristic of MyBlocks is that they aren't re-entrant. No two copies of the same MyBlock can be running at the same time."

I tried a few simple programs in EV3-G and confirmed that this is true. The order in which they run appears to be random.

share|improve this answer
    
Well, that would certainly explain it. Nicely found @David, thanks :-) –  freefaller Jul 21 at 19:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.