View unanswered posts | View active topics It is currently Tue May 21, 2013 6:31 pm






Reply to topic  [ 2 posts ] 
Need help (advanced Line Tracking) 
Author Message
Rookie

Joined: Fri Sep 16, 2011 7:27 am
Posts: 1
Post Need help (advanced Line Tracking)
Hey i have a problem with my code:

my problem is: if for exampl the left light is on the tape, the robo makes a leftturn, but if the corner ist too long the right sensor is also on the tape n the robo stops cause both (leftlight & rightlight) are on the tape. how can i implement if the leftlight is the first on the tape that the rightlight (if it also get on the tape) doesnt send any input to the brik?

Image

my code
Code:
[#pragma config(Sensor, S1,     lightright,          sensorLightActive)
#pragma config(Sensor, S3,     lightleft,           sensorLightActive)
#pragma config(Sensor, S4,     lightmid,            sensorLightActive)
#pragma config(Motor,  motorB,          motorB,        tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  motorC,          motorC,        tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#define STRAIGHT 1;

void forwardHard ();
void forwardLight();
void turnLeft ();
void turnRight ();
void turnHardLeft ();
void turnHardRight ();
void stopp ();
const int v = 20;

task main(){
  int thresholdlr = 50;
  int thresholdm = 34;
  int lichtwertleft, lichtwertright, lichtwertmid;
  int statecode1 = 0;
  int statecode2 = 0;

  wait1Msec(1000);
  while(1==1){
      lichtwertleft = (SensorValue[lightleft]);
        lichtwertmid = SensorValue[lightmid];
        lichtwertright = SensorValue[lightright];
        nxtDisplayCenteredTextLine(1, "%i links:",lichtwertleft );
        nxtDisplayCenteredTextLine(2, "%i mitte:",lichtwertmid );
        nxtDisplayCenteredTextLine(3, "%i rechts:",lichtwertright);
    if(nNxtButtonPressed == 3){
      while(1==1){
        lichtwertleft = (SensorValue[lightleft]);
        lichtwertmid = SensorValue[lightmid];
        lichtwertright = SensorValue[lightright];
        nxtDisplayCenteredTextLine(1, "%i links:",lichtwertleft );
        nxtDisplayCenteredTextLine(2, "%i mitte:",lichtwertmid );
        nxtDisplayCenteredTextLine(3, "%i rechts:",lichtwertright);


        if (SensorValue[lightmid]<=thresholdm) statecode1 = 1;
        else if (SensorValue[lightmid]>thresholdm) statecode1 = 2;


        switch (statecode1){
        case 1:
          if (SensorValue[lightright]>thresholdlr && SensorValue[lightleft]>thresholdlr) statecode2 = 1;
          else if (SensorValue[lightright]<=thresholdlr && SensorValue[lightleft]>thresholdlr) statecode2 = 2;
          else if (SensorValue[lightright]>thresholdlr && SensorValue[lightleft]<=thresholdlr) statecode2 = 3;

          switch (statecode2){
          case 1:
            forwardHard ();
            break;
          case 2:
            turnRight ();
            break;
          case 3:
            turnLeft ();
            break;
          }
          break;
        case 2:
          forwardLight();
          if (SensorValue[lightright]<=thresholdlr && SensorValue[lightleft]>thresholdlr) statecode2 = 1;
          else if(SensorValue[lightright]>thresholdlr && SensorValue[lightleft]<=thresholdlr) statecode2 = 2;

          switch (statecode2){
          case 1:
            turnHardRight ();
            break;
          case 2:
            turnHardLeft ();
            break;
          }
          break;
        }

      }
    }
  }

}

void forwardHard (){
  motor[motorB]=v;
  motor[motorC]=v;
}
void forwardLight (){
  motor[motorB]=v*0.75;
  motor[motorC]=v*0.75;
}
void turnLeft (){
  motor[motorB]=v;
  motor[motorC]=0;
}
void turnRight(){
  motor[motorB]=0;
  motor[motorC]=v;
}
void stopp (){
  motor[motorB]=0;
  motor[motorC]=0;
}
void turnHardRight (){
  motor[motorB]=-v;
  motor[motorC]=v;
}
void turnHardLeft (){
  motor[motorB]=v;
  motor[motorC]=-v;
}


Fri Sep 16, 2011 7:42 am
Profile
Rookie

Joined: Tue Mar 01, 2011 6:16 pm
Posts: 21
Post Re: Need help (advanced Line Tracking)
But, all what you want is follow the black line you painted on the top?


Sat Sep 17, 2011 6:47 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

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