I'm making a simple program with LEGO EV3 Education. It makes a little tank to follow a black line over a white-ish floor.

Here it is:

[enter image description here]

This works very smooth: it makes the tank follow the EDGE of the line and substantially takes in account the amount of light the sensor recevies. Black is 11, White is 75: if the light is near 75, then take the power of the B (left) motor higher than the C (right) motor. if the light is near 11, then take the power of C motor higher than B. Otherwise, make C and B power similar.

I want now to add some output on the display, like this:

enter image description here

The idea is: if B power is between C+10 and C-10, then show a forward arrow. else if: if B < C show Right arrow, else Left arrow.

Problem is that, adding this code, the tank doesn't move straight anymore! C and B motor ,on a stright line, alternate power making the robot zig zagging the line.

Why does an output operation on the display affects motors power?


Because it takes time to write to the display. The motor speed cannot be changed until the display blocks have finished and your loop repeats.

Try this instead... create a second loop in parallel to the first that handles the display. You will need a new logic variable to send information from the motor loop to the display loop.

first two loops third loop

  • I tried, same result! What do you mean with "new logic variable"? I used the same "B-Power" and "C-Power" variable that I'm using in the main motor loop Mar 4 '16 at 8:50
  • I have added screenshots to show what I mean. I imagine that it would be better to move the math blocks from the motor loop to the display loop, then you wouldn't need the "Forward" variable. Mar 4 '16 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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