NXT-G: building a "state machine" problem
Posted: 27 Jan 2012, 18:40
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.
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.