Help with loops and conditions

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
nathanwong25
Posts: 5
Joined: 08 Aug 2012, 11:28

Help with loops and conditions

Post 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?
hassenplug
Posts: 346
Joined: 27 Sep 2010, 03:05
Contact:

Re: Help with loops and conditions

Post 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
---> Link to lots of MINDSTORMS stuff under my picture --->
nathanwong25
Posts: 5
Joined: 08 Aug 2012, 11:28

Re: Help with loops and conditions

Post 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!
Attachments
turn_on_green_l.rbt
Trouble terminating
(1.39 MiB) Downloaded 331 times
hassenplug
Posts: 346
Joined: 27 Sep 2010, 03:05
Contact:

Re: Help with loops and conditions

Post 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
---> Link to lots of MINDSTORMS stuff under my picture --->
nathanwong25
Posts: 5
Joined: 08 Aug 2012, 11:28

Re: Help with loops and conditions

Post 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
nathanwong25
Posts: 5
Joined: 08 Aug 2012, 11:28

Re: Help with loops and conditions

Post 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
hassenplug
Posts: 346
Joined: 27 Sep 2010, 03:05
Contact:

Re: Help with loops and conditions

Post 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
---> Link to lots of MINDSTORMS stuff under my picture --->
nathanwong25
Posts: 5
Joined: 08 Aug 2012, 11:28

Re: Help with loops and conditions

Post by nathanwong25 »

Thanks.
Sorry for the late reply.
Seemed to work ok.
Cheers
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests