Skip to content

Commit c47346f

Browse files
BradG13531patrickelectric
authored andcommitted
Some minor changes to .svlog feature in omniscan, surveyor, and s500
1 parent fe36196 commit c47346f

File tree

6 files changed

+36
-22
lines changed

6 files changed

+36
-22
lines changed

examples/omniscan450Example.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def signal_handler(sig, frame):
114114
while True:
115115
data = Omniscan450.read_packet(f)
116116

117-
if data == None:
117+
if data is None:
118118
break # EOF or bad packet
119119

120120
print(f"ID: {data.message_id}\tName: {data.name}")
@@ -171,9 +171,12 @@ def signal_handler(sig, frame):
171171
try:
172172
while True:
173173
data = myOmniscan450.wait_message([definitions.OMNISCAN450_OS_MONO_PROFILE])
174-
if data and not new_log:
174+
if data:
175175
scaled_result = Omniscan450.scale_power(data)
176-
print(f"Average power: {sum(scaled_result) / len(scaled_result)}")
176+
try:
177+
print(f"Average power: {sum(scaled_result) / len(scaled_result)}")
178+
except ZeroDivisionError:
179+
print("Length of scaled_result is 0")
177180
elif not data:
178181
print("Failed to get message")
179182
except KeyboardInterrupt:

examples/s500Example.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,21 @@ def signal_handler(sig, frame):
113113
while True:
114114
data = S500.read_packet(f)
115115

116-
if data == None:
116+
if data is None:
117117
break # EOF or bad packet
118118

119-
print(f"ID: {data.message_id}\tName: {data.name}")
119+
# Uncomment to print out all packets contained in log file
120+
# print(f"ID: {data.message_id}\tName: {data.name}")
121+
122+
if data.message_id == definitions.S500_PROFILE6_T:
123+
scaled_result = S500.scale_power(data)
124+
try:
125+
print(f"Average power: {sum(scaled_result) / len(scaled_result)}")
126+
except ZeroDivisionError:
127+
print("Length of scaled_result is 0")
120128

121129
# Connected to physical S500
122130
else:
123-
print("\n-------Profile6-------")
124131
# Tell S500 to send profile6 data
125132
if args.range is not None:
126133
parts = args.range.split(':')
@@ -163,9 +170,12 @@ def signal_handler(sig, frame):
163170
# Read and print profile6 data
164171
data = myS500.wait_message([definitions.S500_PROFILE6_T,
165172
definitions.S500_DISTANCE2])
166-
if data and not new_log:
173+
if data:
167174
scaled_result = S500.scale_power(data)
168-
print(f"Average power: {sum(scaled_result) / len(scaled_result)}")
175+
try:
176+
print(f"Average power: {sum(scaled_result) / len(scaled_result)}")
177+
except ZeroDivisionError:
178+
print("Length of scaled_result is 0")
169179
elif not data:
170180
print("Failed to get message")
171181
except KeyboardInterrupt:

examples/surveyor240Example.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def signal_handler(sig, frame):
113113
while True:
114114
data = Surveyor240.read_packet(f)
115115

116-
if data == None:
116+
if data is None:
117117
break # EOF or bad packet
118118

119119
# print(f"ID: {data.message_id}\tName: {data.name}")
@@ -204,13 +204,14 @@ def signal_handler(sig, frame):
204204
definitions.SURVEYOR240_YZ_POINT_DATA,
205205
definitions.SURVEYOR240_WATER_STATS])
206206

207-
## To watch pitch and roll data in real time while recording, uncomment this block
208-
if data.message_id == definitions.SURVEYOR240_ATTITUDE_REPORT:
209-
# Print pitch and roll data
210-
vector = (data.up_vec_x, data.up_vec_y, data.up_vec_z)
211-
pitch = math.asin(vector[0])
212-
roll = math.atan2(vector[1], vector[2])
213-
print(f"Pitch: {pitch}\tRoll: {roll}")
207+
if data:
208+
## To watch pitch and roll data in real time while recording, uncomment this block
209+
if data.message_id == definitions.SURVEYOR240_ATTITUDE_REPORT:
210+
# Print pitch and roll data
211+
vector = (data.up_vec_x, data.up_vec_y, data.up_vec_z)
212+
pitch = math.asin(vector[0])
213+
roll = math.atan2(vector[1], vector[2])
214+
print(f"Pitch: {pitch}\tRoll: {roll}")
214215

215216
except KeyboardInterrupt:
216217
if new_log:

generate/templates/omniscan450.py.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,9 @@ class Omniscan450(PingDevice):
250250
else:
251251
self.log_directory = Path(log_directory)
252252

253-
log_directory.mkdir(parents=True, exist_ok=True)
253+
self.log_directory.mkdir(parents=True, exist_ok=True)
254254

255-
log_path = log_directory / f"{save_name}.svlog"
255+
log_path = self.log_directory / f"{save_name}.svlog"
256256

257257
if log_path.exists():
258258
log_path.unlink() # delete existing file (program was restarted quickly)

generate/templates/s500.py.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,9 @@ class S500(PingDevice):
281281
else:
282282
self.log_directory = Path(log_directory)
283283

284-
log_directory.mkdir(parents=True, exist_ok=True)
284+
self.log_directory.mkdir(parents=True, exist_ok=True)
285285

286-
log_path = log_directory / f"{save_name}.svlog"
286+
log_path = self.log_directory / f"{save_name}.svlog"
287287

288288
if log_path.exists():
289289
log_path.unlink() # delete existing file (program was restarted quickly)

generate/templates/surveyor240.py.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ class Surveyor240(PingDevice):
237237
else:
238238
self.log_directory = Path(log_directory)
239239

240-
log_directory.mkdir(parents=True, exist_ok=True)
240+
self.log_directory.mkdir(parents=True, exist_ok=True)
241241

242-
log_path = log_directory / f"{save_name}.svlog"
242+
log_path = self.log_directory / f"{save_name}.svlog"
243243

244244
if log_path.exists():
245245
log_path.unlink() # delete existing file (program was restarted quickly)

0 commit comments

Comments
 (0)