Ultrasonic sensor pan timing issue

I have an ultrasonic sensor patch that is designed to first pan the servo and then read a distance, i.e., it reads distance AFTER the servo changes position. This is the patch:

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.

gweimer, your suggestion in this post fixed the timing problem I was having here.


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. :thinking:

I think the loop is caused by your loop bus object; you have no defer there. If you put it before the input loop at the bottom, it would be clear that defer and the loop are related.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.