[Documentation] [TitleIndex] [WordIndex

Speed measurement with ToF sensor VL53L1X (Python)

This tutorial guides you through calculating a relative velocity by using the distance measurement of the VL53L1X Time-of Flight sensor over the time.

In order to be able to measure a speed at all, we must first be able to measure a distance to an object. Ultimately, the tof sensor can do no more. Therefore, first read Distance measurement with ToF sensor VL53L1X (Python).

Calculating the speed

Let's take another closer look at the triangle from the previous chapter:

https://lastminuteengineers.b-cdn.net/wp-content/uploads/arduino/Distance-Speed-Time-Formula-Triangle.png

So we need

Speed = Distance / Time

However, we do not want to go to the speed of sound now and check whether there is a deviation here.

I will show you how to measure the speed of movement of an object using this sensor. For that purpose we need to take two distance measurements in a short time apart and we have:

distance2 - distance1 = distance speed at a given time

If we make the measurements in a time period of 1 second, then we get the speed of movement of the object in cm/s.

When the object is moving in the opposite direction, the speed represented on the display has a negative sign.

Programming the speed measurement

We change our code from the previous chapter to:

import VL53L1X
import time

tof = VL53L1X.VL53L1X(i2c_bus=1, i2c_address=0x29)
tof.open()

tof.start_ranging(1)

distance1 = tof.get_distance() * 0.001

tof.stop_ranging()

time.sleep(1)

tof.start_ranging(1)

distance2 = tof.get_distance() * 0.001

tof.stop_ranging()

speed = (distance2 - distance1) / 1.0    # m/s

Now that we know what we can measure with the VL53L1X and how, we can write our driver and wrap it in ROS in the next chapter. Please read for this Writing your VL53L1X driver (Python).


2024-11-16 12:14