Skip to content

Commit 172888b

Browse files
BradG13531patrickelectric
authored andcommitted
Added support for TCP with the Omniscan450, Surveyor240, and the Sounder S500. Added default values for control functions on these sonar.
1 parent 05ac607 commit 172888b

7 files changed

Lines changed: 287 additions & 140 deletions

File tree

examples/simpleOmniscan450Example.py

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,24 @@
1010

1111
import signal
1212
import sys
13-
import struct
1413

1514
##Parse Command line options
1615
############################
1716

1817
parser = argparse.ArgumentParser(description="Ping python library example.")
1918
parser.add_argument('--device', action="store", required=False, type=str, help="Ping device port. E.g: /dev/ttyUSB0")
2019
parser.add_argument('--baudrate', action="store", type=int, default=115200, help="Ping device baudrate. E.g: 115200")
21-
parser.add_argument('--udp', action="store", required=False, type=str, help="Ping UDP server. E.g: 192.168.2.2:9090")
20+
parser.add_argument('--udp', action="store", required=False, type=str, help="Omniscan IP:Port. E.g: 192.168.2.92:51200")
21+
parser.add_argument('--tcp', action="store", required=False, type=str, help="Omniscan IP:Port. E.g: 192.168.2.92:51200")
2222
args = parser.parse_args()
23-
if args.device is None and args.udp is None:
23+
if args.device is None and args.udp is None and args.tcp is None:
2424
parser.print_help()
2525
exit(1)
2626

2727
# Signal handler to stop pinging on the Omniscan450
2828
def signal_handler(sig, frame):
2929
print("Stopping pinging on Omniscan450...")
30-
myOmniscan450.control_os_ping_params(
31-
start_mm=0,
32-
length_mm=0,
33-
msec_per_ping=0,
34-
reserved_1=0,
35-
reserved_2=0,
36-
pulse_len_percent=0.002,
37-
filter_duration_percent=0.0015,
38-
gain_index=-1,
39-
num_results=600,
40-
enable=0,
41-
reserved_3=0
42-
)
30+
myOmniscan450.control_os_ping_params(enable=0)
4331
if myOmniscan450.iodev:
4432
try:
4533
myOmniscan450.iodev.close()
@@ -49,13 +37,16 @@ def signal_handler(sig, frame):
4937

5038
signal.signal(signal.SIGINT, signal_handler)
5139

52-
# Make a new Surveyor240
40+
# Make a new Omniscan450
5341
myOmniscan450 = Omniscan450()
5442
if args.device is not None:
5543
myOmniscan450.connect_serial(args.device, args.baudrate)
5644
elif args.udp is not None:
5745
(host, port) = args.udp.split(':')
5846
myOmniscan450.connect_udp(host, int(port))
47+
elif args.tcp is not None:
48+
(host, port) = args.tcp.split(':')
49+
myOmniscan450.connect_tcp(host, int(port))
5950

6051
if myOmniscan450.initialize() is False:
6152
print("Failed to initialize Omniscan450!")
@@ -71,18 +62,20 @@ def signal_handler(sig, frame):
7162

7263
input("Press Enter to continue...")
7364

65+
# For default settings, just set enable pinging
66+
myOmniscan450.control_os_ping_params(enable=1)
67+
68+
# For a custom ping rate
69+
custom_msec_per_ping = Omniscan450.calc_msec_per_ping(1000) # 1000 Hz
70+
71+
# To find pulse length percent
72+
custom_pulse_length = Omniscan450.calc_pulse_length_pc(0.2) # 0.2%
73+
7474
myOmniscan450.control_os_ping_params(
75-
start_mm=0,
76-
length_mm=0,
77-
msec_per_ping=0,
78-
reserved_1=0,
79-
reserved_2=0,
80-
pulse_len_percent=0.002,
81-
filter_duration_percent=0.0015,
82-
gain_index=-1,
83-
num_results=600,
84-
enable=1,
85-
reserved_3=0
75+
msec_per_ping=custom_msec_per_ping,
76+
pulse_len_percent=custom_pulse_length,
77+
num_results=200,
78+
enable=1
8679
)
8780

8881
# View power results
@@ -95,3 +88,11 @@ def signal_handler(sig, frame):
9588
print(f"Max power: {data.max_pwr_db} dB")
9689
else:
9790
print("Failed to get report")
91+
92+
# Disable pinging and close socket
93+
myOmniscan450.control_os_ping_params(enable=0)
94+
if myOmniscan450.iodev:
95+
try:
96+
myOmniscan450.iodev.close()
97+
except Exception as e:
98+
print(f"Failed to close socket: {e}")

examples/simpleS500Example.py

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import signal
1212
import sys
13-
import struct
1413

1514
##Parse Command line options
1615
############################
@@ -19,25 +18,21 @@
1918
parser.add_argument('--device', action="store", required=False, type=str, help="Ping device port. E.g: /dev/ttyUSB0")
2019
parser.add_argument('--baudrate', action="store", type=int, default=115200, help="Ping device baudrate. E.g: 115200")
2120
parser.add_argument('--udp', action="store", required=False, type=str, help="Ping UDP server. E.g: 192.168.2.2:9090")
21+
parser.add_argument('--tcp', action="store", required=False, type=str, help="Sounder IP:Port. E.g: 192.168.2.86:51200")
2222
args = parser.parse_args()
23-
if args.device is None and args.udp is None:
23+
if args.device is None and args.udp is None and args.tcp is None:
2424
parser.print_help()
2525
exit(1)
2626

2727
# Signal handler to stop pinging on the S500
2828
def signal_handler(sig, frame):
2929
print("Stopping pinging on S500...")
30-
myS500.control_set_ping_params(
31-
start_mm=0,
32-
length_mm=0,
33-
gain_index=-1,
34-
msec_per_ping=-1,
35-
pulse_len_usec=0,
36-
report_id=0,
37-
reserved=0,
38-
chirp=1,
39-
decimation=0
40-
)
30+
myS500.control_set_ping_params(report_id=0)
31+
if myS500.iodev:
32+
try:
33+
myS500.iodev.close()
34+
except Exception as e:
35+
print(f"Failed to close socket: {e}")
4136
sys.exit(0)
4237

4338
signal.signal(signal.SIGINT, signal_handler)
@@ -49,11 +44,17 @@ def signal_handler(sig, frame):
4944
elif args.udp is not None:
5045
(host, port) = args.udp.split(':')
5146
myS500.connect_udp(host, int(port))
47+
elif args.tcp is not None:
48+
(host, port) = args.tcp.split(':')
49+
myS500.connect_tcp(host, int(port))
5250

5351
if myS500.initialize() is False:
5452
print("Failed to initialize S500!")
5553
exit(1)
5654

55+
data1 = myS500.get_device_information()
56+
print("Device type: %s" % data1["device_type"])
57+
5758
print("------------------------------------")
5859
print("Starting S500..")
5960
print("Press CTRL+C to exit")
@@ -64,15 +65,9 @@ def signal_handler(sig, frame):
6465
print("\n-------Distance2-------")
6566
# Tell S500 to send distance2 data
6667
myS500.control_set_ping_params(
67-
start_mm=0,
68-
length_mm=0,
69-
gain_index=-1,
7068
msec_per_ping=0,
71-
pulse_len_usec=0,
7269
report_id=definitions.S500_DISTANCE2,
73-
reserved=0,
74-
chirp=1,
75-
decimation=0
70+
chirp=1
7671
)
7772

7873
# Read and print distance2 data
@@ -87,15 +82,9 @@ def signal_handler(sig, frame):
8782
print("\n-------Profile6-------")
8883
# Tell S500 to send profile6 data
8984
myS500.control_set_ping_params(
90-
start_mm=0,
91-
length_mm=0,
92-
gain_index=-1,
93-
msec_per_ping=100,
94-
pulse_len_usec=0,
85+
msec_per_ping=0,
9586
report_id=definitions.S500_PROFILE6_T,
96-
reserved=0,
9787
chirp=1,
98-
decimation=0
9988
)
10089

10190
# Read and print profile6 data
@@ -120,16 +109,11 @@ def signal_handler(sig, frame):
120109

121110
else:
122111
print("Failed to get profile6 data")
123-
112+
124113
# Stop pinging
125-
myS500.control_set_ping_params(
126-
start_mm=0,
127-
length_mm=0,
128-
gain_index=-1,
129-
msec_per_ping=-1,
130-
pulse_len_usec=0,
131-
report_id=0,
132-
reserved=0,
133-
chirp=1,
134-
decimation=0
135-
)
114+
myS500.control_set_ping_params(report_id=0)
115+
if myS500.iodev:
116+
try:
117+
myS500.iodev.close()
118+
except Exception as e:
119+
print(f"Failed to close socket: {e}")

examples/simpleSurveyor240Example.py

Lines changed: 27 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,17 @@
1818
parser = argparse.ArgumentParser(description="Ping python library example.")
1919
parser.add_argument('--device', action="store", required=False, type=str, help="Ping device port. E.g: /dev/ttyUSB0")
2020
parser.add_argument('--baudrate', action="store", type=int, default=115200, help="Ping device baudrate. E.g: 115200")
21-
parser.add_argument('--udp', action="store", required=False, type=str, help="Ping UDP server. E.g: 192.168.2.2:9090")
21+
parser.add_argument('--udp', action="store", required=False, type=str, help="Surveyor IP:Port. E.g: 192.168.2.86:62312")
22+
parser.add_argument('--tcp', action="store", required=False, type=str, help="Surveyor IP:Port. E.g: 192.168.2.86:62312")
2223
args = parser.parse_args()
23-
if args.device is None and args.udp is None:
24+
if args.device is None and args.udp is None and args.tcp is None:
2425
parser.print_help()
2526
exit(1)
2627

2728
# Signal handler to stop pinging on the Surveyor240
2829
def signal_handler(sig, frame):
2930
print("Stopping pinging on Surveyor240...")
30-
mySurveyor240.control_set_ping_parameters(
31-
start_mm = 5,
32-
end_mm = 0,
33-
sos_mps = 1500,
34-
gain_index = -1,
35-
msec_per_ping = 100,
36-
deprecated=0,
37-
diagnostic_injected_signal = 0,
38-
ping_enable = False,
39-
enable_channel_data = False,
40-
reserved_for_raw_data = False,
41-
enable_yz_point_data = True,
42-
enable_atof_data = True,
43-
target_ping_hz=240000,
44-
n_range_steps = 400,
45-
reserved = 0,
46-
pulse_len_steps = 1.5
47-
)
31+
mySurveyor240.control_set_ping_parameters(ping_enable = False)
4832
# Close socket if open
4933
if mySurveyor240.iodev:
5034
try:
@@ -63,6 +47,9 @@ def signal_handler(sig, frame):
6347
elif args.udp is not None:
6448
(host, port) = args.udp.split(':')
6549
mySurveyor240.connect_udp(host, int(port))
50+
elif args.tcp is not None:
51+
(host, port) = args.tcp.split(':')
52+
mySurveyor240.connect_tcp(host, int(port))
6653

6754
if mySurveyor240.initialize() is False:
6855
print("Failed to initialize Surveyor240!")
@@ -79,24 +66,12 @@ def signal_handler(sig, frame):
7966
input("Press Enter to continue...")
8067

8168
mySurveyor240.control_set_ping_parameters(
82-
start_mm = 0,
83-
end_mm = 0,
84-
sos_mps = 1500,
85-
gain_index = -1,
86-
msec_per_ping = 100,
87-
deprecated=0,
88-
diagnostic_injected_signal = 0,
8969
ping_enable = True,
90-
enable_channel_data = False,
91-
reserved_for_raw_data = False,
9270
enable_yz_point_data = True,
9371
enable_atof_data = True,
94-
target_ping_hz=240000,
95-
n_range_steps = 400,
96-
reserved = 0,
97-
pulse_len_steps = 1.5
9872
)
9973

74+
print("\n---------Attitude Report---------")
10075
while True:
10176
data = mySurveyor240.wait_message([definitions.SURVEYOR240_ATTITUDE_REPORT])
10277
if data:
@@ -109,21 +84,25 @@ def signal_handler(sig, frame):
10984
print("Failed to get attitude report")
11085
time.sleep(0.1)
11186

87+
print("\n---------ATOF Point Data---------")
11288
while True:
11389
data = mySurveyor240.wait_message([definitions.SURVEYOR240_ATOF_POINT_DATA])
11490
if data:
11591
# Use create_atof_list to get formatted atof_t[num_points] list
11692
atof_data = Surveyor240.create_atof_list(data)
117-
for i in range(len(atof_data)):
118-
distance = 0.5 * data.sos_mps * atof_data[i].tof
119-
y = distance * math.sin(atof_data[i].angle)
120-
z = -distance * math.cos(atof_data[i].angle)
121-
print(f"{i}.\tDistance: {distance:.3f} meters\tY: {y:.3f}\tZ: {z:.3f}\t{atof_data[i]}")
122-
break
123-
93+
if len(atof_data) == 0:
94+
continue
95+
else:
96+
for i in range(len(atof_data)):
97+
distance = 0.5 * data.sos_mps * atof_data[i].tof
98+
y = distance * math.sin(atof_data[i].angle)
99+
z = -distance * math.cos(atof_data[i].angle)
100+
print(f"{i}.\tDistance: {distance:.3f} meters\tY: {y:.3f}\tZ: {z:.3f}\t{atof_data[i]}")
101+
break
124102
else:
125-
print("Failed to get attitude report")
103+
print("Failed to get atof point data")
126104

105+
print("\n---------YZ Point Data---------")
127106
while True:
128107
data = mySurveyor240.wait_message([definitions.SURVEYOR240_YZ_POINT_DATA])
129108
if data:
@@ -134,24 +113,12 @@ def signal_handler(sig, frame):
134113
print(f"{i//2}\t{yz_data[i]:.2f}\t{yz_data[i+1]:.2f}")
135114
break
136115
else:
137-
print("Failed to get attitude report")
116+
print("Failed to get yz point data")
138117

139118
# Stop pinging from Surveyor
140-
mySurveyor240.control_set_ping_parameters(
141-
start_mm = 5,
142-
end_mm = 0,
143-
sos_mps = 1500,
144-
gain_index = -1,
145-
msec_per_ping = 100,
146-
deprecated=0,
147-
diagnostic_injected_signal = 0,
148-
ping_enable = False,
149-
enable_channel_data = False,
150-
reserved_for_raw_data = False,
151-
enable_yz_point_data = True,
152-
enable_atof_data = True,
153-
target_ping_hz=240000,
154-
n_range_steps = 400,
155-
reserved = 0,
156-
pulse_len_steps = 1.5
157-
)
119+
mySurveyor240.control_set_ping_parameters(ping_enable = False)
120+
if mySurveyor240.iodev:
121+
try:
122+
mySurveyor240.iodev.close()
123+
except Exception as e:
124+
print(f"Failed to close socket: {e}")

0 commit comments

Comments
 (0)