ROBOTC.net forums
http://www.robotc.net/forums/

Need help with line-tracking code
http://www.robotc.net/forums/viewtopic.php?f=11&t=10608
Page 1 of 1

Author:  nicolaio [ Wed Mar 04, 2015 10:44 pm ]
Post subject:  Need help with line-tracking code

Hello, I have this problem with my code, I am not sure how to program it properly, therefore I am asking for help.
I'm making a marble sorter as a project in school, I'm at the last step of the marble sorter, sorting wood from plastic, however I am not sure how to code the line-tracker properly to work.
Currently it senses plastic marbles in the range of 100-300 and senses wood within the range of 301-1500.
It sensors the marbles just fine, however it will keep on running the code for wood and never stop.

What I want it to do is a marble comes down and then it runs the code for the specific marble, right now it will keep running the code for wood marble, even when there is no marble in front of the line-tracker. However if a plastic marble comes in front of it will run the code for plastic.

So overall my problem is just that it keeps on running, I want it to ONLY run when there is either a wood or plastic marble in front of the sensor.
I have posted my code below, thank you very much!

Code:
task Two()
{

  while(true)
  {
  if((SensorValue(lineTracker) < 300) && (SensorValue(lineTracker) > 100))
  {
    // sensor sees plastic:
        motor[leftMotor] = 0;
        wait1Msec(1000);
      motor[servoMotor]  = 127;
      wait1Msec(1000);
      motor[servoMotor] = 0;
    }
    // sensor sees wood:
    else((SensorValue(lineTracker) < 1500) && (SensorValue(lineTracker) > 301))
     {
       motor[leftMotor] = 30;
       wait1Msec(500);
       motor[leftMotor] = 0;
       wait1Msec(1500);
      motor[servoMotor]  = 127;
      wait1Msec(1000);
      motor[servoMotor] = 0;
      motor[leftMotor] = -30;
      wait1Msec(500);
      motor[leftMotor] = 0;
    }
  }
}

Author:  CARBOT [ Thu Mar 05, 2015 1:38 am ]
Post subject:  Re: Need help with line-tracking code

Try changing the else to an if.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/