Question

I am developing a robot for an engineering class. For the purposes of the class I am required to use the NXT programming language. To move, the robot needs to follow a solid black line.

If the robot looses the line, I have it scan to the left for 1 second, or until it reaches a black line. If no line is found it scans to the right for 2 seconds so the initial position is reached then 1 more second or rotation is achieved.

I have the loop set up so that if the line has not been found, the robot continues to move. That runs for a full 1 second time period. If the line is found, motion stops, but the full second still has to complete. Ultimately that means that my program works perfectly, but is really really slow.

tl;dr Is there a way to make loops with two exit condition in the LEGO Mindstorm programming environment? Either after 1 second has elapsed, or a sensor gets the desired input?

Was it helpful?

Solution 3

Mindstorms does not have an OR function.

The solution is to create an exit variable, then have two switch statements. In the example above, I had one switch statement with a timer, and the other with the sensor output. Set the exit variable to false, then inside a while loop, run until the exit variable is true.

If the timer expires, set the variable to true, otherwise ignore the exit variable. Do the same with the sensor's output.

This is a messy and rather long solution, but it solves the problem perfectly within the rather limited LEGO Mindstorms system.

OTHER TIPS

The last two blocks are Logic blocks set to "OR". In this case, 3 sensors are being watched. If any one is tripped the program drops out of the loop.

.

This is from page 86 of http://www.hightechkids.org/sites/default/files/CoachingLibrary/fll_programming_101_nxt_g.pdf

What you could do is make the timeout shorter (100 ms for instance) and stop if the line is found OR the loop ran 10 times.

I am no mindstorms expert, but I expect it to have an OR function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top