/* Follows an object if it moves (such as a sheet of paper held in front of it)
 * using the Scribbler 2 IR sensors.
 */

#include <stdio.h>
#include <unistd.h>
#include <MyroC.h>

int
main()
{
  const int NUM_SAMPLES = 10;

  rSetForwardnessTxt ("fluke-forward");

  int irValues[2];

  while (1)
    {
      rGetIRAll (irValues, NUM_SAMPLES);
      
      if ( irValues[1] & irValues[2] )      // both sensors don't sense obstacles
        rForward (1,1);              
      
      else if ( irValues[1] & irValues[2] ) // right senses obstacle, left doesn't
        rTurnRight (1, .2);          
     
      else if (irValues[1] & irValues[2] )  // left senses obstacle, right doesn't
        rTurnLeft (1, .2);

      else if ( !irValues[1] & !irValues[2] ) // both sense obstacle
        sleep (1);
      
    } // while
  
  rDisconnect();
  return 0;
} // main

