Page 1 of 1

NXT-G: building a "state machine" problem

Posted: 27 Jan 2012, 18:40
by cfp999
Hi all,

I'm trying to program a robot (NXT 2), that will move around in a zig-zag pattern, search for lego bricks with the lightsensor, while avoiding walls and obstacles. When it locates a brick, a grabbing mechanism will pick up the brick.

To do this, I have tried to implement a "state machine", as described here:

http://www.brickshelf.com/gallery/brdav ... stswap.png

In my program, the top part does all of the movement in a series of sequences controlled
by a text variable - each sequence refering to the next*:

'init' = setting the grabber in the right position
'seek' = move around in a "search & rescue" pattern
'grab' = grab and lift
'avoid' = back off and turn around

* apart form the seek-sequence.

The lower portion/beam, looks for a certain color, sends a stop signal, and sets a new state, 'grab' if it detect something.

Everything is working until the sensor detects a brick. The 'search' is stopped exactly where it should. The colorsensor is set to pause (as it should). But herafter, it seems to hang in the top search loop (the 4 move blocks in the upper part, as seen in the screenshot). At this point "state" is set to 'grab', but it just wont continue after the stop signal is send.

Is there any way around this problem? It seems to me, that sending a stop signal to a move sequence pauses eveything, instead of skipping the rest of the sequence.

Screenshot:

http://www.pixentral.com/show.php?pictu ... 36AgJsdst1

Thanks.

Re: NXT-G: building a "state machine" problem

Posted: 27 Jan 2012, 19:49
by ronmcrae
First of all I want to compliment you on such a well commented program. It's not too often we see that these days!

I think that in NXT-G V1.1 any STOP MOTOR block would indeed cause an active motor block on a separate rung to exit. But I don't think it works that way any longer in NXT-G V2.X. I'm sure I investigated this this difference some months ago and came to the conclusion that with V2.X a RESET MOTORS block in the second rung would cause the running motor block to exit.

Re: NXT-G: building a "state machine" problem

Posted: 28 Jan 2012, 16:51
by cfp999
I'm sure I investigated this this difference some months ago and came to the conclusion that with V2.X a RESET MOTORS block in the second rung would cause the running motor block to exit.
I can confirm that this is the case. Thank you so much ronmcrae! What a great and crucial piece of information. Now my 'state machine' is working as intended (well, apart from some minor adjustments :) ).
After struggling with this for several days I had almost given up, and was about to abandon NXT-G in favor of something else (NXC). My son, 9 years of age, is comfortable with NXT-G for now, so I'm glad it worked out.