Hi Patrick,
Sorry for the delay, it takes quite a long time to set up the tests for this.
Yes I have tested the minimal example, I built the code attached around that example. The CPU usage is fine, barely anything is running.
To show you the problem, I have adapted your simple example for the ping, and added the depth sensor.
#!/usr/bin/env python
#simplePingExample.py
from brping import Ping1D
import time
import argparse
import ms5837
from builtins import input
import csv
import os
##Parse Command line options
############################
parser = argparse.ArgumentParser(description="Ping python library example.")
parser.add_argument('--device', action="store", required=False, type=str, help="Ping device port. E.g: /dev/ttyUSB0")
parser.add_argument('--baudrate', action="store", type=int, default=115200, help="Ping device baudrate. E.g: 115200")
parser.add_argument('--udp', action="store", required=False, type=str, help="Ping UDP server. E.g: 192.168.2.2:9090")
args = parser.parse_args()
if args.device is None and args.udp is None:
parser.print_help()
exit(1)
# Make a new Ping
#myPing = Ping1D()
#if args.device is not None:
# myPing.connect_serial(args.device, args.baudrate)
#elif args.udp is not None:
# (host, port) = args.udp.split(':')
# myPing.connect_udp(host, int(port))
myPing = Ping1D(args.device, args.baudrate)
if myPing.initialize() is False:
print("Failed to initialize Ping!")
exit(1)
sensor = ms5837.MS5837_30BA()
# We must initialize the sensor before reading it
if not sensor.init():
print("Sensor could not be initialized")
exit(1)
# We have to read values from sensor to update pressure and temperature
if not sensor.read():
print("Sensor read failed!")
exit(1)
print("------------------------------------")
print("Starting Ping..")
print("Press CTRL+C to exit")
print("------------------------------------")
input("Press Enter to continue...")
with open('logs.csv', 'w') as f:
writer = csv.writer(f)
writer.writerow(["Time", "Depth", "Range"])
# Read and print distance measurements with confidence
while True:
data = myPing.get_distance()
if sensor.read():
depth = sensor.depth()
print("Depth: %f"%depth)
else:
print("Failed to get depth")
alt = float(data["distance"])/1000.0
if data:
print("Distance: %s\tConfidence: %s%%" % (alt, data["confidence"]))
else:
print("Failed to get distance data")
with open('logs.csv', 'a') as f:
writer = csv.writer(f)
writer.writerow([time.time(), depth, alt])
time.sleep(0.1)
I dunked the AUV in the tank.
The results show a lag between the peaks of the depth, and the troughs of the ping.I have updated the ping to the latest firmware, but I am still getting these issues.