Esempio n. 1
0
/**
 * Simulates distance sensing for the IR sensors via decreasing the voltage the emitters get and counting the number of times the
 * sensors sense something
 */
void calculateIR(int * irLeft, int * irRight, int * irLeftOld, int * irRightOld){
  *irLeftOld = *irLeft;
  *irRightOld = *irRight;
  /*int el = 160/IR_STEP, bl = 0, er = 160/IR_STEP, br = 0;
  while(el-bl>1 || er-br>1){
    int dacVal = (el+bl)/2;
    dac_ctr(26, 0, 160-dacVal*IR_STEP);
    dac_ctr(27, 1, 160-dacVal*IR_STEP);
    freqout(11, 1, 38000);
    if(input(10)) bl=dacVal;
    else el=dacVal;
    
    dacVal = (er+br)/2;
    dac_ctr(26, 0, 160-dacVal*IR_STEP);
    dac_ctr(27, 1, 160-dacVal*IR_STEP);
    freqout(1, 1, 38000);
    if(input(2)) br=dacVal;
    else er=dacVal;
  }
  *irLeft=bl;
  *irRight=br;*/
  *irLeft=*irRight=0;
  for(int dacVal = 0; dacVal < 160; dacVal += 8) {
    dac_ctr(26, 0, dacVal);
    freqout(11, 1, 38000);
    *irLeft += input(10);

    dac_ctr(27, 1, dacVal);
    freqout(1, 1, 38000);
    *irRight += input(2);
  }
}
int main()                                    // main function
{
  dac_ctr(26, 0, 194);                        // 2.5 V to D/A0
  dac_ctr(27, 1, 78);                         // 1 V to D/A1
  pause(2000);                                // Pause 2 seconds
  dac_ctr(26, 0, 78);                         // 1 V to D/A0
  dac_ctr(27, 1, 194);                        // 1.5 V to D/A1
  pause(2000);                                // Pause 2 seconds
  dac_ctr_stop();                             // Stop D/A cog
}
Esempio n. 3
0
int getIR()
{
    irLeft = 0;
    irRight = 0;
    for (int dacVal = 0; dacVal < 160; dacVal += 8) {
        dac_ctr(26, 0, dacVal);
        freqout(11, 1, 38000);
        irLeft += input(10);

        dac_ctr(27, 1, dacVal);
        freqout(1, 1, 38000);
        irRight += input(2);
    }
}
Esempio n. 4
0
int checkClose(){
  
  irLeft = 0;
  irRight = 0;
  distance = ping_cm(8);

  for(int dacVal = 0; dacVal < 160; dacVal += 8){
    dac_ctr(26, 0, dacVal);
    freqout(11, 1, 38000);
    irLeft += input(10);

    dac_ctr(27, 1, dacVal);
    freqout(1, 1, 38000);
    irRight += input(2);
  }

  if (irLeft<7) {
    drive_speed(25,0);
  } else if (irLeft > 9 || irLeft == 0){
    drive_speed(0,25);
  } else {
    drive_speed(40,40);
  }
   
  if (distance<=5){
    fullTurn(90);
    degrees+=90;
    end=1;
  }

  drive_getTicks(&ticksLeft, &ticksRight);
  leftDeg = ((ticksLeft * 360) / 332.38128) * 3.25;
  rightDeg = ((ticksRight * 360) / 332.38128) * 3.25;
  degrees = degrees + (rightDeg - leftDeg);
  moved = ticksLeft * 3.25;
 }