Home        Store        Docs        Blog

Ping Sonar Measurement Latency

Hello, I am attempting to integrate the ping sonar onto the blue ROV 2. However, I have noticed that the sensor’s readings lag significantly. I emailed support about this, and they said that this is not expected. They suggested that I go back to the basic ping-python exampe, and the ping-viewer application. So I did that.

In ping viewer, the measurement lags by about a second behind reality. I measured this by moving the ping quickly between two positions in water, and having a colleague start a stopwatch when I start moving, and stop it when the output has reached within .1 m or so of it’s steady state value. Admittedly not the most precise measurement, but still precise enough to tell that there’s a problem.

Then I ran the simplePingExample (with some small changes, but nothing that should cause this problem). Here is my code:

#test example code to troubleshoot ping data lag
from brping import Ping1D
import time
import argparse

##Parse Command line options
############################

parser = argparse.ArgumentParser(description="Ping python library example.")
parser.add_argument('--device', action="store", required=True, type=str, help="Ping device port.")
parser.add_argument('--baudrate', action="store", type=int, default=115200, help="Ping device baudrate.")
args = parser.parse_args()

#Make a new Ping
myPing = Ping1D(args.device, args.baudrate)
if myPing.initialize() is False:
    print("Failed to initialize Ping!")
    exit(1)

print("Starting Ping..")

# Read and print altitude + confidence
while True:
    data = myPing.get_distance_simple()
    if data:
        print("Distance: %s\tConfidence: %s%%" % (data["distance"], data["confidence"]))
    else:
        print("Failed to get distance data")
    time.sleep(0.01)

Which I ran using the line:

Python simplePingExample.py --device /dev/ttyUSB0

I then looked at the command line output and tested the lag in the same way, which resulted in considerably more lag–about 5 seconds. I was sshing into the pi to get this output (rather than connecting it directly to a monitor), so this could account for the increased lag (as compared to ping viewer). I also tried replacing “get_distance()” with “get_distance_simple”, with no noticeable effect. And I tried changing time.sleep to .1 seconds, instead of .01, which increased the lag yet further–to about 7.5 seconds.

My python version is 2.7, and my brping library is 0.0.8

Any idea what I’m doing wrong? What is the expected latency of readings for the ping sonar?

Thanks,

Randy

Can you confirm the corresponding delay for each Ping or the delay for distance change?

If the delay is due to distance change, the beam angle may be taken into account.

Sure, I’m not exactly sure how to do that though. How would you suggest that I measure the delay of each ping?

And can you elaborate on your second statement? The system is delayed in reading a distance change; not sure how the beam angle would factor in here.

Hi Randy,

So you have a high refresh rate but it takes some time for the value to settle, is that it?

The Ping firmware tries to “lock” to the strongest reflections, which includes a filter among other things. Are you able to see the same behavior in Ping-Viewer?
How exactly are you testing?

Yes, that’s an accurate summary. I can see the value start to change as soon as I start moving the sensor, but it takes about a second to catch up in ping viewer. It’s actually longer in the simplePingExample (about 5 seconds), but I think the extra delay may be due to me reading the data over an SSH connection. I think it makes sense to concentrate on ping viewer for now, until that’s working as expected.

Here’s my test setup:

I have the ping sonar plugged into a laptop, via the bluart USB adapter. I am running ping viewer, and looking at the outputted distance on the screen. I hold the ping underwater, then move it down sharply by about .2 m. I start a stopwatch at the same time that I begin moving the ping, and stop it when the value has almost stabilized. This consistently takes about a second.

Is this lag expected, as a result of the filter that you mention? If so, is there a way to turn that filter off, or modify it? What is the expected lag of the readings?

Thanks for your help!

Hi Randy,

There is a filter, but right now it’s not possible to turn it off, you can try to increase the number of pings/s to see if the delay is minimized.

Could you explain a little bit more in detail what “lock” means? Does it mean that it might keep the past measurement when there is no other strong reflection? In our case, sometime it seems to happen and to “unlock”, we have to move the robot so that there is a big change in the distance measured by the echosounder.