Пример #1
0
void loop(){

 
  if(move){
    detectLine();
    keepDistance();
    adjustMotor(min(motorLine_l,motorDist_l),min(motorLine_r,motorDist_r));
    measureDistance();
  }
  else
  {
      detectAlone();
  }
}
Пример #2
0
unsigned long LUltrasonic::measureDistance3() {
    unsigned long measures[3];
    
    int i = 0;

    do {
        unsigned long distance = measureDistance();
        if (distance <= MAX_MEASUREABLE_DISTANCE) {
            measures[i++] = distance;
        }
        delay(2);
    } while (i < 3);

    return min((measures[0] + measures[1]) / 2, min((measures[1] + measures[2]) / 2, (measures[0] + measures[2]) / 2));
}
Пример #3
0
void loop()
{
	digitalWrite(PIN_LEDRED, HIGH);
	digitalWrite(PIN_LEDGREEN, LOW);

	measureTemperature();
	delay(250);
	measureMagnetism();
	delay(250);
	measureDistance();
	delay(250);

	digitalWrite(PIN_LEDRED, LOW);
	digitalWrite(PIN_LEDGREEN, HIGH);
	delay(25);
}
Пример #4
0
int findNeighbor(int obs, int k) {
    int i, j, temp, neighbor;
    int obs2 = (obs < 0)? -(1 + obs) : obs;
    double dist, min = INFTY;

    neighbor = 0;

    for (i = k; i < ct.n; i++) {
        j = ct.sorts[0][i];
        temp = (j < 0)? -(1 + j) : j;
        if (ct.treatment[temp] != ct.treatment[obs2]) {
            dist = measureDistance(obs2, temp);
            if (dist < min) {
                neighbor = j;
                min = dist;
            }
        }
    }
    return neighbor;
}