Pressed vs Bumped

I was playing around in NXT-G today and found an interesting fact with the LOOP block.

I set up a loop to play a high note, 1 second break, low note, 1 second break and to loop until touch sensor is pressed. Once the touch sensor is 'pressed' it will break out of the loop and say goodbye.


Now if I press and release the touch sensor when it is playing the low note, by time it has finished the high note, the touch sensor is no longer pressed and the program loops as expected. To paraphrase, because the touch sensor has not been pressed at the exact time the loop block is checked, it continues to loop. This is exactly I as expected.

However, if I change the the loop condition to look for the sensor being 'bumped' (pressed and released) it doesn't matter when in the loop I press the button, it will remember it and once it checks the loop conditions after the high note, it will exit the loop.

This also works for the NXT buttons as inputs but not any of the other sensors.

--
Damien Kee

Comments

Yeah, I remember encountering this while writing my Mayan book. One sure fire way around it is to send a TRUE/FALSE logic value to a variable block (running parallel to main program). That Variable block can be wired to the Loop block that is using Logic as its loop/break decision making. I'm sure there are other methods, too...
Yeah I usually use the method Jim mentioned... my struggles have been to get the program to exit a loop as soon as the condition has been met, instead of continuing to the end of the loop.

-Jonathan
As far as I can tell, that's a limitation of NXT-G... it doesn't seem to let you break a loop midway unless you put a STOP block in there somewhere (maybe in a SWITCH block inside the LOOP block) but that halts the program completely.
David Levy said…
The seems like the expected behavior for pressed and bumped. I believe this was the same in the older rcx touch sensors.
Damien Kee said…
I was more intrigued by the fact that it 'remembered' the bump had occured but didn't 'remember' that the button was pushed.

RoboLab is able to exit a loop at anytime, something I miss in NXT-G
>As far as I can tell, that's a
>limitation of NXT-G

Yeah I know... and like you said, the problem with STOP is that it ends the program. I'd think it would be pretty easy for LEGO to include a "Break" block that would simply exit the loop it's in, and it would be an enormous help in some cases. As for now, I usually end up having to use a really complex solution... most times I try to make everything in the loop happen "instantly" (such as only doing things like modifying variables or turning on motors for unlimited) so that it will exit as soon as the trigger condition is met.

-Jonathan
Anonymous said…
NXT-G is meant for kids, so they can make robots and program them fast. LEGO wanted to keep it easy to use. It is also severely limited in functionality.

As a language it is, to put it kindly, lacking. There a number of other languages out there for the NXT that provide a great deal more functionality. There are both graphical user interfaces such as Robolab, and more standard text base interfaces such as that used by RobotC, etc.

Popular Posts