Skip to content

Commit 4241f74

Browse files
peterhollenderebrahimebrahim
authored andcommitted
Update thermal test notebook (#75)
1 parent 3b47584 commit 4241f74

File tree

2 files changed

+103
-43
lines changed

2 files changed

+103
-43
lines changed

notebooks/test_thermal_stress.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
3. Test Device functionality.
2222
"""
2323

24-
log_interval = 1 # seconds; you can adjust this variable as needed
25-
stop_logging = False # flag to signal the logging thread to stop
24+
log_interval = 2 # seconds; you can adjust this variable as needed
2625

2726
frequency = 405e3
2827
voltage = 100.0
29-
duration_msec = 100
30-
interval_msec = 200
28+
duration_msec = 10
29+
interval_msec = 20
3130
num_devices = 1
31+
3232
console_shutoff_temp_C = 70.0 # Console shutoff temperature in Celsius
3333
tx_shutoff_temp_C = 70.0 # TX device shutoff temperature in Celsius
3434
ambient_shutowff_temp_C = 70.0 # Ambient shutoff temperature in Celsius
@@ -66,6 +66,7 @@
6666
# Ask the user if they want to log temperature
6767
log_choice = input("Do you want to log temperature before starting trigger? (y/n): ").strip().lower()
6868
log_temp = (log_choice == "y")
69+
stop_logging = False # flag to signal the logging thread to stop
6970

7071
def log_temperature():
7172
# Create a file with the current timestamp in the name
@@ -165,7 +166,6 @@ def log_temperature():
165166
# If logging is enabled, start the logging thread
166167
if log_temp:
167168
t = threading.Thread(target=log_temperature)
168-
t.start()
169169
else:
170170
print("Get Temperature")
171171
temperature = interface.txdevice.get_temperature()
@@ -185,10 +185,14 @@ def log_temperature():
185185

186186
print("Starting Trigger...")
187187
if interface.txdevice.start_trigger():
188+
if log_temp:
189+
t.start() # Start the logging thread
190+
188191
print("Trigger Running Press enter to STOP:")
189192
input() # Wait for the user to press Enter
193+
stop_logging = True
194+
time.sleep(0.5) # Give the logging thread time to finish
190195
if interface.txdevice.stop_trigger():
191-
stop_logging = True
192196
print("Trigger stopped successfully.")
193197
else:
194198
print("Failed to stop trigger.")

notebooks/test_watertank.py

Lines changed: 93 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import sys
34
import threading
45
import time
56

@@ -25,35 +26,82 @@
2526
log_interval = 1 # seconds; you can adjust this variable as needed
2627
stop_logging = False # flag to signal the logging thread to stop
2728

28-
def log_temperature():
29-
# Create a file with the current timestamp in the name
30-
timestamp = time.strftime("%Y%m%d_%H%M%S")
31-
filename = f"{timestamp}_temp.log"
32-
with open(filename, "w") as logfile:
33-
while not stop_logging:
34-
temperature = interface.txdevice.get_temperature()
35-
a_temp = interface.txdevice.get_ambient_temperature()
36-
current_time = time.strftime("%Y-%m-%d %H:%M:%S")
37-
log_line = f"{current_time}: Temperature: {temperature}, Ambient Temperature: {a_temp}\n"
38-
logfile.write(log_line)
39-
logfile.flush() # Ensure the data is written immediately
40-
time.sleep(log_interval)
29+
# set focus
30+
xInput = 0
31+
yInput = 0
32+
zInput = 50
4133

34+
frequency = 405e3
35+
voltage = 50.0
36+
duration = 2e-4
37+
38+
json_trigger_data = {
39+
"TriggerFrequencyHz": 5,
40+
"TriggerMode": 1,
41+
"TriggerPulseCount": 0,
42+
"TriggerPulseWidthUsec": 20000
43+
}
4244

4345
print("Starting LIFU Test Script...")
4446
interface = LIFUInterface()
4547
tx_connected, hv_connected = interface.is_device_connected()
48+
49+
if not tx_connected:
50+
print("TX device not connected. Attempting to turn on 12V...")
51+
interface.hvcontroller.turn_12v_on()
52+
53+
# Give time for the TX device to power up and enumerate over USB
54+
time.sleep(2)
55+
56+
# Cleanup and recreate interface to reinitialize USB devices
57+
interface.stop_monitoring()
58+
del interface
59+
time.sleep(1) # Short delay before recreating
60+
61+
print("Reinitializing LIFU interface after powering 12V...")
62+
interface = LIFUInterface()
63+
64+
# Re-check connection
65+
tx_connected, hv_connected = interface.is_device_connected()
66+
4667
if tx_connected and hv_connected:
47-
print("LIFU Device Fully connected.")
68+
print("LIFU Device fully connected.")
4869
else:
49-
print(f'LIFU Device NOT Fully Connected. TX: {tx_connected}, HV: {hv_connected}')
70+
print("❌ LIFU Device NOT fully connected.")
71+
print(f" TX Connected: {tx_connected}")
72+
print(f" HV Connected: {hv_connected}")
73+
sys.exit(1)
5074

5175
# Ask the user if they want to log temperature
5276
log_choice = input("Do you want to log temperature before starting trigger? (y/n): ").strip().lower()
5377
log_temp = (log_choice == "y")
5478

55-
print("Ping the device")
56-
interface.txdevice.ping()
79+
def log_temperature():
80+
# Create a file with the current timestamp in the name
81+
timestamp = time.strftime("%Y%m%d_%H%M%S")
82+
filename = f"{timestamp}_temp.csv"
83+
with open(filename, "w") as logfile:
84+
while not stop_logging:
85+
print("Retrieving Console temperature...")
86+
con_temp = interface.hvcontroller.get_temperature1()
87+
print("Retrieving TX temperature...")
88+
tx_temp = interface.txdevice.get_temperature()
89+
print("Retrieving TX Amb temperature...")
90+
amb_temp = interface.txdevice.get_ambient_temperature()
91+
current_time = time.strftime("%Y-%m-%d %H:%M:%S")
92+
log_line = f"{current_time},{frequency},{duration},{voltage},{con_temp},{tx_temp},{amb_temp}\n"
93+
logfile.write(log_line)
94+
logfile.flush() # Ensure the data is written immediately
95+
time.sleep(log_interval)
96+
97+
# Verify communication with the devices
98+
if not interface.txdevice.ping():
99+
print("Failed to ping the transmitter device.")
100+
sys.exit(1)
101+
102+
if not interface.hvcontroller.ping():
103+
print("Failed to ping the console devie.")
104+
sys.exit(1)
57105

58106
print("Enumerate TX7332 chips")
59107
num_tx_devices = interface.txdevice.enum_tx7332_devices()
@@ -62,21 +110,27 @@ def log_temperature():
62110
else:
63111
raise Exception("No TX7332 devices found.")
64112

65-
# set focus
66-
xInput = 0
67-
yInput = 0
68-
zInput = 50
113+
print("Set Trigger")
114+
trigger_setting = interface.txdevice.set_trigger_json(data=json_trigger_data)
115+
if trigger_setting:
116+
print(f"Trigger Setting: {trigger_setting}")
117+
else:
118+
print("Failed to set trigger setting.")
119+
sys.exit(1)
69120

70-
frequency = 405e3
71-
voltage = 12.0
72-
duration = 2e-5
121+
print("Set High Voltage")
122+
if interface.hvcontroller.set_voltage(voltage):
123+
print("High Voltage set successfully.")
124+
else:
125+
print("Failed to set High Voltage.")
126+
sys.exit(1)
73127

74128
pulse = Pulse(frequency=frequency, amplitude=voltage, duration=duration)
75129
pt = Point(position=(xInput,yInput,zInput), units="mm")
76130

77131
#arr = Transducer.from_file(r"C:\Users\Neuromod2\Documents\OpenLIFU-python\OpenLIFU_2x.json")
78132
# arr = Transducer.from_file(R"..\M4_flex.json")
79-
arr = Transducer.from_file(R"E:\CURRENT-WORK\openwater\OpenLIFU-python\notebooks\pinmap.json")
133+
arr = Transducer.from_file(R".\notebooks\pinmap.json")
80134

81135
focus = pt.get_position(units="mm")
82136
#arr.elements = np.array(arr.elements)[np.argsort([el.pin for el in arr.elements])].tolist()
@@ -85,9 +139,7 @@ def log_temperature():
85139
delays = tof.max() - tof
86140
apodizations = np.ones(arr.numelements())
87141

88-
89-
90-
# tURN only single element ON
142+
# Turn only single element ON
91143
#active_element = 25
92144

93145
#delays = delays*0.0
@@ -123,17 +175,9 @@ def log_temperature():
123175
profile_increment=profile_increment
124176
)
125177

126-
print("Get Trigger")
127-
trigger_setting = interface.txdevice.get_trigger_json()
128-
if trigger_setting:
129-
print(f"Trigger Setting: {trigger_setting}")
130-
else:
131-
print("Failed to get trigger setting.")
132-
133178
# If logging is enabled, start the logging thread
134179
if log_temp:
135180
t = threading.Thread(target=log_temperature)
136-
t.start()
137181
else:
138182
print("Get Temperature")
139183
temperature = interface.txdevice.get_temperature()
@@ -145,12 +189,24 @@ def log_temperature():
145189

146190
print("Press enter to START trigger:")
147191
input() # Wait for the user to press Enter
192+
193+
print("Enable High Voltage")
194+
if not interface.hvcontroller.turn_hv_on():
195+
print("Failed to turn on High Voltage.")
196+
sys.exit(1)
197+
148198
print("Starting Trigger...")
149199
if interface.txdevice.start_trigger():
200+
if log_temp:
201+
t.start() # Start the logging thread
202+
else:
203+
print("Trigger started without logging.")
204+
150205
print("Trigger Running Press enter to STOP:")
151206
input() # Wait for the user to press Enter
207+
stop_logging = True
208+
time.sleep(1) # Give the logging thread time to finish
152209
if interface.txdevice.stop_trigger():
153-
stop_logging = True
154210
print("Trigger stopped successfully.")
155211
else:
156212
print("Failed to stop trigger.")

0 commit comments

Comments
 (0)