Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronous camera shots with Python nidaqmx voltage control

Hi all, I am trying to write some code that sets a voltage through an analog output channel and then sets the voltage back to zero at some specified end time. This seems relatively straightforward with the Python API.

 

However, I am also trying to set up my camera (Allied Vision Mako series) to take camera shots every n seconds while the voltage is applied. Is there any way to synchronize the hardware clock of the NI card with the camera, so that I can take the shots at very precise times?

 

Here is my Python code for the analog output control:

 

 

import numpy as np
import nidaqmx
from nidaqmx.constants import AcquisitionType
# Experiment Parameters
num_shot = 20 # number of camera shots
shot_interval = 0.006 # time between camera shots in seconds
shot_fine_offset = 0.005
shot_global_offset = -0.03
(startloading, stoploading) = (0.001, 0.1) # timings for beginning and ending atom loading
(close_shutter, open_shutter) = (0, 3.3) # voltage to close and open the shutter respectively
# NI DAQMx Parameters
sample_rate = 1000 # sample rate for hardware clock in Hz
duration = stoploading
num_ticks = int(sample_rate * duration)
# Register analog output channel
task = nidaqmx.Task()
task.ao_channels.add_ao_voltage_chan("/Dev1/PFI1/ao0")
# Set hardware clock timing
task.timing.cfg_amp_clk_timing(
    sample_rate,
    sample_mode=AcquisitionType.FINITE,
    samps_per_chan=num_ticks
)
# Adjust voltage
task.write(np.ones(num_ticks), auto_start=False)
task.start()
task.wait_until_done()

 

 

Here is the code for my camera control:

 

 

 

from vimba import Vimba, get_all_cameras

with Vimba.get_instance():
    camera = vimba.get_all_cameras()[0]
    camera.GVSPAdjustPacketSize.run()
    for frame in camera.get_frame_generator(limit=10, timeout_ms=500ms):
        print("Shot taken at {}".format(frame))

 

 

This takes a camera shot every 500ms (I believe). I'd like to synchronize it so that I can take a camera shot every n milliseconds while the voltage is on.

0 Kudos
Message 1 of 1
(1,005 Views)