The purpose of this lab is to equip the robot with sensors - the faster the robot can sample and the more it can trust a sensor reading, the faster it is able to drive.
Scan the I2C channel to find the sensor
We used the following step to find the TOF sensor
1. Go to File->Examples->Apollo3->Wire and open Example1_wire_I2C
2. Browse through the code to see how to use i2c commands.
3. Run the code
And here below is the result:
From the serial monitor we could notic that some times the TOP with adress 0x29 is detected and sometimes it was not detected. This is normal to the TOF sensor, which also means that we successfully find the sensor.
Test your chosen mode
Here we used the middle distance mode to find a balance between distance and precesion, the testing results are shown below in the serial monitor:
To visualize the data, we plot the distance v.s. time in the figure below:
which is in consistent with the action of moving the TOP sensor far away from the wall
Using notes from the pre-lab, hook up both ToF sensors simultaneously and demonstrate that both works.
We choose one TOF and connect its 'xshut' pin to the A14 pin of the arduino, shown in the figure below, connected using the green cable.
when the xshut pin is LOW, the TOF will shut down, so that we can connect the other TOF and change its address. After that we change the xshut to HIGH to connect to the other TOF. The code in Arduino is shown below:
And its result is shown below:
In future labs, it is essential that the code executes quickly, therefore you cannot let your code hang while it waits for the sensor to finish a measurement. Write a piece of code that prints the Artemis clock to the Serial as fast as possible, continuously, and prints new ToF sensor data from both sensors only when available.
Here below is the result with delay:
With delay, the time inteval is nearly 100ms, which means that only 10 TOF data were received per second.
Then we modified the code below to delete the delay:
And the result without delay is:
The result shows that without delay, we can send data every 5-8 ms, even most of the time we cannot get the TOF data update, we can still send other useful message.
Many distance sensors are based on infrared trasmission. Discuss a couple, highlight the differences in their fuctionality and the pros/cons of each. Check and discuss whether the ToF sensor is sensitive to different colors and textures.
Infrared sensors for measuring distance come in different types. Some use triangulation, like the Sharp sensor, which estimates distance from reflected light angles, making it simple but less precise. Others, like Time-of-Flight (ToF) sensors such as VL53L0X, measure the time light takes to reflect, offering better accuracy. However, ToF sensors might be influenced by target color and texture due to light properties. The choice depends on the needs - a simple approach with less accuracy (like Sharp) or a more precise method (like VL53L0X) that might be sensitive to the color and texture of the target.