コード例 #1
0
import random

# 类实例化
hardware_info = Hardware()
results_info = Results()
if WORK_ON_RPI:
    # drawer_hard = MotorAction('托盘', [31, 33, 35, 37], [12, 16, 18, 22], 8000)
    # lifting_hard = MotorAction('抬升', [32, 36, 38, 40], [13, 15, 7, 11], 3200)
    drawer_hard = MotorAction('托盘', [31, 33, 35, 37], [12, 16, 18, 22], 6000)
    time.sleep(0.01)
    lifting_hard = MotorAction('抬升', [32, 36, 38, 40], [13, 15, 7, 11], 4000)
    # drawer_hard = MotorAction('托盘', [32, 36, 38, 40], [7, 11, 7, 11], 400)
    # lifting_hard = MotorAction('抬升', [31, 33, 35, 37], [7, 11, 7, 11], 400)
    weight_hard = WeightSensor('/dev/ttyAMA0')
    time.sleep(0.01)
    light_hard = Light(21)
    time.sleep(0.01)
    light_plate_hard = Light(23)
    time.sleep(0.01)
    fan_hard = Fan(29)
    printer_hard = Printer("/dev/ttyUSB0")


class ActionName:
    PLATE_IN = ActionNameType('托盘收回')
    PLATE_OUT = ActionNameType('托盘弹出')
    PLATE_UP = ActionNameType('托盘复位')
    PLATE_DOWN = ActionNameType('托盘下降')
    WEIGHT = ActionNameType('称重/去皮')
    LIGHT_ON = ActionNameType('打开灯')
    LIGHT_OFF = ActionNameType('关闭灯')
コード例 #2
0
    def __init__(self, session_params, mp285=None, actuator=None):
        self.params = self.DEFAULT_PARAMS

        # incorporate kwargs
        self.params.update(session_params)
        self.__dict__.update(self.params)
        self.verify_params()

        # sync
        self.sync_flag = multiprocessing.Value('b', False)
        self.sync_to_save = multiprocessing.Queue()

        # saver
        self.saver = Saver(self.subj,
                           self.name,
                           self,
                           sync_flag=self.sync_flag)

        # hardware
        self.cam = PSEye(sync_flag=self.sync_flag, **self.cam_params)
        self.ar = AnalogReader(saver_obj_buffer=self.saver.buf,
                               sync_flag=self.sync_flag,
                               **self.ar_params)
        self.stimulator = Valve(saver=self.saver,
                                name='stimulator',
                                **self.stimulator_params)
        self.spout = Valve(saver=self.saver, name='spout', **self.spout_params)
        self.light = Light(saver=self.saver, **self.light_params)
        self.light.set(0)
        self.opto = Opto(saver=self.saver, **self.opto_params)
        self.speaker = Speaker(saver=self.saver)

        # mp285, actuator
        self.mp285 = mp285
        self.actuator = actuator
        self.actuator.saver = self.saver
        self.mp285_go(self.position_stim)
        if self.retract_ports:
            self.actuator.retract()
            #self.mp285_go(self.position_stim)
        else:
            self.actuator.extend()
            #self.mp285_go(self.position_lick)

        # communication
        self.sic = SICommunicator(self.imaging)

        # trials
        self.th = TrialHandler(saver=self.saver,
                               condition=self.condition,
                               **self.trial_params)

        # runtime variables
        self.stdinerr = None
        self.notes = {}
        self.session_on = 0
        self.session_complete = False
        self.session_kill = False
        self.session_runtime = -1
        self.trial_runtime = -1
        self.rewards_given = 0
        self.paused = 0
        self.holding = False
        self.current_phase = PHASE_INTRO
        self.live_figure = None

        # sync
        self.sync_flag.value = True  #trigger all processes to get time
        self.sync_val = now()  #get this process's time
        procs = dict(saver=self.saver, cam=self.cam.pseye, ar=self.ar)
        sync_vals = {o: procs[o].sync_val.value
                     for o in procs}  #collect all process times
        sync_vals['session'] = self.sync_val
        self.sync_to_save.put(sync_vals)