Skip to content

Commit d9a2c23

Browse files
committed
update triangle waveform calculation
1 parent 8b40fcd commit d9a2c23

File tree

1 file changed

+20
-48
lines changed

1 file changed

+20
-48
lines changed

src/navigate/model/waveforms.py

Lines changed: 20 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,16 @@ def remote_focus_ramp_triangular(
217217
sample_rate=100000,
218218
exposure_time=0.2,
219219
sweep_time=0.24,
220-
remote_focus_delay=7.5,
221-
camera_delay=10,
222-
fall=2.5,
220+
remote_focus_delay=0.005,
221+
camera_delay=0.001,
223222
amplitude=1,
224223
offset=0,
225224
ramp_type='Rising'
226225
):
227226
"""Returns a numpy array with a triangular ramp typically used for remote focusing
228227
229228
The waveform starts at offset and stays there for the delay period, then
230-
rises linearly to 2x amplitude (amplitude here refers to 1/2 peak-to-peak)
231-
and drops back down to the offset voltage during the fall period.
229+
rises linearly to 2x amplitude (amplitude here refers to 1/2 peak-to-peak).
232230
233231
Switching from a left to right remote focus ramp is possible by exchanging the
234232
rise and fall periods.
@@ -242,11 +240,9 @@ def remote_focus_ramp_triangular(
242240
sweep_time : Float
243241
Unit - Seconds
244242
remote_focus_delay : Float
245-
Unit - Percent
243+
Unit - Seconds
246244
camera_delay : Float
247-
Unit - Percent
248-
fall : Float
249-
Unit - Percent
245+
Unit - Seconds
250246
amplitude : Float
251247
Unit - Volts
252248
offset : Float
@@ -266,53 +262,29 @@ def remote_focus_ramp_triangular(
266262
"""
267263
# create an array just containing the negative amplitude voltage:
268264
# In theory, delay here should be 4H.
269-
delay_samples = int(remote_focus_delay * exposure_time * sample_rate / 100)
265+
delay_samples = int(remote_focus_delay * sample_rate)
270266
delay_array = np.zeros(delay_samples) + offset
271267

272-
# 10-7.5 -> 1.025 * .2
273-
#
274-
rise_ramp_samples = int(
275-
(exposure_time + exposure_time * (0 - remote_focus_delay) / 100)
276-
* sample_rate
277-
)
278-
fall_ramp_samples = int(
279-
(exposure_time + exposure_time * (camera_delay - remote_focus_delay) / 100)
268+
# ramp samples
269+
ramp_samples = int(
270+
(exposure_time + camera_delay - remote_focus_delay)
280271
* sample_rate
281272
)
282-
rise_ramp_array = np.linspace(offset - amplitude, offset + amplitude, rise_ramp_samples)
283-
fall_ramp_array = np.linspace(offset + amplitude, offset - amplitude, fall_ramp_samples)
284-
285-
# fall_samples = .025 * .2 * 100000 = 500
286-
settle_samples = int(fall * exposure_time * sample_rate / 100)
287-
settle_array = np.zeros(settle_samples) + offset
273+
rise_ramp_array = np.linspace(offset - amplitude, offset + amplitude, ramp_samples)
274+
fall_ramp_array = np.linspace(offset + amplitude, offset - amplitude, ramp_samples)
288275

289-
extra_samples = int(
276+
settle_samples = int(
290277
int(np.multiply(sample_rate, sweep_time))
291-
- (delay_samples + rise_ramp_samples + settle_samples)
278+
- (delay_samples + ramp_samples)
292279
)
280+
settle_array = np.zeros(settle_samples) + offset
293281

294-
if extra_samples > 0:
295-
print("extra samples:", extra_samples)
296-
extra_array = np.zeros(extra_samples) + offset
297-
if ramp_type == 'Rising':
298-
waveform = np.hstack(
299-
[delay_array - amplitude, rise_ramp_array, settle_array + amplitude,
300-
delay_array + amplitude, fall_ramp_array, settle_array - amplitude, extra_array - amplitude, extra_array - amplitude]
301-
)
302-
elif ramp_type == 'Falling':
303-
waveform = np.hstack(
304-
[delay_array + amplitude, fall_ramp_array, settle_array - amplitude, extra_array - amplitude,
305-
delay_array - amplitude, rise_ramp_array, settle_array + amplitude, extra_array + amplitude]
306-
)
307-
else:
308-
if ramp_type == 'Rising':
309-
waveform = np.hstack([delay_array - amplitude, rise_ramp_array, settle_array + amplitude,
310-
delay_array + amplitude, fall_ramp_array, settle_array - amplitude]
311-
)
312-
elif ramp_type == 'Falling':
313-
waveform = np.hstack([delay_array + amplitude, fall_ramp_array, settle_array - amplitude,
314-
delay_array - amplitude, rise_ramp_array, settle_array + amplitude]
315-
)
282+
if ramp_type == 'Rising':
283+
waveform = np.hstack([delay_array - amplitude, rise_ramp_array, settle_array + amplitude,
284+
delay_array + amplitude, fall_ramp_array, settle_array - amplitude])
285+
elif ramp_type == 'Falling':
286+
waveform = np.hstack([delay_array + amplitude, fall_ramp_array, settle_array - amplitude,
287+
delay_array - amplitude, rise_ramp_array, settle_array + amplitude])
316288

317289
return waveform
318290

0 commit comments

Comments
 (0)