Help: Light Sensor Counting =(

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
moofiee
Posts: 5
Joined: 30 Aug 2011, 16:49

Help: Light Sensor Counting =(

Post 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..
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: Help: Light Sensor Counting =(

Post 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.
Last edited by muntoo on 30 Aug 2011, 18:50, edited 1 time in total.
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
hassenplug
Posts: 346
Joined: 27 Sep 2010, 03:05
Contact:

Re: Help: Light Sensor Counting =(

Post 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
---> Link to lots of MINDSTORMS stuff under my picture --->
moofiee
Posts: 5
Joined: 30 Aug 2011, 16:49

Re: Help: Light Sensor Counting =(

Post 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. =(
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: Help: Light Sensor Counting =(

Post 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).
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
moofiee
Posts: 5
Joined: 30 Aug 2011, 16:49

Re: Help: Light Sensor Counting =(

Post by moofiee »

so its. (Loopx5) (>50)(forward)(<50)(forward) (Loopx5) (reverse) ?
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: Help: Light Sensor Counting =(

Post 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
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
moofiee
Posts: 5
Joined: 30 Aug 2011, 16:49

Re: Help: Light Sensor Counting =(

Post 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. :(
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: Help: Light Sensor Counting =(

Post 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.
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
aswin0
Posts: 201
Joined: 29 Sep 2010, 06:58

Re: Help: Light Sensor Counting =(

Post 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
My blog: nxttime.wordpress.com
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 12 guests