Page 1 of 2

Help: Light Sensor Counting =(

Posted: 30 Aug 2011, 16:56
by moofiee
Hi guys,

Need a little help here with NXT G. =(

how do i program, using 1 light sensor, to go across 5 black lines and after passing the fifth line, reverse back(reversing part doesnt have to count) ..
been trying out for hours =(

thanks..

Re: Help: Light Sensor Counting =(

Posted: 30 Aug 2011, 17:44
by muntoo
A basic implementation (not allowing for scalability, etc):

Make the robot move forward continuously. This can be done with the Motor or Move Block.

Use a Loop Block, and set it to repeat 5 times. (Counter?) Inside it, put a Wait Block that waits for the Light sensor to be greater than 50% (or some other value). Then add another Wait Block next to the last one, that waits for the Light sensor to be less than 50%.

At the end of the program (outside the Loop Block), put a Motor or Move Block that reverses your robot.

You may wish to calibrate your light sensor. See the first part of the Claw Car with Game Controller program for an example of how to do that.

Re: Help: Light Sensor Counting =(

Posted: 30 Aug 2011, 17:51
by hassenplug
Most people forget that robots count VERY fast, but they aren't very smart. So, you may tell it to move until it sees a line, and that's fine. But you tell it to move to the next line, and the robot thinks it's already there...

Steve

Re: Help: Light Sensor Counting =(

Posted: 30 Aug 2011, 17:57
by moofiee
hassenplug wrote:Most people forget that robots count VERY fast, but they aren't very smart. So, you may tell it to move until it sees a line, and that's fine. But you tell it to move to the next line, and the robot thinks it's already there...

Steve
yeah. this is exactly what happened... upon reaching the first line the loops stops even thou i set it to 5. =(

Re: Help: Light Sensor Counting =(

Posted: 30 Aug 2011, 21:33
by mattallen37
That's why you not only need to see the line, but also see the other color. As muntoo said, until > 50 then until < 50 (or whatever the case may be).

Re: Help: Light Sensor Counting =(

Posted: 31 Aug 2011, 03:13
by moofiee
so its. (Loopx5) (>50)(forward)(<50)(forward) (Loopx5) (reverse) ?

Re: Help: Light Sensor Counting =(

Posted: 31 Aug 2011, 06:06
by muntoo
moofiee wrote:so its. (Loopx5) (>50)(forward)(<50)(forward) (Loopx5) (reverse) ?
It's:

Code: Select all

Forward (Forever)

Loop 5
{
    Wait until >50
    Wait until <50
}

Reverse

Re: Help: Light Sensor Counting =(

Posted: 31 Aug 2011, 07:22
by moofiee
Thanks for the help all.

Muntoo I tried the way as u mention. The robot started reversing upon detecting the first line still. :(

Re: Help: Light Sensor Counting =(

Posted: 31 Aug 2011, 21:36
by muntoo
That's because the light sensor is "just within" the range of 49% - 51%, so the values oscillate between the two very quickly for potentially various reasons. (Lighting conditions, imperfection of the line, sensor error, etc.)

In short, you should try:

Code: Select all

Forward (Forever)

Loop 5
{
    Wait until >50%
    Wait 100 milliseconds
    Wait until <50%
    Wait 100 milliseconds
}

Reverse
You may wish to wait longer or shorter than 100ms (0.1s); some testing is required.

Re: Help: Light Sensor Counting =(

Posted: 31 Aug 2011, 22:26
by aswin0
muntoo wrote:That's because the light sensor is "just within" the range of 49% - 51%, so the values oscillate between the two very quickly for potentially various reasons. (Lighting conditions, imperfection of the line, sensor error, etc.)

In short, you should try:

Code: Select all

Forward (Forever)

Loop 5
{
    Wait until >50%
    Wait 100 milliseconds
    Wait until <50%
    Wait 100 milliseconds
}

Reverse
You may wish to wait longer or shorter than 100ms (0.1s); some testing is required.
I would rather set the threshold for < to a lower value then the one for >. This because timing is always difficult as it depends on robot speed.

Code: Select all

Forward (Forever)

Loop 5
{
    Wait until >50%
    Wait until <40%
}

Reverse