<commit_before>#ifndef PING_SCAN_H
#define PING_SCAN_H

#include "Arduino.h"
#include "declarations.h"
#include "movement.h"
#include "ping_basic.h"
#include "beeps.h"
#include "ping_scan_utils.h"
#include "ping_analyze_scan.h"

const int maxCylWidth = 7;
const int minCylDepth = 5;
const int maxCylDist = 60;
const int timeOut = 100;

void resetMeasurements(){
    for(int i=0; i < nMeasurements; i++){
      measurements[i]=0;
    }
}

// State 1: Use the sonar to search and find direction to a cylinder.
void ping_scan(){
  int scan_steps = 0;
  
  while(scan_steps < pingTimeOut){
    scan_steps++;
    
    resetMeasurements();
    measurements[1] = measurePingDist();
    Serial.println(String(measurements[1])); // DEBUG
    
    rotate(counterClockwise, rotationSpeed);
    while(true){
      measurements[0] = measurements[1];
      measurements[1] = measurePingDist();
      Serial.println(String(measurements[1])); // DEBUG
      delay(msPerStep-7);
      if( (measurements[0] - measurements[1]) > minCylDepth && measurements[1] < maxCylDist){
        break;
      }
    }
    stopMovement();
    
    beep2();
    
    int intervalLength = 0;
    int i = 1;
    rotate(counterClockwise, rotationSpeed);
    while(true){
      i++;
      intervalLength++;
      measurements[i] = measurePingDist();
      Serial.println(String(measurements[i])); // DEBUG
      delay(msPerStep-7);
      if(measurements[i] - measurements[i-1] > minCylDepth){// || intervalLength > maxCylWidth){
        break;
      }
    }
    stopMovement();
    
    beep3();
    
    delay(3000);
    binaryNumberBeep(intervalLength);
    
    if(intervalLength < maxCylWidth){
      rotate(clockwise, rotationSpeed);
      delay(msPerStep * intervalLength/2);
      stopMovement();
      beep();
      return;
    }
  }
  
  /*
  if(scan_steps >= pingTimeOut){
    rotate(clockwise, rotationSpeed);
    delay(msPerStep * intervalLength/2);
    stopMovement();
    return;
  }
  */
  
}

#endif<commit_msg>Added the function isCylinder to determine whether a sonar reading is a cylinder or not.<commit_after>#ifndef PING_SCAN_H
#define PING_SCAN_H

#include "Arduino.h"
#include "declarations.h"
#include "movement.h"
#include "ping_basic.h"
#include "beeps.h"
#include "ping_scan_utils.h"
#include "ping_analyze_scan.h"
#include <Average.h>

const int maxCylWidth = 7;
const int minCylDepth = 5;
const int maxCylDist = 60;
const int timeOut = 100;

void resetMeasurements(){
    for(int i=0; i < nMeasurements; i++){
      measurements[i]=0;
    }
}

// State 1: Use the sonar to search and find direction to a cylinder.
void ping_scan(){
  int scan_steps = 0;
  
  while(scan_steps < pingTimeOut){
    scan_steps++;
    
    resetMeasurements();
    measurements[1] = measurePingDist();
    Serial.println(String(measurements[1])); // DEBUG
    
    rotate(counterClockwise, rotationSpeed);
    while(true){
      measurements[0] = measurements[1];
      measurements[1] = measurePingDist();
      Serial.println(String(measurements[1])); // DEBUG
      delay(msPerStep-7);
      if( (measurements[0] - measurements[1]) > minCylDepth && measurements[1] < maxCylDist){
        break;
      }
    }
    stopMovement();
    
    beep2();
    
    int intervalLength = 0;
    int i = 1;
    rotate(counterClockwise, rotationSpeed);
    while(true){
      i++;
      intervalLength++;
      measurements[i] = measurePingDist();
      Serial.println(String(measurements[i])); // DEBUG
      delay(msPerStep-7);
      if(measurements[i] - measurements[i-1] > minCylDepth){// || intervalLength > maxCylWidth){
        break;
      }
    }
    stopMovement();
    
    beep3();
    
    delay(3000);
    binaryNumberBeep(intervalLength);
    
    if(intervalLength < maxCylWidth){
      rotate(clockwise, rotationSpeed);
      delay(msPerStep * intervalLength/2);
      stopMovement();
      beep();
      return;
    }
  }
  
  /*
  if(scan_steps >= pingTimeOut){
    rotate(clockwise, rotationSpeed);
    delay(msPerStep * intervalLength/2);
    stopMovement();
    return;
  }
  */
  
}

bool isCylinder(int measurements[nMeasurements], int intervalLength) {

    if (minimum(measurements, intervalLength) < 20) {
        if (intervalLength <= 8) {
            return true;
        }else{
            return false;
        }
    }else if(minimum(measurements, intervalLength) < 30) {
        if (intervalLength <= 7) {
            return true;
        }else{
            return false;
        }
    }else if(minimum(measurements, intervalLength) < 40) {
        if (intervalLength <= 5) {
            return true;
        }else{
            return false;
        }
    }else{
        if (intervalLength <= 4) {
            return true;
        }else{
            return false;
        }
    }
}


}
#endif
{'fraction_non_alphanumeric': 0.1285803888772737, 'fraction_numerical': 0.015889609031988293, 'mean_word_length': 2.6743471582181257, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2093148', 'n_tokens_mistral': 1608, 'n_tokens_neox': 1558, 'n_words': 327}