View unanswered posts | View active topics It is currently Wed May 22, 2013 10:11 pm






Reply to topic  [ 8 posts ] 
Line tracking problems 
Author Message
Rookie

Joined: Tue Mar 01, 2011 6:16 pm
Posts: 21
Post Line tracking problems
Hy friends, Im trying to use the light sensor for tracking a black line, but i need a code for make the robot stop in the middle of the line, and continue another command. I tryid all but the robot ever is going till the end of the line... and is not doing the other commando.
Code:
#pragma config(Sensor, S1,     lightSensor,         sensorLightActive)

task main(){
  motor[motorC] = 0;
  motor[motorB] = -45;
  wait10Msec(50);
  motor[motorA] = 0;
  motor[motorB] = 0;
  motor[motorC] = 0;
  wait10Msec(50);
 motor[motorA] = 0;
motor[motorB] = -30;
motor[motorC] = -30;
wait10Msec(515);
 motor[motorA] = 0;
  motor[motorB] = 0;
  motor[motorC] = 0;
  wait10Msec(50);
    motor[motorC] = 0;
  motor[motorB] = 45;
  wait10Msec(50);
   motor[motorA] = 0;
  motor[motorB] = 0;
  motor[motorC] = 0;
  wait10Msec(50);
    motor[motorC] = 20;
  motor[motorB] = 20;
  wait10Msec(100);
  motor[motorC] = -20;
  motor[motorB] = -20;
  wait10Msec(100);
    motor[motorA] = 0;
  motor[motorB] = 0;
  motor[motorC] = 0;
  wait10Msec(50);

{
   wait1Msec(50);

   while(true)
   {
      if(SensorValue[lightSensor] < 45)
      {
        motor[motorB] = 20;
      motor[motorC] = 20;
      wait10Msec(100);

      }
      else
      {
     motor[motorB] = 0;
      motor[motorC] = -20;

      }
   }
}
}



Tue Sep 13, 2011 2:45 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 2864
Location: Rotterdam, The Netherlands
Post Re: Line tracking problems
I am not sure what your program is trying to do from the code. What do all the motor commands at the start do?
What are you expecting the code at the bottom to do?

Can you explain your code to me? That might help me better understand.

- Xander

_________________
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)

| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Tue Sep 13, 2011 3:31 pm
Profile WWW
Rookie

Joined: Tue Mar 01, 2011 6:16 pm
Posts: 21
Post Re: Line tracking problems
Okay, thanks. The first code from " {" to the begining of the light sensor code makes the robot move from the base of the " body forward, you know that right? " to one bone, then the robot begans reading with the light sensor, if it read white it goes left, and if it read black it goes right, so when he detects a black line, it goes left and right following it. And what im looking for is, how i can do for make the robot stop in the middle of the black line, i mean how to stop de robot? for make the robot do another command.With this code, the robot goes till the end without stoping.

Thank you Xander.


Wed Sep 14, 2011 1:54 am
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 495
Post Re: Line tracking problems
How do you want the robot to know when it has reached the middle of the line? Do you want to use encoders or just time it?

_________________
sudo rm -rf /


Wed Sep 14, 2011 7:46 am
Profile
Rookie

Joined: Tue Mar 01, 2011 6:16 pm
Posts: 21
Post Re: Line tracking problems
It doesn't matter, but i prefer timing it. thanks


Thu Sep 15, 2011 10:33 am
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 495
Post Re: Line tracking problems
instead of doing while(true), you can try this:
Code:
int numMSecsToFollowLine;
ClearTimer(T1);
while(time1[T1] < numMSecsToFollowLine){
}

_________________
sudo rm -rf /


Thu Sep 15, 2011 6:52 pm
Profile
Rookie

Joined: Tue Mar 01, 2011 6:16 pm
Posts: 21
Post Re: Line tracking problems
Thanks! One question, IF i wanna write another program/code, after the light's sensor timer get finished, where i have to write it? thanks


Fri Sep 16, 2011 5:23 pm
Profile
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:44 am
Posts: 421
Location: Pittsburgh, PA
Post Re: Line tracking problems
The robot basically reads the commands from left to right, going from the top to the bottom... like a human would read a book. So basically, if you want your robot to track a line for a certain amount of time, you use that while loop. Once it's done (as indicated by the closing curly brace, "}") it will continue to the next line of code. So if you want it to perform another behavior after the line tracking, you would put it after the closing brace of the while loop (BUT BEFORE the closing brace of your program).

_________________
Vu Nguyen
Software Training Development Team | Webmaster
Need more support? Use the ROBOTC Ticketing system

Robotc.net| Robomatter Store | Robotics Academy


Fri Sep 16, 2011 10:25 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 8 posts ] 

Who is online

Users browsing this forum: No registered users and 5 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.