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