int main()                                    // main function
{
  drive_setRampStep(10);                      // 10 ticks/sec / 20 ms

  drive_ramp(128, 128);                       // Forward 2 RPS

  // While disatance greater than or equal
  // to 20 cm, wait 5 ms & recheck.
  while(ping_cm(8) >= 20) pause(5);           // Wait until object in range

  drive_ramp(0, 0);                           // Then stop

  // Turn in a random direction
  turn = rand() % 2;                          // Random val, odd = 1, even = 0

  if(turn == 1)                               // If turn is odd
    drive_speed(64, -64);                     // rotate right
  else                                        // else (if turn is even)
    drive_speed(-64, 64);                     // rotate left

  // Keep turning while object is in view
  while(ping_cm(8) < 20);                     // Turn till object leaves view

  drive_ramp(0, 0);                           // Stop & let program end
}
int main()                              // Main - execution begins!
{
  xbee = fdserial_open(11, 10, 0, 9600);
  //dprint(xbee, "hello");
  //dprint(xbee, "hello");

  drive_speed(0,0);                     // Start servos/encoders cog
  drive_setRampStep(10);                // Set ramping at 10 ticks/sec per 20 ms
  sirc_setTimeout(50);                  // Remote timeout = 50 ms

  //drive_feedback(0);

  dt = CLKFREQ/10;
  t  = CNT;

  while(1)                               // Outer loop
  {
    int button = sirc_button(4);      // check for remote key press

    // Motion responses - if key pressed, set wheel speeds
    if(button == 2)
    {
      if(!running) 
        cogstart(&gofwd, NULL, fstack, sizeof fstack);
    }
    if(button == 8)
    {
      if(!running) 
        cogstart(&gobkwd, NULL, bstack, sizeof bstack);
    }
    if(button == CH_UP)drive_rampStep(100, 100); // Left turn      
    if(button == CH_DN)drive_rampStep(-100, -100); // Right turn 
    if(button == VOL_DN)drive_rampStep(-100, 100); // Left turn      
    if(button == VOL_UP)drive_rampStep(100, -100); // Right turn 
    if(button == MUTE)drive_rampStep(0, 0);        // Stop 
    
    if(button == ENTER)
    {
      getTicks();
      displayTicks();
    }

    if(CNT - t > dt)
    {
      t+=dt;
      i++;
      getTicks();
      if
      (
           ticksLeftCalc  != ticksLeftCalcOld 
        || ticksRightCalc != ticksRightCalcOld
        || ticksLeft      != ticksLeftOld
        || ticksRight     != ticksRightOld
      )
      {
        displayTicks();
      }
    }
  }
}
示例#3
0
static void Config()
{
    // Initialize the drive speed, set the maximum speed, and set ramp step
    drive_speed(0, 0);
    drive_setMaxSpeed(DEFAULT_MAX_SPEED);    
    // Note: Chris has a question as to whether the ramping needed to be adjusted.  This needs to be addressed.
    drive_setRampStep(3);
}
示例#4
0
int main()                                    // Main function
{
  low(26);
  low(27);
  int irLeft, irRight;
  // Add startup code here.
 
  int leftDist, rightDist;

  while(1)
  {
    drive_setRampStep(10);
    drive_ramp(64, 64);
    
    while(1)
    {
      
      irLeft = checkLeft();
      irRight = checkRight();
      irRight = ping_cm(8);
      print ("left = %d,  right = %d \n", irLeft, irRight);
      if(irLeft == 1)
      {
        high(26);
      }
      else
      {
        low(26);
      }        
      if(ping_cm(8)<=10)
      {
        high(27);
      }
      else
      {
        low(27);
      }                        
      if(irLeft == 1)
      {
        
        drive_ramp(0, 0);
        turnLeftH();
        print (" Left empty hall detected");
        break;
      } 
      if (ping_cm(8)<=9)
      {
        drive_ramp(0, 0);
        turnBack();
        print (" End of the line");
        break;
      }               
    }      
  }    
    
     
}