Page 1 of 1

Help with loops and conditions

Posted: 08 Aug 2012, 11:30
by nathanwong25
Hi there,
I am having some major problems trying to get my robot to exit a loop. I am using NXT-G.
I have it so that a loop runs until light sensor 3 detects a reflected light >80.

The problem though is that the program will not exit the loop. I have also run the data logger and it clearly gets readings >80, but it still does not exit.

I have also tried using wires to program it.

Can anyone please give me some advice?

Re: Help with loops and conditions

Posted: 08 Aug 2012, 13:03
by hassenplug
nathanwong25 wrote:Hi there,
I am having some major problems trying to get my robot to exit a loop. I am using NXT-G.
I have it so that a loop runs until light sensor 3 detects a reflected light >80.

The problem though is that the program will not exit the loop. I have also run the data logger and it clearly gets readings >80, but it still does not exit.
Can you post the program, or a screenshot of the program for us to look at?

Steve

Re: Help with loops and conditions

Posted: 08 Aug 2012, 13:40
by nathanwong25
hassenplug wrote: Can you post the program, or a screenshot of the program for us to look at?
I have attached it as requested, your help is appreciated!

Re: Help with loops and conditions

Posted: 09 Aug 2012, 17:46
by hassenplug
It's kind of hard to actually see exactly what you want the program to do. I suspect the problem that it has to see >80 at EXACTLY the right time in the program. It's spending a lot of the time moving, or waiting to see the line, and a small bit of time looking for >80.

How about if you try to explain what you want the robot to do, and maybe we can help you get there.

Steve

Re: Help with loops and conditions

Posted: 11 Aug 2012, 06:14
by nathanwong25
Hi,
Sorry for not clarifying. I am trying to program a robot for RoboCup junior. More or less it is a line tracking program.
When the robot gets to the end of the track their is a silver strip (detected at >80). The robot needs to stop when it sees the silver strip and then go onto the next part of the algorithm (which I havn't programmed). Light sensors 1+2 do the line tracking and sensor 3 looks for the silver strip.

From doing some more research, I have learnt that the program will only exit the loop if at the end of the sequence the condition is meet. Because the sequence within the loop may be still running when the condition is meet, the loop will not terminate.

I have tried running a program parallel to it on another sequence beam, simply "wait for light sensor >80 -> stop". This works all the time, although it shuts down the robot.

I was thinking about using a variable and then passing it through to the loop, but I do not know how to program this.

Thanks for your help

Re: Help with loops and conditions

Posted: 13 Aug 2012, 13:24
by nathanwong25
ok I think I have it, I need to set up a variable similiar to the one here
http://www.brickshelf.com/cgi-bin/gallery.cgi?i=1906478

Re: Help with loops and conditions

Posted: 13 Aug 2012, 14:37
by hassenplug
That's one good option. If you have time, I'd suggest you come back and review your line-following code to see if it can be made any better. But what you have may work.

Steve

Re: Help with loops and conditions

Posted: 04 Sep 2012, 14:14
by nathanwong25
Thanks.
Sorry for the late reply.
Seemed to work ok.
Cheers