Data Capture - ofithcheallaigh/masters_project GitHub Wiki

Introduction

This page will review how the data for this project was captured.

Data capture is an essential part of the research. It is the most important part because, with good data, we can expect good results.

This section of the Wiki will detail the data collection process.

Data Collection

Care, time, and thought must be given to the data collection process. The process has three main stages under the headings System, Objects and Format. In addition, each heading will have several sub-questions, which must be answered before data collection can start.

System

We can see from the figure above that the System section has several questions which are trying to determine the best method which can be employed to collect the data. There is no real question that this will be a microcontroller of some description used with a sensor.

Microcontroller

As any electronics engineer or hobbyist will tell you, a wide range of microcontrollers are on the market today. Still, when looking for a microcontroller for a TinyML application, we need to ensure that it is a 32-bit platform. TinyML applications are written in C++, and this has been very well tested on the Arm Cortex-M Series architecture and has been ported to other applications, such as the ESP32 [4].

A list of microcontrollers which can be used for a TinyML project is given below:

This is not an exhaustive list and does not cover the potential applications that FPGAs could cover.

We will not go into an extensive discussion here on microcontrollers, as this is covered here

With these things in mind, the following list of options was compiled:

  • Garmin LIDAR-Lite Optical Distance Sensor (V3)
  • Ultrasonic Distance Sensor
  • Garmin LIDAR-Lite Optical Distance Sensor (V4)
  • IR Distance Sensor
  • Large Ultrasonic (Sonar) with horn and UART Output
  • Adafruit MLX90640 IR Thermal Camera - 55 degree

The table below will detail some of the features of each:

Sensor Name Measuring Distance Height Width Depth Accuracy Voltage Interface cost
Garmin LIDAR-Lite Optical Distance Sensor - V3 40 m 40 mm 48 mm 20 mm ±2.5 cm at > 1m - I2C or PWN $130
Ultrasonic Distance Sensor 2 cm to 450 cm - - - - 3 - 5.5 V - $4
Garmin LIDAR-Lite Optical Distance Sensor (V4) 5 cm - 10 m 52.2 mm 21.2 mm 24.0 mm ± 1 cm to 2 m ± 2 cm to 4 m ± 5 cm to 10 m 4.75-5.25VDC I2C or ANT $60
IR Distance Sensor 1 m 18.6 mm 44.3 mm 13.5 mm - - - $15
Large Ultrasonic (Sonar) with horn and UART Output 28 cm - 600 cm - - - 1 cm ± 0.5% 3.3 - 5 V UART $29
Adafruit MLX90640 IR Thermal Camera - 55 degree - 25.7 mm 17.7 mm 16.0 mm - 3.3 V I2C $75

The main characteristics detailed above were scored in a weighted-scoring system. First, the factors were weighted with numbers 1 to 7, where 1 was the least important characteristic, and 7 was the most important characteristic. After that, each characteristic was given a score of 1 if the characteristic for a particular feature was good, a score of 0 if it wasn't important, and -1 if it was bad. So, for example, a score of -1 would be assigned to the cost of a very expensive sensor.

The full table can scores can be seen below:

We can see from this table that the ultrasonic distance sensor and the large ultrasonic sensor both scored the same. The decision then came down to availability. Having several ultrasonic distance sensors available means that that sensor was picked.

Ultrasonic Sensor

This section of the wiki will go into the operation of the ultrasonic sensor, which was

How Does the Ultrasonic Sensor Work?

The ultrasonic sensor's operating principle is quite simple. It works by emitting a sound wave (at 40 kHz) and then waiting for that wave to be reflected back, calculating the distance the wave travelled based on the time it took to receive that return signal [1]. The setup is shown in the diagram below:

Typically, an ultrasonic sensor will have the transmitter and receiver built into one unit. These sections can be seen in the image below, where the transmitter is marked with a T in the bottom left corner, and the receiver is marked with an R in the bottom right corner [2].

The distance is determined using the following equation:

$$ D = (C * T)/2 $$

Where D is the distance, C is the speed of sound in air (taken as 343m/s at room temperature) and T is the time.

The ultrasonic sensor used in this project was the HC-SR04 [3]. The main features of the HC-SR04 include which are essential for this research:

  • Range of 2 cm to 400 cm
  • Measuring angle of 15°

The sensor requires specific inputs provided by a microcontroller, which for this project, during the data collection phase, is the Arduino Uno.

Grid Layout

Below is the grid layout used for data capture:

This is a 3 ft by 3 ft grid, where each grid is 1 ft by 1 ft.

The data was collected using an Arduino Uno and two HC-SR04 ultrasonic sensors, pictures below:

Objects and location

As has been stated, the data will be collected from a hallway, which can be seen below:

This hallway has a door which can be closed for data collection. The image below shows the large bin, which was used for data collection, in the hallway:

Format

The data collection system outputs the data to a serial port. This can be monitored using an application called Tera Term, shown below:

Data Collection Code

The code which was used for the data collection is provided below:

/*
 * Sensor: HC-SR04 Ultrasonic sensor
 * Dev kit: Arduino Uno
 * 
 * 
 * Grid:
 *          X
 * |-----------------|
 * |  1  |  2  |  3  | 
 * |-----------------|
 * |  4  |  5  |  6  | 
 * |-----------------|
 * |  7  |  8  |  9  | 
 * |-----------------|
 * 
 * X = obstacle
 */


#define echoPinCh1 9 //8 // Echo pin on sensor wired to Pin D8 on dev kit
#define trigPinCh1 10 // // Echo pin on sensor wired to Pin D9 on dev kit
#define echoPinCh2 2 // Echo pin on sensor wired to Pin D8 on dev kit
#define trigPinCh2 3 // Echo pin on sensor wired to Pin D9 on dev kit
#define SAMPLE_LIMIT 100001

long channel1();
long channel2();


// defines variables
long durationCh1, durationCh2;  // Variable for the duration of sound wave travel
long distanceCh1, distanceCh2;  // Variable for the distance measurement
long cm;
int j, i;
long k;



void setup() {
  delay(10000); // Delay to serial monitor to be set up
  pinMode(trigPinCh1, OUTPUT);  // Sets the trigPin as an OUTPUT
  pinMode(echoPinCh1, INPUT);   // Sets the echoPin as an INPUT
  pinMode(trigPinCh2, OUTPUT);  // Sets the trigPin as an OUTPUT
  pinMode(echoPinCh2, INPUT);   // Sets the echoPin as an INPUT
  Serial.begin(9600);           // Serial Communication is starting with 9600 of baudrate speed
  Serial.print("Ultrasonic Sensor Data Capture Start"); // Text to note start of data collection
  Serial.println(",");
  Serial.print("Obstacle: Umbreall holder, open door mid hallway");
  Serial.println(",");
  Serial.print("Grid place: 9 (Steady)");
  Serial.println(",");
  delay(30000); // Delay to serial monitor to be set up
}
void loop() 
{ 
  // long int t1 = millis();
  // Serial.print("~~~Start~~~");
  // Serial.println(",");
  Serial.print("Ch1: ");
  Serial.println(",");
  long int t1 = millis();
  channel1();
  long int t2 = millis();
  Serial.print("~~~Ch1 End~~~");
  Serial.println(",");
  Serial.print("Channel 1 time: "); 
  Serial.print(t2-t1); 
  Serial.println(" milliseconds");
  Serial.println(",");

  delay(1000); // 1 second delay

  // Serial.print("~~~Start~~~");
  // Serial.println(",");
  Serial.print("Ch2: ");
  Serial.println(",");
  long int t3 = millis();
  channel2();
  long int t4 = millis();
  Serial.print("~~~Ch2 End~~~");
  Serial.println(",");
  Serial.print("Channel 2 time: "); 
  Serial.print(t4-t3); 
  Serial.println(" milliseconds");
  Serial.println(",");

  delay(300000); 
    
} // End of void loop

long channel1()
{
    for(k=0; k < SAMPLE_LIMIT; k++)
    {
      // Clears the trigPin condition
      digitalWrite(trigPinCh1, LOW);
      delayMicroseconds(2);
      
      // Sets the trigPin HIGH (ACTIVE) for 10 microseconds, as required by sensor
      digitalWrite(trigPinCh1, HIGH);
      delayMicroseconds(10);
      digitalWrite(trigPinCh1, LOW);
      
      // Reads the echoPin, returns the sound wave travel time in microseconds
      // I need to convert the long data type to int - this is for memory usage
      durationCh1 =  pulseIn(echoPinCh1, HIGH);
      distanceCh1 = durationCh1 * 0.034 / 2;
      Serial.print(durationCh1);
      Serial.println(",");
      // return distanceCh1;
    }
}

long channel2()
{
      for(k=0; k < SAMPLE_LIMIT; k++)
      {
        // Clears the trigPin condition
        digitalWrite(trigPinCh2, LOW);
        delayMicroseconds(2);
        
        // Sets the trigPin HIGH (ACTIVE) for 10 microseconds, as required by sensor
        digitalWrite(trigPinCh2, HIGH);
        delayMicroseconds(10);
        digitalWrite(trigPinCh2, LOW);
        
        // Reads the echoPin, returns the sound wave travel time in microseconds
        // I need to convert the long data type to int - this is for memory usage
        durationCh2 =  pulseIn(echoPinCh2, HIGH);
        distanceCh2 = durationCh2 * 0.034 / 2;
        Serial.print(durationCh2);
        Serial.println(",");
      }


}

Sources

[1] https://www.arrow.com/en/research-and-events/articles/ultrasonic-sensors-how-they-work-and-how-to-use-them-with-arduino
[2] https://randomnerdtutorials.com/complete-guide-for-ultrasonic-sensor-hc-sr04/
[3] https://cdn.sparkfun.com/datasheets/Sensors/Proximity/HCSR04.pdf
[4] TensorFlow, "TensorFlow Lite for Microcontrollers," TensorFlow Org, 22 7 2022. [Online]. Available: https://www.tensorflow.org/lite/microcontrollers. [Accessed 2023 1 24].