ROVer is online | last fetch at :: | status:

Live Camera Feed

ROVer Robot D92: Short, Safer, Autonomous Drive Tests to Sort Out Drive Distance Settings

I had originally intended to let ROVer have another try at my hallway, but realized that he wasn’t yet ready.

We’ve got a lot of trial & error with respect to his Drive Settings before he’s ready to try the hallway again. Instead, we use a storage bin/box as a moveable obstacle that ROVer can crash into, over and over again, as we try and determine what distance, speed and acceleration work with the various turn maneuvers to result in the result we’re after.

I also managed to figure out a way to address those nagging sensor anomalies that had ROVer behaving erratically the other day during his Autonomous test drive. By taking the maximum of 4 values, we’re able to disregard any errant low values that would have otherwise triggered ROVer to respond and proceed with various events/actions.

Sensor Data Smoothing for Anomalies in Ultrasonic & IR

boolean getDistances() {

  allclear = false;
  sfclear = true;
  ssclear = true;
  
  if(relays[1] == 1) {
    if((currentMillis - lastPing) > 50) {

      if(currentPing == 0) {
        currentPing = 1;
        sfr_read = sonar[currentPing].ping_cm();
        sfr = max(sfr_prev[0], sfr_prev[1]);
      } else {
        currentPing = 0;
        sfl_read = sonar[currentPing].ping_cm();
      }
      
      lastPing = currentMillis;
    }
  
    //sfc = analogRead(ir);
    sfc = sharpf.distance();
    sl = sharpl.distance();
    sr = sharpr.distance();
    //sfc = map(analogRead(ir), 0, 650, 0, 255);

    if(gotDist >= 4) {gotDist = 0;}

    if(sfl_read > 0) {
      sfl_prev[gotDist] = sfl_read;
    }

    sfl = max(max(sfl_prev[0], sfl_prev[1]),max(sfl_prev[2], sfl_prev[3]));
    Serial.print("sfl = max(");
    Serial.print(sfl_prev[0]);
    Serial.print(", ");
    Serial.print(sfl_prev[1]);
    Serial.print(", ");
    Serial.print(sfl_prev[2]);
    Serial.print(", ");
    Serial.print(sfl_prev[3]);
    Serial.print(") = ");
    Serial.println(sfl);
    
    gotDist++;

    if(direction == 2) {
      allclear = true;
    } else {
      if(sfc > sfc_min && (sfl == 0 || sfl > sfl_min) && (sfr == 0 || sfr > sfr_min)) {
        if(sl < sl_min || sr < sr_min) {
          allclear = false; ssclear = false;
        } else {
          allclear = true;
        }
      } else {
        allclear = false; sfclear = false;
      }
    }

    /*if(debug) {
      Serial.print("sfl: ");
      Serial.print(sfl);
      Serial.print(", sfc: ");
      Serial.print(sfc);
      Serial.print(", sfr: ");
      Serial.print(sfr);
      Serial.print(", sl: ");
      Serial.print(sl);
      Serial.print(", sr: ");
      Serial.println(sr);
    }*/
    
  } else { // FWD Sensors are OFF
    allclear = true;
  }

  if(LastCommand == 1) {
    if(!allclear) {
      if(running && !obstacle) {
        obstacle = true;
      } else if(CMDTarget == 1) {
        obstacle = true;
        Serial.println("Obstacle(s)! Cannot Start");
        int autoLog[] = {10002, sfl, sfc, sfr};
        logROVer(autoLog);
      }
    }
  }

  return allclear;
}

I also came across this source, which offered a different "voting" solution, which may be something to explore:

https://www.codeproject.com/tips/813946/a-method-to-ignore-anomalies-in-an-ultrasonic-dist

Leave a comment