Source code for stytra.stimulation.stimuli.external

from stytra.stimulation.stimuli import Stimulus


[docs]class PybPulseStimulus(Stimulus): """ """ def __init__( self, burst_freq=100, pulse_amp=3.0, pulse_n=5, pulse_dur_ms=2, com_port="COM3", **kwargs ): """ Burst of electric pulses generated by the pyboard(Anki's code) :param burst_freq: burst frequency (Hz) :param pulse_amp: pulse amplitude (mA) :param pulse_n: number of pulses :param pulse_dur_ms: pulses duration (ms) :param pyboard: PyboardConnection object """ try: from stytra.hardware.serial import PyboardConnection except ImportError: print("Serial pyboard connection not installed") super().__init__(**kwargs) self.name = "pulses" self._com_port = com_port self._pyb = None self.burst_freq = burst_freq self.pulse_dur_ms = pulse_dur_ms self.pulse_n = pulse_n self.pulse_amp_mA = pulse_amp # Pause between shocks in the burst in ms: self.pause = 1000 / burst_freq - pulse_dur_ms amp_dac = str(int(255 * pulse_amp / 3.5)) pulse_dur_str = str(pulse_dur_ms).zfill(3) self.mex = str("shock" + amp_dac + pulse_dur_str)
[docs] def initialise_external(self, experiment): """ Parameters ---------- experiment : Returns ------- """ try: from stytra.hardware.serial import PyboardConnection except ImportError: print("Serial pyboard connection not installed") self._pyb = PyboardConnection(com_port=self._com_port)
[docs] def start(self): """ """ super().update() for i in range(self.pulse_n): self._pyb.write(self.mex) self.elapsed = 1