View unanswered posts | View active topics It is currently Wed Oct 22, 2014 5:40 am






Reply to topic  [ 6 posts ] 
Line Following Robot 
Author Message
Rookie

Joined: Thu Jul 18, 2013 7:22 pm
Posts: 4
Post Line Following Robot
Hi!

I am working on the Summer of Learning course and am trying to complete the Obstacle Course Challenge. I can get the robot to the black line, but cannot manage to get him to follow the line. I have tried several different methods used in the tutorial video about line tracking and copied them all precisely, but the robot will not work. He will make the first left swing turn until it detects white, then stop.

This is the line following section of my code:

Code:
while(1 == 1)                                                //Track the line
      {
         if(SensorValue(lightSensor) < 50)
            {
               swingTurn(left, 100);
            }
         else
            {
               swingTurn(right, 100);
            }
      }


Thanks!
Lacey


Tue Aug 06, 2013 5:04 pm
Profile
Moderator
Moderator

Joined: Mon Oct 04, 2010 2:18 pm
Posts: 196
Post Re: Line Following Robot
AceInventor wrote:
Hi!

I am working on the Summer of Learning course and am trying to complete the Obstacle Course Challenge. I can get the robot to the black line, but cannot manage to get him to follow the line. I have tried several different methods used in the tutorial video about line tracking and copied them all precisely, but the robot will not work. He will make the first left swing turn until it detects white, then stop.

This is the line following section of my code:

Code:
while(1 == 1)                                                //Track the line
      {
         if(SensorValue(lightSensor) < 50)
            {
               swingTurn(left, 100);
            }
         else
            {
               swingTurn(right, 100);
            }
      }


Thanks!
Lacey


Hey Lacey,

Glad you are in the Summer of Learning. Thanks for the question. I can offer a few suggestions/comments based upon the code you provided. First, you said that the robot is not following the line. What is it actually doing?

Next, I see that you have your robot set to turn at 100 power. That is too fast for a line following robot. Try slowing it down and see what happens.

How did you arrive at your threshold value of 50?

Finally, based upon your code, the robot is following the left side of a line. If it sees dark, it turns left; when it sees light, it turns right. When you robot gets to the line, which side of the line is it on? If the robot is on the right side of the line, it will see light, and then turn right. Therefore, since it is on the right side of the line, your robot will just spin.

I hope this helps. Let us know,


Tue Aug 06, 2013 9:08 pm
Profile
Rookie

Joined: Thu Jul 18, 2013 7:22 pm
Posts: 4
Post Re: Line Following Robot
Hi again!

Thanks for the quick response.

First, I have told the robot to move forward until it detects a black line then stop. It does this perfectly and is very nearly centered on the black line. Then, when it gets to the line following part of the program, it makes the first left turn until it sees the white area and stops and will not continue. Originally, I had the turn speed at 50 percent power, but I changed it to 100 hoping that maybe it was just moving to slow for me to see. I think that it might be a problem with the while loop, seeing how it only does the first step. I have tried multiple conditional statements in order to get the loop to work, but it always stops after the first turn.

About the threshold value, I am using the Robot Virtual Worlds program, so I do not know of a way to check the values. 50 has been working so far.

Thank you so much for your help!

Lacey


Wed Aug 07, 2013 1:07 pm
Profile
Moderator
Moderator

Joined: Mon Oct 04, 2010 2:18 pm
Posts: 196
Post Re: Line Following Robot
Hey Lacey,

Try posting your entire code. I'll run it and see what happens.

In order to figure out the thresholds in all of the virtual world environments, I always look in the sample programs.

Like I said, post your code, and I'll see what I can do to help


Wed Aug 07, 2013 1:30 pm
Profile
Rookie

Joined: Thu Jul 18, 2013 7:22 pm
Posts: 4
Post Re: Line Following Robot
Hi!

Here is my code:

Code:
#pragma config(StandardModel, "Virtual Worlds NXT")
#pragma config(RenamedStdModelSensor, S1, touchSensor)
#pragma config(RenamedStdModelSensor, S2, compassSensor)
#pragma config(RenamedStdModelSensor, S3, lightSensor)
#pragma config(RenamedStdModelSensor, S4, sonarSensor)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/* Virtual Worlds Configuration (Type - Name):
Motor Port A: NXT Motor - gripperMotor
Motor Port B: NXT Motor - rightMotor
Motor Port C: NXT Motor - leftMotor
Sensor Port 1: Touch Sensor - touch
Sensor Port 2: Compass Sensor - compass
Sensor Port 3: Light Sensor - light
Sensor Port 4: Sonar Sensor - sonar
*/

task main()
{

   while(SensorValue(touchSensor) == 0)               //forward until touch
      {
         forward(100);
      }

   backward(100);                                             //back up
   untilEncoderCounts(160);
   stop();

   motor(leftMotor) = 0;
   motor(rightMotor) = 0;
   wait1Msec(1000);

   pointTurn(left, 50);                                    //Turn Left
   untilEncoderCounts(155, rightMotor);
   stop();

   motor(leftMotor) = 0;
   motor(rightMotor) = 0;
   wait1Msec(1000);

   while(SensorValue(lightSensor) > 50)            //Forward to the black line
      {
         forward(100);
      }

   motor(leftMotor) = 0;
   motor(rightMotor) = 0;
   wait1Msec(1000);



   while(1 == 1)                                                //Track the line
      {
         if(SensorValue(lightSensor) < 50)
            {
               swingTurn(left, 100);
            }
         else
            {
               swingTurn(right, 100);
            }
      }
}


I have tried several different things, this is just the current version of my code.

Thanks so much!

Lacey


Wed Aug 07, 2013 2:18 pm
Profile
Moderator
Moderator

Joined: Mon Oct 04, 2010 2:18 pm
Posts: 196
Post Re: Line Following Robot
Ok, I tried your code, and it worked. As you mentioned, it was following the line very slowly. Robots in a virtual world tend to do this. If you look at the sample code that I posted below, you will see that the robot is making counter turns, instead of swing turns in which one of the wheels is set at zero. Try replacing the turns in your code with the turns from the code below. Nothing is wrong with the condition in your while loop. Let me know how it works.

Code:
#pragma config(Sensor, S1,     touchSensor,              sensorTouch)
#pragma config(Sensor, S2,     compassSensor,            sensorVirtualCompass)
#pragma config(Sensor, S3,     lightSensor,              sensorLightActive)
#pragma config(Sensor, S4,     sonarSensor,              sensorSONAR)
#pragma config(Motor,  motorA,          gripperMotor,       tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  motorB,          rightMotor,         tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  motorC,          leftMotor,          tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/*+++++++++++++++++++++++++++++++++++++++++++++| Notes |++++++++++++++++++++++++++++++++++++++++++++++
Line Track for Distance
This program uses 1 NXT Line Follower Sensor to track a black line on a light(er) surface
for 5 rotations of the encoders. There is a two second pause at the beginning of the program.

The threshold variable defined in this program may need to be changed for the line/surface your
robot is tracking and the lighting conditions.

Robot Model(s): NXT REMBOT

[I/O Port]          [Name]              [Type]                [Description]
Motor Port 2        rightMotor          NXT Motor             Right side motor
Motor Port 3        leftMotor           NXT Motor             Left side motor
Sensor Port S3      lightSensor         NXT Line Follower     Front-center, facing down

----------------------------------------------------------------------------------------------------*/

//+++++++++++++++++++++++++++++++++++++++++++++| MAIN |+++++++++++++++++++++++++++++++++++++++++++++++
task main()
{
  wait1Msec(2000);          // The program waits for 2000 milliseconds before continuing.

  int threshold = 45;       /* found by taking a reading on both DARK and LIGHT    */
                            /* surfaces, adding them together, then dividing by 2. */

  nMotorEncoder[rightMotor] = 0;  // Reset the right motor encoder to 0.

  //Line Track for 5 rotations...
  while(nMotorEncoder(rightMotor) < 1800)
  {
    // sensor sees light:
    if(SensorValue(lightSensor) < threshold)
    {
      // counter-steer left:
      motor[leftMotor]  = 55;
      motor[rightMotor] = 25;
    }
    // sensor sees dark:
    else
    {
      // counter-steer right:
      motor[leftMotor]  = 25;
      motor[rightMotor] = 55;
    }
  }
}


Wed Aug 07, 2013 7:20 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.