Follow black line

Post your RCX projects, project ideas, etc here!

Moderator: roger

antogrim2
New User
Posts: 5
Joined: Tue Jun 10, 2008 11:07 am

Follow black line

Postby antogrim2 » Tue Jun 10, 2008 11:11 am

I trying to write a program in which my robot would follw a black line, but i don't know how to do this...Can you help me? This is an university project, most important for me...thanks a lot...

ChrisB01
Advanced Member
Posts: 189
Joined: Sat Mar 15, 2008 12:19 pm
Location: UK

Line Folowing

Postby ChrisB01 » Tue Jun 10, 2008 3:34 pm

What kit do you have, most inportant light sensors and nxt/rcx's. There are diffrent ways of atacking the problem but it depends on what kit you have.

Thanks,

Chris

antogrim2
New User
Posts: 5
Joined: Tue Jun 10, 2008 11:07 am

Re: Line Folowing

Postby antogrim2 » Tue Jun 10, 2008 3:57 pm

[quote="ChrisB01"]What kit do you have, most inportant light sensors and nxt/rcx's. There are diffrent ways of atacking the problem but it depends on what kit you have.

Thanks,

Chris[/quote]

I have RCX. and one LightSensor.

User avatar
JavaMan
Novice
Posts: 27
Joined: Tue Apr 01, 2008 1:47 pm
Location: United States

Postby JavaMan » Wed Jun 11, 2008 11:37 am

I hope you have two motors, or one with a differential gear.

Here is the basic steps of a line-following robot I built with a rcx:

Robot drives forward a little bit.
Checks to see of light sensor is still reading black:
If it is then drive forward a little bit more.
If it is not then turn left a little bit then turn right a little bit to try to find the black line.
When the line is found the drive forward a little bit more.
Repeat process.

Make sure you have the RCX drive forward only a little bit because if it drives forward too much then you loose the black line, and finding it can be hard.

Jman
look up and see the chemtrails
www.carnicom.com

antogrim2
New User
Posts: 5
Joined: Tue Jun 10, 2008 11:07 am

Postby antogrim2 » Sat Jun 14, 2008 7:45 am

[quote="JavaMan"]I hope you have two motors, or one with a differential gear.

Here is the basic steps of a line-following robot I built with a rcx:

Robot drives forward a little bit.
Checks to see of light sensor is still reading black:
If it is then drive forward a little bit more.
If it is not then turn left a little bit then turn right a little bit to try to find the black line.
When the line is found the drive forward a little bit more.
Repeat process.

Make sure you have the RCX drive forward only a little bit because if it drives forward too much then you loose the black line, and finding it can be hard.

Jman[/quote]

Thanks very well...do you know something about color recognizing of light sensor? I have understood that the sensor recognizes accuratly only 3 colors: Black White and Grey...in raw mode

User avatar
JavaMan
Novice
Posts: 27
Joined: Tue Apr 01, 2008 1:47 pm
Location: United States

Postby JavaMan » Mon Jun 16, 2008 10:52 am

Yes, the light sensor for the RCX can only detect light intensity levels. So, usually black has a lower intensity and white has a higher intensity. Gray would have a intensity somewhere in the middle. It can't detect different wavelengths. Here is a site I found describing how to build a Color Sensor
http://www.extremenxt.com/MUX2.HTM for the RCX.

Hope that helps.
Jman
look up and see the chemtrails

www.carnicom.com

antogrim2
New User
Posts: 5
Joined: Tue Jun 10, 2008 11:07 am

Postby antogrim2 » Thu Jun 19, 2008 9:12 am

[quote="JavaMan"]I hope you have two motors, or one with a differential gear.

Here is the basic steps of a line-following robot I built with a rcx:

Robot drives forward a little bit.
Checks to see of light sensor is still reading black:
If it is then drive forward a little bit more.
If it is not then turn left a little bit then turn right a little bit to try to find the black line.
When the line is found the drive forward a little bit more.
Repeat process.

Make sure you have the RCX drive forward only a little bit because if it drives forward too much then you loose the black line, and finding it can be hard.

Jman[/quote]

Hi,
I have written an algorithm in which robot go on the left OR on the right, but it isn't up to decide run-time the direction. Can you help me, please? I post you my alg.

Robot.backward(3,3);
Robot.pause(150);
Robot.right(3,3); // or Robot.left(3,3);
Robot.pause(80);
Robot.forward(1,1);

it is called when state of light sensor changed from black to white. The parenthetical numbers of the methods forward right and backward indicate the power of motors.

User avatar
JavaMan
Novice
Posts: 27
Joined: Tue Apr 01, 2008 1:47 pm
Location: United States

Postby JavaMan » Thu Jun 19, 2008 10:55 pm

Ok, I think I understand what you mean.
I suggest when the rover notices that the the light goes from black to white:

Robot.backward(3,3);
Robot.pause(150);
Robot.right(3,3);
Robot.pause(80);
Robot.forward(1,1);
if(light.equals(white)){
Robot.left(3,3);
Robot.pause(80);
Robot.backward(3,3);
Robot.pause(150);
Robot.left(3,3);
Robot.pause(80);
Robot.forward(1,1);
//Hopefully the line is found.
}
else{
regular movement...
}


You could also have the robot sweep some degress left and right until he finds the line. Of course, depending on how curly your line is may screw this up.

Jman
look up and see the chemtrails

www.carnicom.com

antogrim2
New User
Posts: 5
Joined: Tue Jun 10, 2008 11:07 am

Postby antogrim2 » Sat Jun 21, 2008 7:49 pm

[quote="JavaMan"]Ok, I think I understand what you mean.
I suggest when the rover notices that the the light goes from black to white:

Robot.backward(3,3);
Robot.pause(150);
Robot.right(3,3);
Robot.pause(80);
Robot.forward(1,1);
if(light.equals(white)){
Robot.left(3,3);
Robot.pause(80);
Robot.backward(3,3);
Robot.pause(150);
Robot.left(3,3);
Robot.pause(80);
Robot.forward(1,1);
//Hopefully the line is found.
}
else{
regular movement...
}


You could also have the robot sweep some degress left and right until he finds the line. Of course, depending on how curly your line is may screw this up.

Jman[/quote]


Ok thanks...I try this solution and then tell you results. bye

DaliMe
New User
Posts: 1
Joined: Tue May 24, 2011 12:10 pm

Re: Follow black line

Postby DaliMe » Tue May 24, 2011 12:14 pm

Thank you very much! I also hae the similar task in my course work. Read lots of manuals but I couldn't understand the logic. Now it is clear.
Last edited by DaliMe on Wed Jun 13, 2012 9:06 am, edited 1 time in total.

rachael17
New User
Posts: 1
Joined: Wed Oct 26, 2011 9:21 am

Re: Follow black line

Postby rachael17 » Wed Oct 26, 2011 9:22 am

So do I!!! Thank you very much cialis for explanation, very helpful for me!
Last edited by rachael17 on Tue Feb 07, 2012 11:22 am, edited 1 time in total.

maccast
New User
Posts: 5
Joined: Fri Nov 11, 2011 11:49 pm

Re: Follow black line

Postby maccast » Sun Nov 27, 2011 5:57 am

I took some of the info in this thread and combined it with some other code and tutorials to write my version of a very simple line follower program. I am VERY new to lejos, so I'm open for any suggestions for improvement. I am posting the code mainly to help anyone else who might be working to figure this out as I could't find many actual code examples. This is code for the RCX and mine is a RCX 1.0. I am having one issue where at a certain point the RCX crashes (basically locks up on whatever the current command being executed is), but I'm not sure if that is me reaching a hardware limit or if there is an actual issue with this code. The RCX will make a beep and the LCD will display a 62 with a carrot (^) pointing to the #2 sensor. The number to the right of the "run" character will also change from a 0 to a 5. Not sure if that is significant or not. Again any suggestions are appreciated.

Code: Select all

import josx.platform.rcx.*;
import josx.robotics.*;

//////////////////////////////////////
/**
* Line follower
*
* @author Adam Christianson
* @url   http://www.terraform.com
* @version 1.0
*/
public class LineFollow {       

    ////////////////////////////////////////////
    // public methods
    ////////////////////////////////////////////

    ////////////////////////////////////////////
    /**
     * main method
     * @throws InterruptedException
     */
    public static void main(String[] args)
        throws InterruptedException {
      Sensor.S1.setTypeAndMode (3, 0x80);
      Sensor.S1.activate();
      Sensor.S1.addSensorListener (new SensorListener() {
        public void stateChanged (Sensor src, int oldValue, int newValue) {
          // Will be called whenever sensor value changes
          LCD.showNumber(newValue);
         TimingNavigator robot = new TimingNavigator(Motor.C, Motor.A, 1.6f, 0.54f);
         if (newValue > 35 ) {
            robot.travel(-15);
            pause(300);
            robot.rotate(-45);
            pause(300);
         } else {
            robot.forward();
         }
          try {
            Thread.sleep(100);
          } catch (InterruptedException e) {
            // ignore
          }
        }
      });      
      // just run until RUN button is pressed again
       Button.RUN.waitForPressAndRelease();
   } //main()
   
   public static void pause(int delay)
    {
      try { Thread.sleep(delay); }
      catch (InterruptedException ie) { }
    }
}

Charis
New User
Posts: 1
Joined: Thu Dec 29, 2011 2:56 pm

Re:

Postby Charis » Thu Dec 29, 2011 2:59 pm

JavaMan wrote:Yes, the light sensor for the RCX can only detect light intensity levels. So, usually black has a lower intensity and white has a higher intensity. Gray would have a intensity somewhere in the middle. It can't detect different wavelengths. Here is a site I found describing how to build a Color Sensor
http://www.extremenxt.com/MUX2.HTM for the RCX.

Hope that helps.
Jman

Thank you very much for this link! I have been wanting to create a sensor like this for a project that I am working on. It is a robot that will analyze and document the skid marks on a road after an accident, to help aid in accident reconstruction. I know that this might sound like a somewhat impractical, or far fetched concept, but if I get it working the way I designed, I can actually see it being quite a helpful contraption. I already have a coupe potential buyers waiting for a prototype. I am really excited about this project, and hope all goes well.


Return to “RCX Projects”

Who is online

Users browsing this forum: No registered users and 1 guest