Announcement

Collapse
No announcement yet.

Line Tracking

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Line Tracking

    We have ordered a range sensor from modern robotics, but for the time being we are trying to line track and stop using the optical distance sensors. Is there any reason the following piece of code wouldnt work? IT keeps freezing. Thank you for any help.

    while (odsSensor.getLightDetected() < 0.2) {

    if(lightSensor.getLightDetected() > WHITE_THRESHOLD){
    robot.leftMotor.setPower(30);
    robot.rightMotor.setPower(10);
    }
    else{
    robot.leftMotor.setPower(10);
    robot.rightMotor.setPower(30);
    }
    // Display the light level while we are looking for the line

    }
    robot.leftMotor.setPower(0);
    robot.rightMotor.setPower(0);

  • #2
    Is this in a linear OpMode? Please post the entire OpMode. Click the 'Go Advanced' reply option and paste our OpMode inside Code tags (use the # button in the editor).

    Comment


    • #3
      Originally posted by 5294-jjkd View Post
      Is this in a linear OpMode? Please post the entire OpMode. Click the 'Go Advanced' reply option and paste our OpMode inside Code tags (use the # button in the editor).
      Make that ... paste your OpMode ...

      The Code tags make your code retain spacing and indent when posted (I reformatted your code and added code tags):

      Code:
      while (odsSensor.getLightDetected() < 0.2) {
      
          if (lightSensor.getLightDetected() > WHITE_THRESHOLD) {
              robot.leftMotor.setPower(30);
              robot.rightMotor.setPower(10);
          } else {
              robot.leftMotor.setPower(10);
              robot.rightMotor.setPower(30);
          }
      
         // Display the light level while we are looking for the line
      
      }
      
      robot.leftMotor.setPower(0);
      robot.rightMotor.setPower(0);

      Comment


      • #4
        Simple error. The value for set power should be between 0 and 1. I added a decimal (.3 and .10) and magic! Thank you for your replies.

        Comment


        • #5
          Originally posted by FTC11180 View Post
          Simple error. The value for set power should be between 0 and 1. I added a decimal (.3 and .10) and magic! Thank you for your replies.
          BYW

          If this is in a LineaerOpMode, you should also include a way for the loop to exit if you press the STOP button.

          eg:

          while (opModeIsActive() && (odsSensor.getLightDetected() < 0.2)) {

          Comment


          • #6
            Thank you, we did go back and add that! Much appreciated.

            Comment

            Working...
            X