The ultrasonic distance sensor is great for object avoidance because is has a wide field of view. But it has problems detecting objects that are at an angle to the sensor.
An infrared ToF (Time of Flight) sensor is much better at detecting objects at an angle.
The VL53L0X-V2 sensor is easy to use with the XRP and MicroPython. It communicates via the I2C (QWIIC) interface and there are several libraries available. Its filed of view is similar to the ultrasonic distance sensor.
Which sensor is best for your project? Experiment and find out!
Or, if you need a narrow field of view, consider a sensor such as the TF-Luna Lidar Sensor Kit which uses optical lenses to decrease the field of view to 2 degrees.
Solder the male-male header pins onto the VL53L0X-V2.
Use a Flexible Qwiic Cable - Female Jumper (4-pin) to connect the VL53L0X-V2 VIN, GND, SCL, SCA pins to the XRP QWIIC1 connector.
The "VL53L0X Time of Flight for MicroPython" Github has
Download vl53l0x.py here or from the Gtihub and save it directly onto the XRP's lib/ directory using the XRP code editor.
Copy the following example Micropython program: