Exemplo n.º 1
0
    def __init__(self, param=DefaultParam):

        self.param = param
        self.experiment = self.param['experiment']
        self.experiment_time = self.param['experiment_time']
        self.time_start = time.time()

        # Set up Phidget channels
        self.aout_channel_yaw = 0
        self.aout_channel_x = 1
        self.aout_channel_yaw_gain = 2
        self.aout_channel_y = 3
        self.aout_max_volt = 10.0
        self.aout_min_volt = 0.0

        # Setup analog output YAW
        self.aout_yaw = VoltageOutput()
        self.aout_yaw.setChannel(self.aout_channel_yaw)
        self.aout_yaw.openWaitForAttachment(5000)
        self.aout_yaw.setVoltage(0.0)

        # Setup analog output X
        self.aout_x = VoltageOutput()
        self.aout_x.setChannel(self.aout_channel_x)
        self.aout_x.openWaitForAttachment(5000)
        self.aout_x.setVoltage(0.0)

        # Setup analog output YAW gain
        self.aout_yaw_gain = VoltageOutput()
        self.aout_yaw_gain.setChannel(self.aout_channel_yaw_gain)
        self.aout_yaw_gain.openWaitForAttachment(5000)
        self.aout_yaw_gain.setVoltage(0.0)

        # Setup analog output Y
        self.aout_y = VoltageOutput()
        self.aout_y.setChannel(self.aout_channel_y)
        self.aout_y.openWaitForAttachment(5000)
        self.aout_y.setVoltage(0.0)

        self.print = True

        # Set up socket info
        self.HOST = '127.0.0.1'  # The (receiving) host IP address (sock_host)
        self.PORT = 65432  # The (receiving) host port (sock_port)

        self.done = False

        self.gain_yaw = 1
        self.heading_with_gain = 0

        self.jump = True
        self.time_between_jumps = 90
        self.jump_size = 0

        #set up logger to save hd5f file
        self.logger = H5Logger(
            filename=self.param['logfile_name'],
            auto_incr=self.param['logfile_auto_incr'],
            auto_incr_format=self.param['logfile_auto_incr_format'],
            param_attr=self.param)
Exemplo n.º 2
0
def get_device_channel(serial_number, channel):
    try:
        """
        * Allocate a new Phidget Channel object
        """
        ch = VoltageOutput()
        """
        * Set matching parameters to specify which channel to open
        """
        #You may remove this line and hard-code the addressing parameters to fit your application

        ch.setDeviceSerialNumber(serial_number)
        ch.setIsHubPortDevice(False)
        ch.setChannel(channel)
        """
        * Add event handlers before calling open so that no events are missed.
        """
        print("\n--------------------------------------")
        print("\nSetting OnAttachHandler...")
        ch.setOnAttachHandler(onAttachHandler)

        print("Setting OnDetachHandler...")
        ch.setOnDetachHandler(onDetachHandler)

        print("Setting OnErrorHandler...")
        ch.setOnErrorHandler(onErrorHandler)
        """
        * Open the channel with a timeout
        """
        print("\nOpening and Waiting for Attachment...")

        try:
            ch.openWaitForAttachment(5000)
        except PhidgetException as e:
            PrintOpenErrorMessage(e, ch)
            raise EndProgramSignal("Program Terminated: Open Failed")

        # ch.setVoltage(voltage)
        '''
        * Perform clean up and exit
        '''

        return ch

    except:
        pass
Exemplo n.º 3
0
    def __init__(self, param=DefaultParam):

        self.param = param
        self.experiment = self.param['experiment']
        self.stim_speed = self.param['stim_speed']
        self.turn_type = self.param['turn_type']
        self.bar_offset = self.param[
            'bar_offset']  # bar relative to wind [deg]
        self.experiment_time = self.param['experiment_time']
        self.time_start = time.time(
        )  # get the current time and use it as a ref for elapsed time
        self.stim_dir = 0
        self.offset_adjust = 15  # use this offset to make bars perfectly aligned to wind, hard coded (deg)
        self.fly_heading = 0  # for calculating heading of the fly (rad)
        self.first_time_in_loop = True

        self.print = True  # for printing the current values on the console

        # specify the time epochs in the experiment
        self.time_baseline = 10  # [s] baseline period
        self.epoch_dur = 200  # [s] duration of an individual epoch
        self.epoch_num = 6  # total number of epochs

        # set voltage range for Phidget
        self.aout_max_volt = 10.0
        self.aout_min_volt = 0.0

        # set up two Phidgets
        self.phidget_vision = 525577  # for writing Fictrac x, y, and panels (yaw_gain)
        self.phidget_wind = 589946  # for sending the position of the motor to NI-DAQ, actual animal yaw

        # Set up Phidget channels in device 1 for vision (0-index)
        self.aout_channel_ydimension = 0
        self.aout_channel_x = 1
        self.aout_channel_y = 3
        self.aout_channel_yaw_gain = 2

        # Setup analog output X
        self.aout_x = VoltageOutput()
        self.aout_x.setDeviceSerialNumber(self.phidget_vision)
        self.aout_x.setChannel(self.aout_channel_x)
        self.aout_x.openWaitForAttachment(5000)
        self.aout_x.setVoltage(0.0)

        # Setup analog output Y
        self.aout_y = VoltageOutput()
        self.aout_y.setDeviceSerialNumber(self.phidget_vision)
        self.aout_y.setChannel(self.aout_channel_y)
        self.aout_y.openWaitForAttachment(5000)
        self.aout_y.setVoltage(0.0)

        # Setup analog output YAW (use this channel to turn panels on and off)
        self.aout_ydim = VoltageOutput()
        self.aout_ydim.setDeviceSerialNumber(self.phidget_vision)
        self.aout_ydim.setChannel(self.aout_channel_ydimension)
        self.aout_ydim.openWaitForAttachment(5000)
        self.aout_ydim.setVoltage(0.0)

        # Setup analog output YAW gain (use this channel to control panel bar position)
        self.aout_yaw_gain = VoltageOutput()
        self.aout_yaw_gain.setDeviceSerialNumber(self.phidget_vision)
        self.aout_yaw_gain.setChannel(self.aout_channel_yaw_gain)
        self.aout_yaw_gain.openWaitForAttachment(5000)
        self.aout_yaw_gain.setVoltage(0.0)

        # Set up Phidget channels in device 2 for wind (0-index)
        self.aout_channel_motor = 0
        self.aout_channel_yaw = 1  # for recording the actual yaw of the fly
        self.aout_channel_wind_valve = 2

        # Setup analog output motor
        self.aout_motor = VoltageOutput()
        self.aout_motor.setDeviceSerialNumber(self.phidget_wind)
        self.aout_motor.setChannel(self.aout_channel_motor)
        self.aout_motor.openWaitForAttachment(5000)
        self.aout_motor.setVoltage(0.0)

        # Setup analog output for yaw
        self.aout_yaw = VoltageOutput()
        self.aout_yaw.setDeviceSerialNumber(self.phidget_wind)
        self.aout_yaw.setChannel(self.aout_channel_yaw)
        self.aout_yaw.openWaitForAttachment(5000)
        self.aout_yaw.setVoltage(0.0)

        # Setup analog output wind valve
        self.aout_wind_valve = VoltageOutput()
        self.aout_wind_valve.setDeviceSerialNumber(self.phidget_wind)
        self.aout_wind_valve.setChannel(self.aout_channel_wind_valve)
        self.aout_wind_valve.openWaitForAttachment(5000)
        self.aout_wind_valve.setVoltage(0.0)

        # Set up socket info for connecting with the FicTrac
        self.HOST = '127.0.0.1'  # The (receiving) host IP address (sock_host)
        self.PORT = 65432  # The (receiving) host port (sock_port)

        # Set up Arduino connection
        self.COM = 'COM4'  # serial port
        self.baudrate = 115200  # 9600
        self.serialTimeout = 0.001  # blocking timeout for readline()

        # flag for indicating when the trial is done
        self.done = False

        #set up logger to save hd5f file
        self.logger_fictrac = H5Logger(
            filename=self.param['logfile_name'],
            auto_incr=self.param['logfile_auto_incr'],
            auto_incr_format=self.param['logfile_auto_incr_format'],
            param_attr=self.param)

        #set up logger to save hd5f file
        self.logger_arduino = H5Logger(
            filename=(self.param['logfile_name']).replace(
                '.hdf5', '_arduino.hdf5'),
            auto_incr=self.param['logfile_auto_incr'],
            auto_incr_format=self.param['logfile_auto_incr_format'],
            param_attr=self.param)
Exemplo n.º 4
0
    def __init__(self, master, initial_name, top_name, color, sol, reg_pwr,
                 reg_set, reg_get, PSI):
        self.frame = Frame(master, borderwidth=2, relief=SUNKEN, bg=color)
        self.frame.pack()
        self.master = master
        self.frame_name = StringVar()
        self.frame_name.set(initial_name)
        self.state = 0
        self.fontType = "Comic Sans"
        self.activeColor = 'SpringGreen4'
        self.frameColor = color

        self.pressure = IntVar()
        self.lock_flag = IntVar()
        self.pressure.set("")

        self.power = Button(self.frame,
                            text="PWR",
                            activebackground=self.activeColor,
                            command=lambda: self.toggle_pwr())
        self.set_label = Button(self.frame,
                                text="SET LABEL",
                                font=(self.fontType, 7),
                                command=lambda: self.get_label_input())
        self.observed_pressure = Entry(self.frame,
                                       width=5,
                                       state="readonly",
                                       textvariable=self.pressure)
        if self.frame_name.get() == "Hydro":
            self.set_pressure_scale = Scale(self.frame,
                                            orient=HORIZONTAL,
                                            from_=0,
                                            to=92,
                                            resolution=0.5,
                                            bg=color,
                                            label="Set Pressure (PSI)",
                                            highlightthickness=0,
                                            command=self.set_pressure)
        else:
            self.set_pressure_scale = Scale(self.frame,
                                            orient=HORIZONTAL,
                                            from_=0,
                                            to=50,
                                            resolution=0.5,
                                            bg=color,
                                            label="Set Pressure (PSI)",
                                            highlightthickness=0,
                                            command=self.set_pressure)
        self.custom_label = Label(self.frame,
                                  textvariable=self.frame_name,
                                  font=(self.fontType, 14),
                                  bg=color)
        self.label = Label(self.frame, text=initial_name, bg=color)
        self.lock = Checkbutton(self.frame,
                                text="LOCK",
                                bg=color,
                                variable=self.lock_flag,
                                command=self.lock)
        self.frame_name.set(top_name)

        # Init the pressure scale to the default value.
        self.set_pressure_scale.set(PSI)
        # Lock hydo at startup
        if initial_name == "Hydro":
            self.lock.select()
            self.set_pressure_scale.config(state="disabled")
            self.power.config(state="disable")

        self.frame.rowconfigure(0, minsize=30)
        self.custom_label.grid(row=0, column=0, columnspan=2, sticky=S)
        self.set_label.grid(column=0, row=1, columnspan=2)
        self.frame.rowconfigure(2, minsize=50)
        self.power.grid(column=0, row=2)
        self.observed_pressure.grid(column=1, row=2)
        self.set_pressure_scale.grid(column=0, row=3, columnspan=2, padx=20)
        self.frame.rowconfigure(4, minsize=5)
        self.label.grid(column=0, row=5)
        self.lock.grid(column=1, row=5)

        # Connect to Phidget Solid State Relay for solinoid control
        if self.frame_name.get() == "Hydro":
            self.solenoid_switch = DigitalOutput()
            self.solenoid_switch.setDeviceSerialNumber(sol[0])
            self.solenoid_switch.setIsHubPortDevice(False)
            self.solenoid_switch.setHubPort(sol[1])
            self.solenoid_switch.setChannel(sol[2])
            self.solenoid_switch.openWaitForAttachment(5000)

        #Connect to Phidget Solid State Relay for regulator power control
        self.reg_switch = DigitalOutput()
        self.reg_switch.setDeviceSerialNumber(reg_pwr[0])
        self.reg_switch.setIsHubPortDevice(False)
        self.reg_switch.setHubPort(reg_pwr[1])
        self.reg_switch.setChannel(reg_pwr[2])
        self.reg_switch.openWaitForAttachment(5000)

        #Connect to Phidget Voltage Ouptut for pressure control
        self.pressure_ctrl = VoltageOutput()
        self.pressure_ctrl.setDeviceSerialNumber(reg_set[0])
        self.pressure_ctrl.setIsHubPortDevice(False)
        self.pressure_ctrl.setHubPort(reg_set[1])
        self.pressure_ctrl.setChannel(reg_set[2])
        self.pressure_ctrl.openWaitForAttachment(5000)

        #Connect to Phidget Analog Input for pressure reading
        self.pressure_reading = VoltageRatioInput()
        self.pressure_reading.setDeviceSerialNumber(reg_get[0])

        #One of the VINT Hubs on the SBC is used and needs special configuration
        if reg_get[0] == SBCH:
            self.pressure_reading.setIsHubPortDevice(True)
            self.pressure_reading.setHubPort(0)

        self.pressure_reading.setChannel(reg_get[1])
        self.pressure_reading.openWaitForAttachment(5000)
    def __init__(self, master, colorArray):
        frame1 = Frame(master, borderwidth=2, relief=SUNKEN)
        frame2 = Frame(master, borderwidth=2, relief=SUNKEN)
        frame3 = Frame(master, borderwidth=2, relief=SUNKEN)
        frame4 = Frame(master, borderwidth=2, relief=SUNKEN)
        frame5 = Frame(master, borderwidth=2, relief=SUNKEN)
        frame6 = Frame(master, borderwidth=2, relief=SUNKEN)
        frame7 = Frame(master, borderwidth=2, relief=SUNKEN)
        camera_frame = Frame(master, borderwidth=2, relief=SUNKEN)

        frame1.grid(row=1, column=0)
        frame2.grid(row=1, column=1)
        frame3.grid(row=1, column=2)
        frame4.grid(row=1, column=3)
        frame5.grid(row=1, column=4)
        frame6.grid(row=1, column=5)
        frame7.grid(row=1, column=6)
        camera_frame.grid(row=3, column=0, columnspan=7, sticky=W)

        self.out1 = AxisFrame(frame1, "BASE CIRC", "VESSEL RIGHT",
                              "VESSEL LEFT", HUB1, 5, colorArray[0], 3.3, 0.55)
        self.out2 = AxisFrame(frame2, "BASE AUX", "CW/IN", "CCW/OUT", HUB2, 0,
                              colorArray[1], 2.2, 0.11)
        self.out3 = AxisFrame(frame3, "VARD ROT", "CW", "CCW", HUB1, 3,
                              colorArray[2], 2.2, 0.15)
        self.out4 = AxisFrame(frame4, "VARD VERT", "UP", "DOWN", HUB1, 4,
                              colorArray[3], 7.8, 0.54)
        self.out5 = AxisFrame(frame5, "DA MAST", "UP", "DOWN", HUB1, 0,
                              colorArray[4], 8, 0.86)
        self.out6 = AxisFrame(frame6, "DA PAN", "CW", "CCW", HUB1, 2,
                              colorArray[5], 3.0, 0.30)
        self.out7 = AxisFrame(frame7, "DA TILT", "UP", "DOWN", HUB1, 1,
                              colorArray[6], 3.6, 0.57)

        #RJ Camera Control Code
        self.invert_tilt = BooleanVar()
        self.invert_pan = BooleanVar()
        self.btn_power = Button(camera_frame,
                                text="PWR",
                                font="Courier, 12",
                                command=self.toggle_power)
        self.btn_near = Button(camera_frame,
                               text="NEAR",
                               font="Courier, 12",
                               width=7)
        self.btn_far = Button(camera_frame,
                              text="FAR",
                              font="Courier, 12",
                              width=7)
        self.btn_wide = Button(camera_frame,
                               text="WIDE",
                               font="Courier, 12",
                               width=7)
        self.btn_tele = Button(camera_frame,
                               text="TELE",
                               font="Courier, 12",
                               width=7)
        self.btn_ms = Button(camera_frame,
                             text="MS",
                             font="Courier, 12",
                             width=7)
        self.left_light_scale = Scale(camera_frame,
                                      orient=VERTICAL,
                                      from_=0,
                                      to=0.45,
                                      resolution=0.01,
                                      command=self.update_left_intensity)
        self.right_light_scale = Scale(camera_frame,
                                       orient=VERTICAL,
                                       from_=0,
                                       to=0.45,
                                       resolution=0.01,
                                       command=self.update_right_intensity)
        self.label_lights = Label(camera_frame, text="  Light Intensity")
        self.btn_tilt_up = Button(camera_frame,
                                  text="TILT UP",
                                  font="Courier, 12",
                                  width=10)
        self.btn_tilt_down = Button(camera_frame,
                                    text="TILT DOWN",
                                    font="Courier, 12",
                                    width=10)
        self.btn_pan_right = Button(camera_frame,
                                    text="PAN RIGHT",
                                    font="Courier, 12",
                                    width=10)
        self.btn_pan_left = Button(camera_frame,
                                   text="PAN LEFT",
                                   font="Courier, 12",
                                   width=10)
        self.tilt_speed = Scale(camera_frame,
                                orient=HORIZONTAL,
                                from_=0.01,
                                to=.5,
                                resolution=0.01)
        self.pan_speed = Scale(camera_frame,
                               orient=HORIZONTAL,
                               from_=0.01,
                               to=.5,
                               resolution=0.01)
        self.ckbx_invert_tilt = Checkbutton(camera_frame,
                                            text="Invert Tilt",
                                            variable=self.invert_tilt)
        self.ckbx_invert_pan = Checkbutton(camera_frame,
                                           text="Invert Pan",
                                           variable=self.invert_pan)
        self.activeColor = 'SpringGreen4'

        self.tilt_speed.set(0.15)
        self.pan_speed.set(0.15)

        self.btn_power.grid(row=0, column=0, padx=60)
        self.btn_ms.grid(row=1, column=0, padx=5, pady=5)
        self.btn_near.grid(row=0, column=2, padx=20, pady=10)
        self.btn_far.grid(row=1, column=2, padx=20, pady=10)
        self.btn_tele.grid(row=0, column=3, padx=20, pady=10)
        self.btn_wide.grid(row=1, column=3, padx=20, pady=10)
        self.left_light_scale.grid(row=0, column=4, rowspan=3, padx=20, pady=5)
        self.right_light_scale.grid(row=0,
                                    column=5,
                                    rowspan=3,
                                    padx=45,
                                    pady=5)
        self.label_lights.grid(row=3,
                               column=4,
                               columnspan=2,
                               padx=45,
                               sticky=N)
        self.btn_tilt_up.grid(row=0, column=6, padx=20, pady=5)
        self.btn_tilt_down.grid(row=1, column=6, padx=20, pady=5)
        self.btn_pan_right.grid(row=0, column=8, padx=20, pady=5, rowspan=2)
        self.btn_pan_left.grid(row=0, column=7, padx=20, pady=5, rowspan=2)
        self.tilt_speed.grid(row=2, column=6)
        self.pan_speed.grid(row=2, column=7, columnspan=2)
        self.ckbx_invert_tilt.grid(row=3, column=6)
        self.ckbx_invert_pan.grid(row=3, column=7, columnspan=2)

        #Connect to Phidget Devices
        self.power = DigitalOutput()
        self.power.setDeviceSerialNumber(HUB2)
        self.power.setIsHubPortDevice(False)
        self.power.setHubPort(1)
        self.power.setChannel(0)
        self.power.openWaitForAttachment(5000)

        self.manual_select = DigitalOutput()
        self.manual_select.setDeviceSerialNumber(HUB2)
        self.manual_select.setIsHubPortDevice(False)
        self.manual_select.setHubPort(1)
        self.manual_select.setChannel(1)
        self.manual_select.openWaitForAttachment(5000)

        self.near = DigitalOutput()
        self.near.setDeviceSerialNumber(HUB2)
        self.near.setIsHubPortDevice(False)
        self.near.setHubPort(1)
        self.near.setChannel(2)
        self.near.openWaitForAttachment(5000)

        self.far = DigitalOutput()
        self.far.setDeviceSerialNumber(HUB2)
        self.far.setIsHubPortDevice(False)
        self.far.setHubPort(1)
        self.far.setChannel(3)
        self.far.openWaitForAttachment(5000)

        self.wide = DigitalOutput()
        self.wide.setDeviceSerialNumber(HUB2)
        self.wide.setIsHubPortDevice(False)
        self.wide.setHubPort(1)
        self.wide.setChannel(4)
        self.wide.openWaitForAttachment(5000)

        self.tele = DigitalOutput()
        self.tele.setDeviceSerialNumber(HUB2)
        self.tele.setIsHubPortDevice(False)
        self.tele.setHubPort(1)
        self.tele.setChannel(5)
        self.tele.openWaitForAttachment(5000)

        self.left_light = VoltageOutput()
        self.left_light.setDeviceSerialNumber(HUB2)
        self.left_light.setIsHubPortDevice(False)
        self.left_light.setHubPort(2)
        self.left_light.setChannel(0)
        self.left_light.openWaitForAttachment(5000)

        self.right_light = VoltageOutput()
        self.right_light.setDeviceSerialNumber(HUB2)
        self.right_light.setIsHubPortDevice(False)
        self.right_light.setHubPort(3)
        self.right_light.setChannel(0)
        self.right_light.openWaitForAttachment(5000)

        self.pan = VoltageOutput()
        self.pan.setDeviceSerialNumber(HUB2)
        self.pan.setIsHubPortDevice(False)
        self.pan.setHubPort(5)
        self.pan.setChannel(0)
        self.pan.openWaitForAttachment(5000)

        self.tilt = VoltageOutput()
        self.tilt.setDeviceSerialNumber(HUB2)
        self.tilt.setIsHubPortDevice(False)
        self.tilt.setHubPort(4)
        self.tilt.setChannel(0)
        self.tilt.openWaitForAttachment(5000)

        self.btn_near.bind('<ButtonPress-1>', lambda event: self.focus("+"))
        self.btn_near.bind('<ButtonRelease-1>', lambda event: self.focus("0"))
        self.btn_far.bind('<ButtonPress-1>', lambda event: self.focus("-"))
        self.btn_far.bind('<ButtonRelease-1>', lambda event: self.focus("0"))
        self.btn_wide.bind('<ButtonPress-1>', lambda event: self.zoom("-"))
        self.btn_wide.bind('<ButtonRelease-1>', lambda event: self.zoom("0"))
        self.btn_tele.bind('<ButtonPress-1>', lambda event: self.zoom("+"))
        self.btn_tele.bind('<ButtonRelease-1>', lambda event: self.zoom("0"))
        self.btn_ms.bind('<ButtonPress-1>',
                         lambda event: self.focus_type("ON"))
        self.btn_ms.bind('<ButtonRelease-1>',
                         lambda event: self.focus_type("OFF"))

        self.btn_tilt_up.bind('<ButtonPress-1>',
                              lambda event: self.tilt_move("-"))
        self.btn_tilt_up.bind('<ButtonRelease-1>',
                              lambda event: self.tilt_move("0"))
        self.btn_tilt_down.bind('<ButtonPress-1>',
                                lambda event: self.tilt_move("+"))
        self.btn_tilt_down.bind('<ButtonRelease-1>',
                                lambda event: self.tilt_move("0"))
        self.btn_pan_right.bind('<ButtonPress-1>',
                                lambda event: self.pan_move("R"))
        self.btn_pan_right.bind('<ButtonRelease-1>',
                                lambda event: self.pan_move("0"))
        self.btn_pan_left.bind('<ButtonPress-1>',
                               lambda event: self.pan_move("L"))
        self.btn_pan_left.bind('<ButtonRelease-1>',
                               lambda event: self.pan_move("0"))
Exemplo n.º 6
0
    def __init__(self, param=DefaultParam):

        self.param = param
        self.experiment = self.param['experiment']
        self.experiment_time = self.param['experiment_time']
        self.time_start = time.time()

        # Set up Phidget channels
        self.aout_channel_ydimension = 0  #I'm setting up a channel such that I can change the y dimension of the panels sending a signal through here
        self.aout_channel_x = 1
        self.aout_channel_yaw_gain = 2
        self.aout_channel_y = 3
        self.aout_max_volt = 10.0
        self.aout_min_volt = 0.0

        # Set up Phidget serial numbers for using two devices
        self.phidget_vision = 525577  # written on the back of the Phidget
        self.phidget_wind = 589946  # for sending the position of the motor to NI-DAQ

        # Setup analog output YAW
        self.aout_ydim = VoltageOutput()
        self.aout_ydim.setDeviceSerialNumber(self.phidget_vision)
        self.aout_ydim.setChannel(self.aout_channel_ydimension)
        self.aout_ydim.openWaitForAttachment(5000)
        self.aout_ydim.setVoltage(0.0)

        # Setup analog output X
        self.aout_x = VoltageOutput()
        self.aout_x.setDeviceSerialNumber(self.phidget_vision)
        self.aout_x.setChannel(self.aout_channel_x)
        self.aout_x.openWaitForAttachment(5000)
        self.aout_x.setVoltage(0.0)

        # Setup analog output YAW gain
        self.aout_yaw_gain = VoltageOutput()
        self.aout_yaw_gain.setDeviceSerialNumber(self.phidget_vision)
        self.aout_yaw_gain.setChannel(self.aout_channel_yaw_gain)
        self.aout_yaw_gain.openWaitForAttachment(5000)
        self.aout_yaw_gain.setVoltage(0.0)

        # Setup analog output Y
        self.aout_y = VoltageOutput()
        self.aout_y.setDeviceSerialNumber(self.phidget_vision)
        self.aout_y.setChannel(self.aout_channel_y)
        self.aout_y.openWaitForAttachment(5000)
        self.aout_y.setVoltage(9.0)

        # Set up Phidget channels in device 2 for wind
        self.aout_channel_motor = 0
        self.aout_channel_wind_valve = 2

        # Setup analog output motor
        self.aout_motor = VoltageOutput()
        self.aout_motor.setDeviceSerialNumber(self.phidget_wind)
        self.aout_motor.setChannel(self.aout_channel_motor)
        self.aout_motor.openWaitForAttachment(5000)
        self.aout_motor.setVoltage(0.0)

        # Setup analog output wind valve
        self.aout_wind_valve = VoltageOutput()
        self.aout_wind_valve.setDeviceSerialNumber(self.phidget_wind)
        self.aout_wind_valve.setChannel(self.aout_channel_wind_valve)
        self.aout_wind_valve.openWaitForAttachment(5000)
        self.aout_wind_valve.setVoltage(0.0)

        self.print = True

        # Set up socket info
        self.HOST = '127.0.0.1'  # The (receiving) host IP address (sock_host)
        self.PORT = 65432  # The (receiving) host port (sock_port)

        # Set up Arduino connection
        self.COM = 'COM4'  # serial port
        self.baudrate = 115200  # 9600
        self.serialTimeout = 0.001  # blocking timeout for readline()

        self.done = False

        self.gain_yaw = 1
        self.heading_with_gain = 0

        self.bar_jump = True
        self.bar_jump_size = 0
        self.wind_jump = True
        self.wind_jump_size = 0

        #initialize the bar on and the wind off
        self.bar = False
        self.wind = True

        #initialize heading with respect to panels to be starting position
        self.motor_command = 0
        self.bar_position = np.deg2rad(360 - self.param['offset'])

        #set up logger to save hd5f file
        self.logger_fictrac = H5Logger(
            filename=self.param['logfile_name'],
            auto_incr=self.param['logfile_auto_incr'],
            auto_incr_format=self.param['logfile_auto_incr_format'],
            param_attr=self.param)

        #set up logger to save hd5f file
        self.logger_arduino = H5Logger(
            filename=(self.param['logfile_name']).replace(
                '.hdf5', '_arduino.hdf5'),
            auto_incr=self.param['logfile_auto_incr'],
            auto_incr_format=self.param['logfile_auto_incr_format'],
            param_attr=self.param)

        #specify a variable for the first message being read
        self.first_time_in_loop = True
Exemplo n.º 7
0
    def __init__(self, param=DefaultParam):

        self.param = param
        self.experiment = self.param['experiment']
        self.experiment_time = self.param['experiment_time']
        self.time_start = time.time(
        )  # get the current time and use it as a ref for elapsed time

        #get gain for the panels and wind
        self.gain_panels = self.param['gain_panels']
        self.gain_wind = self.param['gain_wind']

        # Set up Phidget serial numbers for using two devices
        self.phidget_vision = 525577  # written on the back of the Phidget
        self.phidget_wind = 589946  # for sending the position of the motor to NI-DAQ

        # Set up Phidget channels in device 1 for vision (0-index)
        self.aout_channel_yaw = 0
        self.aout_channel_x = 1
        self.aout_channel_yaw_gain = 2
        self.aout_channel_y = 3
        self.aout_max_volt = 10.0
        self.aout_min_volt = 0.0

        # Setup analog output YAW
        self.aout_yaw = VoltageOutput()
        self.aout_yaw.setDeviceSerialNumber(self.phidget_vision)
        self.aout_yaw.setChannel(self.aout_channel_yaw)
        self.aout_yaw.openWaitForAttachment(5000)
        self.aout_yaw.setVoltage(0.0)

        # Setup analog output X
        self.aout_x = VoltageOutput()
        self.aout_x.setDeviceSerialNumber(self.phidget_vision)
        self.aout_x.setChannel(self.aout_channel_x)
        self.aout_x.openWaitForAttachment(5000)
        self.aout_x.setVoltage(0.0)

        # Setup analog output YAW gain
        self.aout_yaw_gain = VoltageOutput()
        self.aout_yaw_gain.setDeviceSerialNumber(self.phidget_vision)
        self.aout_yaw_gain.setChannel(self.aout_channel_yaw_gain)
        self.aout_yaw_gain.openWaitForAttachment(5000)
        self.aout_yaw_gain.setVoltage(0.0)

        # Setup analog output Y
        self.aout_y = VoltageOutput()
        self.aout_y.setDeviceSerialNumber(self.phidget_vision)
        self.aout_y.setChannel(self.aout_channel_y)
        self.aout_y.openWaitForAttachment(5000)
        self.aout_y.setVoltage(0.0)

        # Set up Phidget channels in device 2 for wind (0-index)
        self.aout_channel_motor = 0
        self.aout_channel_wind_valve = 2

        # Setup analog output motor
        self.aout_motor = VoltageOutput()
        self.aout_motor.setDeviceSerialNumber(self.phidget_wind)
        self.aout_motor.setChannel(self.aout_channel_motor)
        self.aout_motor.openWaitForAttachment(5000)
        self.aout_motor.setVoltage(0.0)

        # Setup analog output wind valve
        self.aout_wind_valve = VoltageOutput()
        self.aout_wind_valve.setDeviceSerialNumber(self.phidget_wind)
        self.aout_wind_valve.setChannel(self.aout_channel_wind_valve)
        self.aout_wind_valve.openWaitForAttachment(5000)
        self.aout_wind_valve.setVoltage(0.0)

        self.print = True

        # Set up socket info for connecting with the FicTrac
        self.HOST = '127.0.0.1'  # The (receiving) host IP address (sock_host)
        self.PORT = 65432  # The (receiving) host port (sock_port)

        # Set up Arduino connection
        self.COM = 'COM4'  # serial port
        self.baudrate = 115200  # 9600
        self.serialTimeout = 0.001  # blocking timeout for readline()

        # flag for indicating when the trial is done
        self.done = False

        #initialize heading with respect to panels to be starting position
        self.motor_command = 0
        self.bar_position = np.deg2rad(360 - self.param['offset'])

        self.jump = True
        self.time_between_jumps = 90  # [s]
        self.jump_mag = 90  # [deg] jump magnitude
        self.jump_size = 0  # default value is zero

        #set up logger to save hd5f file
        self.logger_fictrac = H5Logger(
            filename=self.param['logfile_name'],
            auto_incr=self.param['logfile_auto_incr'],
            auto_incr_format=self.param['logfile_auto_incr_format'],
            param_attr=self.param)

        #set up logger to save hd5f file
        self.logger_arduino = H5Logger(
            filename=(self.param['logfile_name']).replace(
                '.hdf5', '_arduino.hdf5'),
            auto_incr=self.param['logfile_auto_incr'],
            auto_incr_format=self.param['logfile_auto_incr_format'],
            param_attr=self.param)

        #specify a variable for the first message being read
        self.first_time_in_loop = True
Exemplo n.º 8
0
    def __init__(self, param=DefaultParam):

        self.param = param
        self.experiment = self.param['experiment']
        self.stim_speed = self.param['stim_speed']
        self.turn_type = self.param['turn_type']
        self.experiment_time = self.param['experiment_time']
        self.time_start = time.time(
        )  # get the current time and use it as a ref for elapsed time
        self.current_wind_dir = 0

        # Set up Phidget serial numbers for using two devices
        self.phidget_vision = 525577  # written on the back of the Phidget
        self.phidget_wind = 589946  # for sending the position of the motor to NI-DAQ

        # Set up Phidget channels in device 1 for vision (0-index)
        self.aout_channel_yaw = 0
        self.aout_channel_x = 1
        self.aout_channel_yaw_gain = 2
        self.aout_channel_y = 3
        self.aout_max_volt = 10.0
        self.aout_min_volt = 0.0

        # Setup analog output YAW
        self.aout_yaw = VoltageOutput()
        self.aout_yaw.setDeviceSerialNumber(self.phidget_vision)
        self.aout_yaw.setChannel(self.aout_channel_yaw)
        self.aout_yaw.openWaitForAttachment(5000)
        self.aout_yaw.setVoltage(0.0)

        # Setup analog output X
        self.aout_x = VoltageOutput()
        self.aout_x.setDeviceSerialNumber(self.phidget_vision)
        self.aout_x.setChannel(self.aout_channel_x)
        self.aout_x.openWaitForAttachment(5000)
        self.aout_x.setVoltage(0.0)

        # Setup analog output YAW gain
        self.aout_yaw_gain = VoltageOutput()
        self.aout_yaw_gain.setDeviceSerialNumber(self.phidget_vision)
        self.aout_yaw_gain.setChannel(self.aout_channel_yaw_gain)
        self.aout_yaw_gain.openWaitForAttachment(5000)
        self.aout_yaw_gain.setVoltage(0.0)

        # Setup analog output Y
        self.aout_y = VoltageOutput()
        self.aout_y.setDeviceSerialNumber(self.phidget_vision)
        self.aout_y.setChannel(self.aout_channel_y)
        self.aout_y.openWaitForAttachment(5000)
        self.aout_y.setVoltage(0.0)

        # Set up Phidget channels in device 2 for wind (0-index)
        self.aout_channel_motor = 0
        self.aout_channel_wind_valve = 2

        # Setup analog output motor
        self.aout_motor = VoltageOutput()
        self.aout_motor.setDeviceSerialNumber(self.phidget_wind)
        self.aout_motor.setChannel(self.aout_channel_motor)
        self.aout_motor.openWaitForAttachment(5000)
        self.aout_motor.setVoltage(0.0)

        # Setup analog output wind valve
        self.aout_wind_valve = VoltageOutput()
        self.aout_wind_valve.setDeviceSerialNumber(self.phidget_wind)
        self.aout_wind_valve.setChannel(self.aout_channel_wind_valve)
        self.aout_wind_valve.openWaitForAttachment(5000)
        self.aout_wind_valve.setVoltage(0.0)

        self.print = True

        # Set up socket info for connecting with the FicTrac
        self.HOST = '127.0.0.1'  # The (receiving) host IP address (sock_host)
        self.PORT = 65432  # The (receiving) host port (sock_port)

        # Set up Arduino connection
        self.COM = 'COM4'  # serial port
        self.baudrate = 115200  # 9600
        self.serialTimeout = 0.001  # blocking timeout for readline()

        # flag for indicating when the trial is done
        self.done = False

        #set up logger to save hd5f file
        self.logger_fictrac = H5Logger(
            filename=self.param['logfile_name'],
            auto_incr=self.param['logfile_auto_incr'],
            auto_incr_format=self.param['logfile_auto_incr_format'],
            param_attr=self.param)

        #set up logger to save hd5f file
        self.logger_arduino = H5Logger(
            filename=(self.param['logfile_name']).replace(
                '.hdf5', '_arduino.hdf5'),
            auto_incr=self.param['logfile_auto_incr'],
            auto_incr_format=self.param['logfile_auto_incr_format'],
            param_attr=self.param)
Exemplo n.º 9
0
right_light.openWaitForAttachment(5000)
right_light.setAcceleration(20)

#Setup pan and tilt motors
tilt = DCMotor()
tilt.setDeviceSerialNumber(465371)
tilt.openWaitForAttachment(1000)
tilt.setAcceleration(ACCEL)

pan = DCMotor()
pan.setDeviceSerialNumber(469502)
pan.openWaitForAttachment(1000)
pan.setAcceleration(ACCEL)

#Setup Pnematics
pressure_ctrl = VoltageOutput()
pressure_ctrl.setDeviceSerialNumber(540047)
pressure_ctrl.setIsHubPortDevice(False)
pressure_ctrl.setHubPort(3)
pressure_ctrl.setChannel(0)
pressure_ctrl.openWaitForAttachment(5000)

pressure_reading = VoltageRatioInput()
pressure_reading.setDeviceSerialNumber(540047)
pressure_reading.setIsHubPortDevice(False)
pressure_reading.setHubPort(0)
pressure_reading.setChannel(0)
pressure_reading.openWaitForAttachment(5000)

solenoid = DigitalOutput()
solenoid.setDeviceSerialNumber(540047)
Exemplo n.º 10
0
    def __init__(self, param=DefaultParam):

        self.param = param
        self.experiment = self.param['experiment']
        self.experiment_time = self.param['experiment_time']
        self.time_start = time.time()

        # Set up Phidget channels
        self.aout_channel_ydimension = 0
        self.aout_channel_x = 1
        self.aout_channel_yaw_gain = 2
        self.aout_channel_y = 3
        self.aout_max_volt = 10.0
        self.aout_min_volt = 0.0

        # Set up Phidget serial numbers for using two devices
        self.phidget_vision = 525577  # written on the back of the Phidget
        self.phidget_heading = 589946

        # Setup analog output y dim, to change the y dimension of the stimulus
        self.aout_ydim = VoltageOutput()
        self.aout_ydim.setDeviceSerialNumber(self.phidget_vision)
        self.aout_ydim.setChannel(self.aout_channel_ydimension)
        self.aout_ydim.openWaitForAttachment(5000)
        self.aout_ydim.setVoltage(0.0)

        # Setup analog output X
        self.aout_x = VoltageOutput()
        self.aout_x.setDeviceSerialNumber(self.phidget_vision)
        self.aout_x.setChannel(self.aout_channel_x)
        self.aout_x.openWaitForAttachment(5000)
        self.aout_x.setVoltage(0.0)

        # Setup analog output YAW gain
        self.aout_yaw_gain = VoltageOutput()
        self.aout_yaw_gain.setDeviceSerialNumber(self.phidget_vision)
        self.aout_yaw_gain.setChannel(self.aout_channel_yaw_gain)
        self.aout_yaw_gain.openWaitForAttachment(5000)
        self.aout_yaw_gain.setVoltage(0.0)

        # Setup analog output Y
        self.aout_y = VoltageOutput()
        self.aout_y.setDeviceSerialNumber(self.phidget_vision)
        self.aout_y.setChannel(self.aout_channel_y)
        self.aout_y.openWaitForAttachment(5000)
        self.aout_y.setVoltage(9.0)

        # Set up Phidget channels in device 2 to save the heading
        self.aout_heading_channel = 1

        # Setup analog output motor
        self.aout_heading = VoltageOutput()
        self.aout_heading.setDeviceSerialNumber(self.phidget_heading)
        self.aout_heading.setChannel(self.aout_heading_channel)
        self.aout_heading.openWaitForAttachment(5000)
        self.aout_heading.setVoltage(0.0)

        self.print = True

        # Set up socket info
        self.HOST = '127.0.0.1'  # The (receiving) host IP address (sock_host)
        self.PORT = 65432  # The (receiving) host port (sock_port)

        # Set up Arduino connection
        self.COM = 'COM4'  # serial port
        self.baudrate = 115200  # 9600
        self.serialTimeout = 0.001  # blocking timeout for readline()

        self.done = False

        self.gain_yaw = 1
        self.heading_with_gain = 0

        self.bar_jump = True
        self.bar_jump_size = 0

        #initialize the bar on
        self.bar = True
        self.bar_moving = True

        #define times when bar will be turned off
        self.turn_off_times = np.linspace(900, 3525, 26)
        #self.turn_off_times = np.linspace(30,300,7)   #uncomment for testing

        #initialize heading with respect to panels to be starting position
        self.bar_position = np.deg2rad(360 - self.param['offset'])

        #set up logger to save hd5f file
        self.logger_fictrac = H5Logger(
            filename=self.param['logfile_name'],
            auto_incr=self.param['logfile_auto_incr'],
            auto_incr_format=self.param['logfile_auto_incr_format'],
            param_attr=self.param)

        #specify a variable for the first message being read
        self.first_time_in_loop = True
Exemplo n.º 11
0
#!/usr/bin/env python3

from Phidget22.Phidget import *
from Phidget22.Devices.VoltageOutput import *
import sys
import time

experiment_time = float(sys.argv[1]) + 2.0  # adding two extra seconds

phidget_wind = 589946  # for sending the position of the motor to NI-DAQ
aout_channel_wind_valve = 2

aout_wind_valve = VoltageOutput()
aout_wind_valve.setDeviceSerialNumber(phidget_wind)
aout_wind_valve.setChannel(aout_channel_wind_valve)
aout_wind_valve.openWaitForAttachment(5000)
aout_wind_valve.setVoltage(0.0)

time_start = time.time() 

print(f'Turning MFC on for {experiment_time} seconds')

while True:
    time_elapsed = time.time() - time_start
    aout_wind_valve.setVoltage(5.0)
    if time_elapsed > experiment_time:
        aout_wind_valve.setVoltage(0.0)
        print('Turning MFC off')
        break
Exemplo n.º 12
0
    def __init__(self, master, colorArray):
        frame1 = Frame(master, borderwidth=2, relief=SUNKEN)
        frame2 = Frame(master, borderwidth=2, relief=SUNKEN)
        frame3 = Frame(master, borderwidth=2, relief=SUNKEN)
        frame4 = Frame(master, borderwidth=2, relief=SUNKEN)
        frame5 = Frame(master, borderwidth=2, relief=SUNKEN)
        frame6 = Frame(master, borderwidth=2, relief=SUNKEN)
        frame7 = Frame(master, borderwidth=2, relief=SUNKEN)
        camera_frame_1 = Frame(master, borderwidth=2, relief=SUNKEN, bg='LightSkyBlue2')
        camera_frame_2 = Frame(master, borderwidth=2, relief=SUNKEN, bg='light goldenrod yellow')

        frame1.grid(row=1, column=0)
        frame2.grid(row=1, column=1)
        frame3.grid(row=1, column=2)
        frame4.grid(row=1, column=3)
        frame5.grid(row=1, column=4)
        frame6.grid(row=1, column=5)
        frame7.grid(row=1, column=6)
        camera_frame_1.grid(row=3, column=0, columnspan=7, sticky=NSEW)
        camera_frame_2.grid(row=4, column=0, columnspan=7, sticky=NSEW)

        self.out1 = AxisFrame(frame1, "BASE CIRC", "VESSEL RIGHT", "VESSEL LEFT", HUB1, 5, colorArray[0], 3.3, 0.55)
        self.out2 = AxisFrame(frame2, "BASE AUX", "CW/IN", "CCW/OUT", HUB2, 0, colorArray[1], 2.2, 0.11)
        self.out3 = AxisFrame(frame3, "VARD ROT", "CW", "CCW", HUB1, 3, colorArray[2], 2.2, 0.15)
        self.out4 = AxisFrame(frame4, "VARD VERT", "UP", "DOWN", HUB1, 4, colorArray[3], 7.8, 0.54)
        self.out5 = AxisFrame(frame5, "DA MAST", "UP", "DOWN", HUB1, 0, colorArray[4], 8, 0.86)
        self.out6 = AxisFrame(frame6, "DA PAN", "CW", "CCW", HUB1, 2, colorArray[5], 3.0, 0.30)
        self.out7 = AxisFrame(frame7, "DA TILT", "UP", "DOWN", HUB1, 1, colorArray[6], 3.6, 0.57)

        # RJ Camera Control: Code Tool Camera
        self.invert_tilt_1 = BooleanVar()
        self.invert_pan_1 = BooleanVar()
        self.btn_power_1 = Button(camera_frame_1, text="PWR", font="Courier, 12", command=self.toggle_power_1)
        self.btn_near_1 = Button(camera_frame_1, text="NEAR", font="Courier, 12", width=7)
        self.btn_far_1 = Button(camera_frame_1, text="FAR", font="Courier, 12", width=7)
        self.btn_wide_1 = Button(camera_frame_1, text="WIDE", font="Courier, 12", width=7)
        self.btn_tele_1 = Button(camera_frame_1, text="TELE", font="Courier, 12", width=7)
        self.btn_ms_1 = Button(camera_frame_1, text="MS", font="Courier, 12", width=7)
        self.left_light_scale_1 = Scale(camera_frame_1, orient=VERTICAL, from_=0, to=0.45, resolution=0.01,
                                        command=self.update_left_intensity_1, bg='LightSkyBlue2', highlightthickness=0)
        self.right_light_scale_1 = Scale(camera_frame_1, orient=VERTICAL, from_=0, to=0.45, resolution=0.01,
                                         command=self.update_right_intensity_1, bg='LightSkyBlue2',
                                         highlightthickness=0)
        self.label_lights_1 = Label(camera_frame_1, text="  Light Intensity", bg='LightSkyBlue2')
        self.label_camera_type_1 = Label(camera_frame_1, text="TOOL CAMERA", font=("TkDefaultFont", 14),
                                         bg='LightSkyBlue2')
        self.btn_tilt_up_1 = Button(camera_frame_1, text="TILT UP", font="Courier, 12", width=10)
        self.btn_tilt_down_1 = Button(camera_frame_1, text="TILT DOWN", font="Courier, 12", width=10)
        self.btn_pan_right_1 = Button(camera_frame_1, text="PAN RIGHT", font="Courier, 12", width=10)
        self.btn_pan_left_1 = Button(camera_frame_1, text="PAN LEFT", font="Courier, 12", width=10)
        self.tilt_speed_1 = Scale(camera_frame_1, orient=HORIZONTAL, from_=0.01, to=.5, resolution=0.01,
                                  bg='LightSkyBlue2', highlightthickness=0)
        self.pan_speed_1 = Scale(camera_frame_1, orient=HORIZONTAL, from_=0.01, to=.5, resolution=0.01,
                                 bg='LightSkyBlue2', highlightthickness=0)
        self.ckbx_invert_tilt_1 = Checkbutton(camera_frame_1, text="Invert Tilt", variable=self.invert_tilt_1,
                                              bg='LightSkyBlue2')
        self.ckbx_invert_pan_1 = Checkbutton(camera_frame_1, text="Invert Pan", variable=self.invert_pan_1,
                                             bg='LightSkyBlue2')
        self.activeColor_1 = 'SpringGreen4'

        self.tilt_speed_1.set(0.15)
        self.pan_speed_1.set(0.15)

        # RJ Camera Control: Overview Camera
        self.invert_tilt_2 = BooleanVar()
        self.invert_pan_2 = BooleanVar()
        self.btn_power_2 = Button(camera_frame_2, text="PWR", font="Courier, 12", command=self.toggle_power_2)
        self.btn_near_2 = Button(camera_frame_2, text="NEAR", font="Courier, 12", width=7)
        self.btn_far_2 = Button(camera_frame_2, text="FAR", font="Courier, 12", width=7)
        self.btn_wide_2 = Button(camera_frame_2, text="WIDE", font="Courier, 12", width=7)
        self.btn_tele_2 = Button(camera_frame_2, text="TELE", font="Courier, 12", width=7)
        self.btn_ms_2 = Button(camera_frame_2, text="MS", font="Courier, 12", width=7)
        self.left_light_scale_2 = Scale(camera_frame_2, orient=VERTICAL, from_=0, to=0.45, resolution=0.01,
                                        command=self.update_left_intensity_2, bg='light goldenrod yellow',
                                        highlightthickness=0)
        self.right_light_scale_2 = Scale(camera_frame_2, orient=VERTICAL, from_=0, to=0.45, resolution=0.01,
                                         command=self.update_right_intensity_2, bg='light goldenrod yellow',
                                         highlightthickness=0)
        self.label_lights_2 = Label(camera_frame_2, text="  Light Intensity", bg='light goldenrod yellow')
        self.label_camera_type_2 = Label(camera_frame_2, text="OVERVIEW CAMERA", font=("TkDefaultFont", 14),
                                         bg='light goldenrod yellow')
        self.btn_tilt_up_2 = Button(camera_frame_2, text="TILT UP", font="Courier, 12", width=10)
        self.btn_tilt_down_2 = Button(camera_frame_2, text="TILT DOWN", font="Courier, 12", width=10)
        self.btn_pan_right_2 = Button(camera_frame_2, text="PAN RIGHT", font="Courier, 12", width=10)
        self.btn_pan_left_2 = Button(camera_frame_2, text="PAN LEFT", font="Courier, 12", width=10)
        self.tilt_speed_2 = Scale(camera_frame_2, orient=HORIZONTAL, from_=0.01, to=.5, resolution=0.01,
                                  bg='light goldenrod yellow', highlightthickness=0)
        self.pan_speed_2 = Scale(camera_frame_2, orient=HORIZONTAL, from_=0.01, to=.5, resolution=0.01,
                                 bg='light goldenrod yellow', highlightthickness=0)
        self.ckbx_invert_tilt_2 = Checkbutton(camera_frame_2, text="Invert Tilt", variable=self.invert_tilt_2,
                                              bg='light goldenrod yellow')
        self.ckbx_invert_pan_2 = Checkbutton(camera_frame_2, text="Invert Pan", variable=self.invert_pan_2,
                                             bg='light goldenrod yellow')
        self.activeColor_2 = 'SpringGreen4'

        self.tilt_speed_2.set(0.15)
        self.pan_speed_2.set(0.15)

        # Grid the Tool Camera Controls
        self.btn_power_1.grid(row=0, column=0, padx=60)
        self.btn_ms_1.grid(row=1, column=0, padx=5, pady=5)
        self.btn_near_1.grid(row=0, column=2, padx=20, pady=10)
        self.btn_far_1.grid(row=1, column=2, padx=20, pady=10)
        self.btn_tele_1.grid(row=0, column=3, padx=20, pady=10)
        self.btn_wide_1.grid(row=1, column=3, padx=20, pady=10)
        self.label_camera_type_1.grid(row=2, column=0, columnspan=4)
        self.left_light_scale_1.grid(row=0, column=4, rowspan=3, padx=20, pady=5)
        self.right_light_scale_1.grid(row=0, column=5, rowspan=3, padx=45, pady=5)
        self.label_lights_1.grid(row=3, column=4, columnspan=2, padx=45, sticky=N)
        self.btn_tilt_up_1.grid(row=0, column=6, padx=20, pady=5)
        self.btn_tilt_down_1.grid(row=1, column=6, padx=20, pady=5)
        self.btn_pan_right_1.grid(row=0, column=8, padx=20, pady=5, rowspan=2)
        self.btn_pan_left_1.grid(row=0, column=7, padx=20, pady=5, rowspan=2)
        self.tilt_speed_1.grid(row=2, column=6)
        self.pan_speed_1.grid(row=2, column=7, columnspan=2)
        self.ckbx_invert_tilt_1.grid(row=3, column=6)
        self.ckbx_invert_pan_1.grid(row=3, column=7, columnspan=2)

        # Grid the Overview Camera Controls
        self.btn_power_2.grid(row=0, column=0, padx=60)
        self.btn_ms_2.grid(row=1, column=0, padx=5, pady=5)
        self.btn_near_2.grid(row=0, column=2, padx=20, pady=10)
        self.btn_far_2.grid(row=1, column=2, padx=20, pady=10)
        self.btn_tele_2.grid(row=0, column=3, padx=20, pady=10)
        self.btn_wide_2.grid(row=1, column=3, padx=20, pady=10)
        self.label_camera_type_2.grid(row=2, column=0, columnspan=4)
        self.left_light_scale_2.grid(row=0, column=4, rowspan=3, padx=20, pady=5)
        self.right_light_scale_2.grid(row=0, column=5, rowspan=3, padx=45, pady=5)
        self.label_lights_2.grid(row=3, column=4, columnspan=2, padx=45, sticky=N)
        self.btn_tilt_up_2.grid(row=0, column=6, padx=20, pady=5)
        self.btn_tilt_down_2.grid(row=1, column=6, padx=20, pady=5)
        self.btn_pan_right_2.grid(row=0, column=8, padx=20, pady=5, rowspan=2)
        self.btn_pan_left_2.grid(row=0, column=7, padx=20, pady=5, rowspan=2)
        self.tilt_speed_2.grid(row=2, column=6)
        self.pan_speed_2.grid(row=2, column=7, columnspan=2)
        self.ckbx_invert_tilt_2.grid(row=3, column=6)
        self.ckbx_invert_pan_2.grid(row=3, column=7, columnspan=2)

        # Connect to Phidget Devices for Tool Camera
        self.power_1 = DigitalOutput()
        self.power_1.setDeviceSerialNumber(HUB2)
        self.power_1.setIsHubPortDevice(False)
        self.power_1.setHubPort(1)
        self.power_1.setChannel(0)
        try:
            self.power_1.openWaitForAttachment(1000)
        except PhidgetException as e:
            print("Failed to open (CAM POWER): " + e.details)

        self.manual_select_1 = DigitalOutput()
        self.manual_select_1.setDeviceSerialNumber(HUB2)
        self.manual_select_1.setIsHubPortDevice(False)
        self.manual_select_1.setHubPort(1)
        self.manual_select_1.setChannel(1)
        try:
            self.manual_select_1.openWaitForAttachment(1000)
        except PhidgetException as e:
            print("Failed to open (Manual Select): " + e.details)

        self.near_1 = DigitalOutput()
        self.near_1.setDeviceSerialNumber(HUB2)
        self.near_1.setIsHubPortDevice(False)
        self.near_1.setHubPort(1)
        self.near_1.setChannel(2)
        try:
            self.near_1.openWaitForAttachment(1000)
        except PhidgetException as e:
            print("Failed to open (NEAR): " + e.details)

        self.far_1 = DigitalOutput()
        self.far_1.setDeviceSerialNumber(HUB2)
        self.far_1.setIsHubPortDevice(False)
        self.far_1.setHubPort(1)
        self.far_1.setChannel(3)
        try:
            self.far_1.openWaitForAttachment(1000)
        except PhidgetException as e:
            print("Failed to open (FAR): " + e.details)

        self.wide_1 = DigitalOutput()
        self.wide_1.setDeviceSerialNumber(HUB2)
        self.wide_1.setIsHubPortDevice(False)
        self.wide_1.setHubPort(1)
        self.wide_1.setChannel(4)
        try:
            self.wide_1.openWaitForAttachment(1000)
        except PhidgetException as e:
            print("Failed to open (WIDE): " + e.details)

        self.tele_1 = DigitalOutput()
        self.tele_1.setDeviceSerialNumber(HUB2)
        self.tele_1.setIsHubPortDevice(False)
        self.tele_1.setHubPort(1)
        self.tele_1.setChannel(5)
        try:
            self.tele_1.openWaitForAttachment(1000)
        except PhidgetException as e:
            print("Failed to open (TELE): " + e.details)

        self.left_light_1 = VoltageOutput()
        self.left_light_1.setDeviceSerialNumber(HUB2)
        self.left_light_1.setIsHubPortDevice(False)
        self.left_light_1.setHubPort(2)
        self.left_light_1.setChannel(0)
        try:
            self.left_light_1.openWaitForAttachment(1000)
        except PhidgetException as e:
            print("Failed to open (LEFT LIGHT): " + e.details)

        self.right_light_1 = VoltageOutput()
        self.right_light_1.setDeviceSerialNumber(HUB2)
        self.right_light_1.setIsHubPortDevice(False)
        self.right_light_1.setHubPort(3)
        self.right_light_1.setChannel(0)
        try:
            self.right_light_1.openWaitForAttachment(1000)
        except PhidgetException as e:
            print("Failed to open (RIGHT LIGHT): " + e.details)

        self.pan_1 = VoltageOutput()
        self.pan_1.setDeviceSerialNumber(HUB2)
        self.pan_1.setIsHubPortDevice(False)
        self.pan_1.setHubPort(5)
        self.pan_1.setChannel(0)
        try:
            self.pan_1.openWaitForAttachment(1000)
        except PhidgetException as e:
            print("Failed to open (PAN): " + e.details)

        self.tilt_1 = VoltageOutput()
        self.tilt_1.setDeviceSerialNumber(HUB2)
        self.tilt_1.setIsHubPortDevice(False)
        self.tilt_1.setHubPort(4)
        self.tilt_1.setChannel(0)
        try:
            self.tilt_1.openWaitForAttachment(1000)
        except PhidgetException as e:
            print("Failed to open (TILT): " + e.details)

        self.btn_near_1.bind('<ButtonPress-1>', lambda event: self.focus_1("+"))
        self.btn_near_1.bind('<ButtonRelease-1>', lambda event: self.focus_1("0"))
        self.btn_far_1.bind('<ButtonPress-1>', lambda event: self.focus_1("-"))
        self.btn_far_1.bind('<ButtonRelease-1>', lambda event: self.focus_1("0"))
        self.btn_wide_1.bind('<ButtonPress-1>', lambda event: self.zoom_1("-"))
        self.btn_wide_1.bind('<ButtonRelease-1>', lambda event: self.zoom_1("0"))
        self.btn_tele_1.bind('<ButtonPress-1>', lambda event: self.zoom_1("+"))
        self.btn_tele_1.bind('<ButtonRelease-1>', lambda event: self.zoom_1("0"))
        self.btn_ms_1.bind('<ButtonPress-1>', lambda event: self.focus_type_1("ON"))
        self.btn_ms_1.bind('<ButtonRelease-1>', lambda event: self.focus_type_1("OFF"))

        self.btn_tilt_up_1.bind('<ButtonPress-1>', lambda event: self.tilt_move_1("-"))
        self.btn_tilt_up_1.bind('<ButtonRelease-1>', lambda event: self.tilt_move_1("0"))
        self.btn_tilt_down_1.bind('<ButtonPress-1>', lambda event: self.tilt_move_1("+"))
        self.btn_tilt_down_1.bind('<ButtonRelease-1>', lambda event: self.tilt_move_1("0"))
        self.btn_pan_right_1.bind('<ButtonPress-1>', lambda event: self.pan_move_1("R"))
        self.btn_pan_right_1.bind('<ButtonRelease-1>', lambda event: self.pan_move_1("0"))
        self.btn_pan_left_1.bind('<ButtonPress-1>', lambda event: self.pan_move_1("L"))
        self.btn_pan_left_1.bind('<ButtonRelease-1>', lambda event: self.pan_move_1("0"))

        # Connect to Phidget Devices for Overview Camera
        self.power_2 = DigitalOutput()
        self.power_2.setDeviceSerialNumber(HUB2)
        self.power_2.setIsHubPortDevice(False)
        self.power_2.setHubPort(1)
        self.power_2.setChannel(0)
        try:
            self.power_2.openWaitForAttachment(1000)
        except PhidgetException as e:
            print("Failed to open (CAM POWER): " + e.details)

        self.manual_select_2 = DigitalOutput()
        self.manual_select_2.setDeviceSerialNumber(HUB2)
        self.manual_select_2.setIsHubPortDevice(False)
        self.manual_select_2.setHubPort(1)
        self.manual_select_2.setChannel(1)
        try:
            self.manual_select_2.openWaitForAttachment(1000)
        except PhidgetException as e:
            print("Failed to open (Manual Select): " + e.details)

        self.near_2 = DigitalOutput()
        self.near_2.setDeviceSerialNumber(HUB2)
        self.near_2.setIsHubPortDevice(False)
        self.near_2.setHubPort(1)
        self.near_2.setChannel(2)
        try:
            self.near_2.openWaitForAttachment(1000)
        except PhidgetException as e:
            print("Failed to open (NEAR): " + e.details)

        self.far_2 = DigitalOutput()
        self.far_2.setDeviceSerialNumber(HUB2)
        self.far_2.setIsHubPortDevice(False)
        self.far_2.setHubPort(1)
        self.far_2.setChannel(3)
        try:
            self.far_2.openWaitForAttachment(1000)
        except PhidgetException as e:
            print("Failed to open (FAR): " + e.details)

        self.wide_2 = DigitalOutput()
        self.wide_2.setDeviceSerialNumber(HUB2)
        self.wide_2.setIsHubPortDevice(False)
        self.wide_2.setHubPort(1)
        self.wide_2.setChannel(4)
        try:
            self.wide_2.openWaitForAttachment(1000)
        except PhidgetException as e:
            print("Failed to open (WIDE): " + e.details)

        self.tele_2 = DigitalOutput()
        self.tele_2.setDeviceSerialNumber(HUB2)
        self.tele_2.setIsHubPortDevice(False)
        self.tele_2.setHubPort(1)
        self.tele_2.setChannel(5)
        try:
            self.tele_2.openWaitForAttachment(1000)
        except PhidgetException as e:
            print("Failed to open (TELE): " + e.details)

        self.left_light_2 = VoltageOutput()
        self.left_light_2.setDeviceSerialNumber(HUB2)
        self.left_light_2.setIsHubPortDevice(False)
        self.left_light_2.setHubPort(2)
        self.left_light_2.setChannel(0)
        try:
            self.left_light_2.openWaitForAttachment(1000)
        except PhidgetException as e:
            print("Failed to open (LEFT LIGHT): " + e.details)

        self.right_light_2 = VoltageOutput()
        self.right_light_2.setDeviceSerialNumber(HUB2)
        self.right_light_2.setIsHubPortDevice(False)
        self.right_light_2.setHubPort(3)
        self.right_light_2.setChannel(0)
        try:
            self.right_light_2.openWaitForAttachment(1000)
        except PhidgetException as e:
            print("Failed to open (RIGHT LIGHT): " + e.details)

        self.pan_2 = VoltageOutput()
        self.pan_2.setDeviceSerialNumber(HUB2)
        self.pan_2.setIsHubPortDevice(False)
        self.pan_2.setHubPort(5)
        self.pan_2.setChannel(0)
        try:
            self.pan_2.openWaitForAttachment(1000)
        except PhidgetException as e:
            print("Failed to open (PAN): " + e.details)

        self.tilt_2 = VoltageOutput()
        self.tilt_2.setDeviceSerialNumber(HUB2)
        self.tilt_2.setIsHubPortDevice(False)
        self.tilt_2.setHubPort(4)
        self.tilt_2.setChannel(0)
        try:
            self.tilt_2.openWaitForAttachment(1000)
        except PhidgetException as e:
            print("Failed to open (TILT): " + e.details)
# The following is from the 'init' part of analogout.py (https://github.com/jennyl617/fly_experiments/blob/master/fictrac_2d/analogout.py)

# *********** Set up aout params ***********

rate_to_volt_const = 50,
aout_max_volt = 10.0,
aout_min_volt = 0.0,
aout_max_volt_vel = 10.0,
aout_min_volt_vel = 0.0,
lowpass_cutoff = 0.5,

# *********** Set up analog output channels ***********

# Setup analog output 'runSpeed' - inst. running speed in rads/frame
aout_runSpeed = VoltageOutput()
aout_runSpeed.setChannel(0)
aout_runSpeed.openWaitForAttachment(5000)
aout_runSpeed.setVoltage(0.0)
aout_runSpeed.setDeviceSerialNumber(525438)

# Setup analog output 'animalheading360' -- this will be fly heading in degrees (0-3.6V) as in open loop trials
aout_animalheading360 = VoltageOutput()
aout_animalheading360.setChannel(1)
aout_animalheading360.openWaitForAttachment(5000)
aout_animalheading360.setVoltage(0.0)
aout_animalheading360.setDeviceSerialNumber(525438)

# xpos command to controller
aout_xposcmd = VoltageOutput()
aout_xposcmd.setChannel(2)
Exemplo n.º 14
0
    def __init__(self, param=DefaultParam):

        self.param = param
        self.experiment = self.param['experiment']
        self.experiment_time = self.param['experiment_time']
        self.time_start = time.time()

        # Set up Phidget channels
        self.aout_channel_yaw = 0
        self.aout_channel_x = 1
        self.aout_channel_yaw_gain = 2
        self.aout_channel_y = 3
        self.aout_max_volt = 10.0
        self.aout_min_volt = 0.0

        # Set up Phidget serial numbers for using two devices
        self.phidget_vision = 525577  # written on the back of the Phidget
        self.phidget_wind = 589946  # for sending the position of the motor to NI-DAQ

        # Setup analog output YAW
        self.aout_yaw = VoltageOutput()
        self.aout_yaw.setDeviceSerialNumber(self.phidget_vision)
        self.aout_yaw.setChannel(self.aout_channel_yaw)
        self.aout_yaw.openWaitForAttachment(5000)
        self.aout_yaw.setVoltage(0.0)

        # Setup analog output X
        self.aout_x = VoltageOutput()
        self.aout_x.setDeviceSerialNumber(self.phidget_vision)
        self.aout_x.setChannel(self.aout_channel_x)
        self.aout_x.openWaitForAttachment(5000)
        self.aout_x.setVoltage(0.0)

        # Setup analog output YAW gain
        self.aout_yaw_gain = VoltageOutput()
        self.aout_yaw_gain.setDeviceSerialNumber(self.phidget_vision)
        self.aout_yaw_gain.setChannel(self.aout_channel_yaw_gain)
        self.aout_yaw_gain.openWaitForAttachment(5000)
        self.aout_yaw_gain.setVoltage(0.0)

        # Setup analog output Y
        self.aout_y = VoltageOutput()
        self.aout_y.setDeviceSerialNumber(self.phidget_vision)
        self.aout_y.setChannel(self.aout_channel_y)
        self.aout_y.openWaitForAttachment(5000)
        self.aout_y.setVoltage(0.0)

        self.print = True

        # Set up socket info
        self.HOST = '127.0.0.1'  # The (receiving) host IP address (sock_host)
        #self.HOST = '10.119.97.141'
        self.PORT = 65432  # The (receiving) host port (sock_port)

        self.done = False

        # Set initial bar position
        self.bar_position = np.deg2rad(
            360 - self.param['offset'])  # right to the fly is +90 deg

        #set up logger to save hd5f file
        self.logger = H5Logger(
            filename=self.param['logfile_name'],
            auto_incr=self.param['logfile_auto_incr'],
            auto_incr_format=self.param['logfile_auto_incr_format'],
            param_attr=self.param)

        #specify a variable for the first message being read
        self.first_time_in_loop = True
Exemplo n.º 15
0
def endheatersignal():
    voltageOutput0 = VoltageOutput()
    voltageOutput0.close()
Exemplo n.º 16
0
    ch2.setDeviceSerialNumber(118651)
    ch2.setChannel(0)
    ch2.setOnAttachHandler(onAttachHandler)
    ch2.setOnTemperatureChangeHandler(onTemperatureChangeHandler)
    ch2.openWaitForAttachment(5000)
    temp9 = ch2.getTemperature() * 9 / 5 + 32
    temp8 = temp9
    #time.sleep(10)

    ch2.close()

    print("i got the temperature, its ", temp9)
    return temp8


voltageOutput0 = VoltageOutput()


def setheatersignal(heatersignal):
    global voltageOutput0
    voltageOutput0.openWaitForAttachment(5000)
    voltout = heatersignal / 100 * 5.0
    if voltout >= 0 and voltout <= 5.0:
        voltageOutput0.setVoltage(voltout)
    print("first")
    time.sleep(10)


    #voltageOutput0.close()
def endheatersignal():
    voltageOutput0 = VoltageOutput()