Lab3 - Time of Flight (ToF) Sensors
Published:
Objective
The purpose of this lab is to equip the robot with ToF sensors to get the distance information. Once the robots are equipped with sensors, the faster the robot can sample and the more it can trust a sensor reading, the faster it is able to drive.
Keywords
I2C Address, ToF (Time of Flight) Sensor
Prelab - Setup Two ToF Sensors by Changing I2C Address
After I connected the sensor to the Artemis, uploaded the Example02_Wire_I2C.ino, our board automatically returned the I2C sensor address as 0x29.
However, when I simultaneously used 2 ToF sensors, our board could not work well because the two sensors have the same I2C address which conflicts with each other. So, we needed to change one of the sensors’ address. First , by using one of the GPIOs of Artemis (pin 8), we set the XShut pin of one Tof sensor1 to LOW to disable sensor1. Then, we randomly assigned another I2C address to our still working sensor2 and reset sensor1’s XShut to HIGH to let it function. So, in this way, both sensors will function simultaneously using different I2C addresses.
Based on this method of setting up the two sensors, we should wiring the components in this way:
We only have two ToF sensors to detect the distances. So, I will probably place one in the front of the robot and the other one on the side. However, this will obviously miss the obstacles behind the robot and the ones on the other side of the robot.
Lab Tasks
Task 1 - Connection of ToF Sensors using QWIIC Breakout Board
I connected the two sensors with the Artemis using the QWIIC breakout board according to the wiring diagram, and here is the picture:
Task 2 - ToF I2C Address on Artemis Board
This part required attaching the screenshot of Artemis scanning for I2C device, which I had included in the Prelab section.
Task 3 - ToF Sensor Mode Selection
There are two modes for our ToF sensors - Short with 1.3m range, Long with 4m range. The short mode has the smallest range but with the highest precision, and the long mode has the biggest range but with the lowest precision. In practice, we should consider the exact real situations to choose which mode to use. Here, I chose both short mode for experiment.
Task 4 - Two ToF Sensors Functioning Simultaneously
After we set up our two ToF sensors, we can test them and let them output the distances in ArduinoIDE.
Task 5 - ToF Sampling Rate
I modified my code and let the sensors get the readings only when they were ready.
And I got the output from the Artemis with the time sample and the distance readings.
I selected this part of the output as the “sample”, and I calculated the rates:
which I got the rate of the Artemis getting the time readings at 200Hz at most, and the rate of ToF sensors getting distance readings at around 30Hz.
In this case, the current major limiting factor of the sample speed is the time of ToF sensors getting ready and acquiring new data. Every function for the sensor setup can cost some delay. So, whenever the sensors get ready, then the loop has to run the code about distance collecting and printing.
Task 6 - Data Transfer of ToF Distance Readings by BLE
I implemented a case command into ble_arduino.ino file called TOF_READINGS. After I uploaded the file into the board, I used the battery to charge up the board and connected the board to our computer, which showed as follows:
Then, I nodified the notification handler and stored the time and distance stamps into the corresponding arrays time_stamps, dist1_stamps, dist2_stamps.
Later, I plotted the curves of time - dist1 and time - dist2, which was almost as expected.