def bpod_modules_ok() -> bool: # List bpod modules # figure out if RE is in Module 1, Ambient sensore in port 2 and # if ephys in board name if SoundCard in port 3 ephys_rig = "ephys" in _grep_param_dict("NAME") if ephys_rig: expected_modules = [ "RotaryEncoder1", "AmbientModule1", "SoundCard1", ] else: expected_modules = [ "RotaryEncoder1", "AmbientModule1", ] out = False try: comport = _grep_param_dict("COM_BPOD") bpod = Bpod(serial_port=comport) mods = [x.name for x in bpod.modules] bpod.close() oks = [x in mods for x in expected_modules] if all(oks): out = True else: missing = set(expected_modules) - set(mods) log.warning(f"Missing modules: {missing}") except BaseException as e: log.warning(f"{e} \nCan't check modules from Bpod.") return out
class Airtrack: """Airtrack system interface.""" def __init__(self): self.__bpod = None self._bpod_closed = True self._subject = AirtrackSubject() # Register exit handler atexit.register(self.close) @property def _bpod(self): if self.__bpod is None: self._create_bpod() if self._bpod_closed: self._open_bpod() return self.__bpod @handle_error def _create_bpod(self): self.__bpod = Bpod(emulator_mode=True) @handle_error def _open_bpod(self): self.__bpod.open() self._bpod_closed = False @handle_error def _close(self): self.__bpod.close(ignore_emulator=True) self._bpod_closed = True @handle_error def _run(self): self._sma = AirtrackStateMachine(self._bpod, self._subject) self._sma.setup() self._bpod.send_state_machine(self._sma, ignore_emulator=True) self._bpod.run_state_machine(self._sma) @handle_error def _clean_up(self): self._subject.clean_up() self._sma.clean_up() def run(self, trials=None): """Run the system. :keyword trials (optional): Number of trials to run the system for. :type trials (optional): ``int`` """ iterator = range(trials or 0) or itertools.count() for i in iterator: trial = i + 1 logger.debug(f'Starting trial #{trial}...') self._run() logger.debug(f'End of trial #{trial}.') def close(self): """Close the system.""" self._clean_up() self._close()
state_timer=0, state_change_conditions={Bpod.Events.Tup: 'Port1Active1'}, output_actions=[(Bpod.OutputChannels.GlobalTimerTrig, 1)]) # Infinite loop (with next state). Only a global timer can save us. sma.add_state( state_name='Port1Active1', state_timer=0, state_change_conditions={Bpod.Events.Port1In: 'Port2Active1', Bpod.Events.GlobalTimer1_End: 'exit'}, output_actions=[(Bpod.OutputChannels.PWM1, 255)]) sma.add_state( state_name='Port2Active1', state_timer=0, state_change_conditions={Bpod.Events.Port2In: 'Port3Active1', Bpod.Events.GlobalTimer1_End: 'exit'}, output_actions=[(Bpod.OutputChannels.PWM2, 255)]) sma.add_state( state_name='Port3Active1', state_timer=0, state_change_conditions={Bpod.Events.Port3In: 'Port1Active1', Bpod.Events.GlobalTimer1_End: 'exit'}, output_actions=[(Bpod.OutputChannels.PWM3, 255)]) my_bpod.send_state_machine(sma) my_bpod.run_state_machine(sma) print("Current trial info: {0}".format(my_bpod.session.current_trial)) my_bpod.close()
as_data = tph.save_ambient_sensor_data(bpod, sph.SESSION_RAW_DATA_FOLDER) tph.show_trial_log() # Update online plots op.update_fig(f, axes, tph) tph.check_sync_pulses() stop_crit = tph.check_stop_criterions() if stop_crit and sph.USE_AUTOMATIC_STOPPING_CRITERIONS: if stop_crit == 1: msg = "STOPPING CRITERIA Nº1: PLEASE STOP TASK AND REMOVE MOUSE\ \n < 400 trials in 45min" f.patch.set_facecolor('xkcd:mint green') elif stop_crit == 2: msg = "STOPPING CRITERIA Nº2: PLEASE STOP TASK AND REMOVE MOUSE\ \nMouse seems to be inactive" f.patch.set_facecolor('xkcd:yellow') elif stop_crit == 3: msg = "STOPPING CRITERIA Nº3: PLEASE STOP TASK AND REMOVE MOUSE\ \n> 90 minutes have passed since session start" f.patch.set_facecolor('xkcd:red') [log.warning(msg) for x in range(5)] bpod.close() if __name__ == '__main__': print('main')
state_name='FlashStimulus', state_timer=0.1, state_change_conditions={Bpod.Events.Tup: 'WaitForResponse'}, output_actions=[(stimulus, 255)]) sma.add_state( state_name='WaitForResponse', state_timer=1, state_change_conditions={Bpod.Events.Port1In: leftAction, Bpod.Events.Port3In: rightAction}, output_actions=[]) sma.add_state( state_name='Reward', state_timer=0.1, state_change_conditions={Bpod.Events.Tup: 'exit'}, output_actions=[(Bpod.OutputChannels.Valve, rewardValve)]) # Reward correct choice sma.add_state( state_name='Punish', state_timer=3, state_change_conditions={Bpod.Events.Tup: 'exit'}, output_actions=[(Bpod.OutputChannels.LED, 1), (Bpod.OutputChannels.LED, 2), (Bpod.OutputChannels.LED, 3)]) # Signal incorrect choice my_bpod.send_state_machine(sma) # Send state machine description to Bpod device print("Waiting for poke. Reward: ", 'left' if thisTrialType == 1 else 'right') my_bpod.run_state_machine(sma) # Run state machine print("Current trial info: {0}".format(my_bpod.session.current_trial)) my_bpod.close() # Disconnect Bpod
print("Set BNC output ch2 to high") my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.BNC, channel_number=2, value=1) time.sleep(0.01) # Wait 10ms print("Set BNC output ch2 to low") my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.BNC, channel_number=2, value=0) time.sleep(1) # Wait 1s ### PORT 3 Wire ### print("Set Wire output ch3 to high") my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.WIRE, channel_number=3, value=1) time.sleep(0.01) # Wait 10ms print("Set Wire output ch3 to low") my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.WIRE, channel_number=3, value=0) time.sleep(1) # Wait 1s ### PORT 2 Serial ### print("Send byte 65 on UART port 2") my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.SERIAL, channel_number=2, value=65) time.sleep(0.01) # Wait 10ms print("Send byte 66 on UART port 1") my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.SERIAL, channel_number=1, value=66) # Stop Bpod my_bpod.close() # Sends a termination byte and closes the serial port. PulsePal stores current params to its EEPROM.