Close

[TOF] Detection now running at 150Hz with 3 sensors

A project log for Gesture/Pattern Recognition Without Camera : TOF !

Grumpy Hedgehog is a connected device that allows you to read and interact with movements. Its LCD screen displays the Hedgehog's expression

jeanperardeljean.perardel 11/08/2021 at 10:430 Comments

By integrating the Start Ranging and the Check on separate loops. The code can now run at full speed. 
This allows us to reach 110Hz with 2 sensors, 150Hz with 3, 200 Hz with 4. 

int detect_All() {
  int range = 250;
  int distanceAll = MAX_DISTANCE_SHORT_DETECTION;
  for (int i = 0; i < NUMBER_OF_TOF_SENSORS; i++)
  {
    distanceSensor[i].setROI(16, 16, 198);
    distanceSensor[i].startRanging(); //Write configuration bytes to initiate measurement
  }
  for (int i = 0; i < NUMBER_OF_TOF_SENSORS; i++)
  {
    while (!distanceSensor[i].checkForDataReady()) {
      delay(1);
    }
    distanceAll = distanceSensor[i].getDistance(); //Get the result of the measurement from the sensor
    if (distanceAll >= MAX_DISTANCE_SHORT_DETECTION) {
      distanceAll = MAX_DISTANCE_SHORT_DETECTION;
    }
    distanceSensor[i].clearInterrupt();
    distanceSensor[i].stopRanging();

    if (distanceAll < range) {
      return 1;
    }
  }
  return 0;
}

Discussions