Announcement

Collapse
No announcement yet.

Flaws in the LinearIrExample

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

  • Philbot
    replied
    Hi

    To compound this, if the IR seeker is a new Modern Robotics one, it will NEVER be = 0, Unless it can't see the Beacon at all.
    The values is a double, and it's calculated, so the chance that the value will be 0.00000000 is VERY remote.
    So this loop would NEVER complete.

    Leave a comment:


  • dlevy
    started a topic Flaws in the LinearIrExample

    Flaws in the LinearIrExample

    First flaw:
    Code:
    // wait for the robot to center on the beacon
 
    while (irSeeker.getAngle() != 0) {
  
           waitOneHardwareCycle();

    }
    The above code is executed after the program initially decides to pivot left or right. It assumes that the robot will continue to turn and eventually put it at a zero angle from the target. It is however conceivable that two consecutive IR reading may result a value <0 and >0 respectively. If this is the case then the robot would have to spin 360 degrees while waiting for a potential zero angle reading.


    Second Flaw:
    Code:
    // wait until we are close enough
    while (irSeeker.getStrength() < HOLD_IR_SIGNAL_STRENGTH) {
           waitOneHardwareCycle();

    }
    The above code is executed after the program registers a zero angle to target and therefore sets its motors to drive straight until it receives a strong signal from the sensor. It is however conceivable that a robot programmed to drive straight (same power in each motor) may still veer slightly to the left or right. Although this error may be small, it will compound over larger distances. If this is the case then the robot would need to recheck the angle reading in addition to signal strength.

    I think a better implementation would be to remove both of the above code segments and wrap a "while (opModeIsActive()) { " above the " irSeeker.getAngle() " and have the "waitOneHardwareCycle()" line before the commands to stop the motors.


    I suppose that this makes the code less "linear" and one may ask the question " why not just use what is being referred to as the"event based" mode. Still - I like having control over where I code the looping so using while (opModeIsActive()) seems a bit more flexible.
Working...
X