I use that patch in another patch that is designed to take three readings from the sensor in three different directions. It is working EXCEPT the reported distance is measured BEFORE the servo changes its angle. In other words, the resulting measurement is the distance to an object before the servo changed angle for another reading. I don’t understand why the distance being reported is from the previous sensor/servo position.
Here is the patch in which the sensor is being used to take successive readings in three different directions:
Defer will only pause long enough for other processing around it to finish (in this case, there is nothing else to do…). Instead of the defer node, you will need a delay node between the time you set the servo angle & the time you take the reading. The servo can take around 0.2 seconds to reach its target destination.
If you find the servo jerking back & forth instead of moving to a new position, that is a different problem that needs another solution.
When I replaced the DEFER node in the ultrasonic sensor patch with a delay node, the XOD compiler complained of a loop. When I put the DEFER node back, it compiled without error. The loop is certainly not obvious wherever it is, but apparently there is one that is addressed by the DEFER node.