class MyRelay: def __init__(self, hub_serial, hub_port, relay_channel): self.updated_n = 0 self.relay = DigitalOutput() self.relay.setChannel(relay_channel) self.relay.setHubPort(hub_port) self.relay.setDeviceSerialNumber(hub_serial) self.relay_channel = relay_channel self.relay.openWaitForAttachment(5000) self.previous_duty_cycle = 100 def set_state(self, state): self.relay.setState(state) def set_duty_cycle(self, duty_cycle): try: diff = math.fabs(self.previous_duty_cycle - duty_cycle) if diff > 0.05: self.relay.setDutyCycle(duty_cycle) self.previous_duty_cycle = duty_cycle self.updated_n = self.updated_n + 1 except PhidgetException as exception: print('Error on relay channel', self.relay_channel, exception) self.reconnect() def __del__(self): self.relay.close()
class DigitalOutputChannel(): ''' Class used to set high or low voltages on Digital Output channels on IO boards ''' def __init__(self, deviceSN,channelNo): ''' Constructor for Digital Output channels. ''' #Attempt to attach tochannel self.deviceSN = deviceSN self.channelNo = channelNo self.attachChannel() def attachChannel(self): ''' Connect to Digital output channel testing ''' self.channel = DigitalOutput() self.channel.setDeviceSerialNumber(self.deviceSN) self.channel.setChannel(self.channelNo) self.channel.openWaitForAttachment(100) self.channel.setState(False) def setState(self,state): ''' Changes the output state of the channel between high and low using True and False ''' self.channel.setState(state)
class jigOutput(object): '''generic digital output on the jig''' def __init__(self, provider, channel, defaultState): self._defaultState = defaultState self.do = DigitalOutput() self.do.setDeviceSerialNumber(provider) self.do.setChannel(channel) self.do.setOnAttachHandler(self._attached) self.do.openWaitForAttachment(1000) def _attached(self, event): self.set(self._defaultState) @property def state(self): return self.do.getState() def set(self, state): self.do.setState(state) def reset(self): self.set(self._defaultState)
LED.setDeviceSerialNumber(437969) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) def onAttachHandler(e): print("Phidget attached!") LED.setOnAttachHandler(onAttachHandler) LED.setChannel(0) LED.openWaitForAttachment(5000) #Declare score score = 0 command = "" LED.setState(True) def gameLoop(command): #This function gets called when a round starts and one of the players need to input a command global score if (command == "lost"): print("Your score is %i!" % (score - 1)) score = 0 userMotor.close() randomMotor.close() LED.close() return elif (command == "right"): randomMotor.setTargetPosition(180) randomMotor.setEngaged(True)
class PneumaticFrame2: 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 toggle_pwr(self): #Turn on air channel if self.state == 0: #Turn on power to regulator and show active button color self.power.config(bg=self.activeColor) self.reg_switch.setState(True) if self.frame_name.get() == "Hydro": self.solenoid_switch.setState(True) #Start monitoring air pressure self.update_pressure() #Change state of air channel self.state = 1 #Turn off air channel elif self.state == 1: remember_state = self.set_pressure_scale.get() if self.frame_name.get() != "Hydro": messagebox.showinfo( self.frame_name.get() + " Warning", "Pressure will be set to zero. Acknowledge that " + self.frame_name.get() + " is in a safe configuration") # Change pressure to zero self.set_pressure_scale.set(0) self.set_pressure(0) time.sleep(0.5) self.frame.update() self.reg_switch.setState(False) time.sleep(0.5) self.set_pressure_scale.set(remember_state) if self.frame_name.get() == "Hydro": self.solenoid_switch.setState(False) self.lock.select() self.set_pressure_scale.config(state="disabled") self.power.config(state="disable") #Turn off power to reguluator and remove active button color self.power.config(bg="SystemButtonFace") #Update air channel state self.state = 0 def get_label_input(self): self.window = popupWindow(self.master) self.set_label.config(state=DISABLED) self.master.wait_window(self.window.top) self.set_label.config(state=NORMAL) #If the user does not enter a value exception will be produced try: if len(self.window.value) > 12: self.frame_name.set("SET ERROR") else: self.frame_name.set(self.window.value) except: self.frame_name.set("SET ERROR") def set_pressure(self, val): # Pressure Range range = MAXPR - MINPR # Calculate volts/PSI ratio = 5 / range self.pressure_ctrl.setVoltage(float(val) * ratio) def update_pressure(self): if self.reg_switch.getState(): try: val = float(self.pressure_reading.getSensorValue()) PSI = val * 165.63 - 30.855 PSI = round(PSI, 2) self.pressure.set(PSI) #Low pressure check if PSI < (self.set_pressure_scale.get() - 3): if self.frame.cget('bg') == "Red": self.frame.config(bg=self.frameColor) self.set_pressure_scale.config(bg=self.frameColor) self.custom_label.config(bg=self.frameColor) self.label.config(bg=self.frameColor) self.lock.config(bg=self.frameColor) else: self.frame.config(bg='Red') self.set_pressure_scale.config(bg="Red") self.custom_label.config(bg="Red") self.label.config(bg="Red") self.lock.config(bg="Red") if PSI > (self.set_pressure_scale.get() - 3): if self.frame.cget('bg') == "Red": self.frame.config(bg=self.frameColor) self.set_pressure_scale.config(bg=self.frameColor) self.custom_label.config(bg=self.frameColor) self.label.config(bg=self.frameColor) self.lock.config(bg=self.frameColor) except: print("Init Air Pressure") root.after(200, self.update_pressure) else: self.pressure.set("") def lock(self): if self.lock_flag.get() == True: self.set_pressure_scale.config(state="disabled") self.power.config(state="disable") elif self.lock_flag.get() == False: self.set_pressure_scale.config(state="normal") self.power.config(state="normal")
class ControlFrame: 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")) def toggle_power(self): if self.power.getState() == True: self.power.setState(False) self.btn_power.config(bg="SystemButtonFace") elif self.power.getState() == False: self.power.setState(True) self.btn_power.config(bg=self.activeColor) def update_left_intensity(self, val): self.left_light.setVoltage(float(val)) def update_right_intensity(self, val): self.right_light.setVoltage(float(val)) def focus(self, direction): if direction == "+": self.near.setState(TRUE) elif direction == "-": self.far.setState(TRUE) elif direction == "0": self.far.setState(FALSE) self.near.setState(FALSE) def zoom(self, direction): if direction == "+": self.tele.setState(TRUE) elif direction == "-": self.wide.setState(TRUE) elif direction == "0": self.tele.setState(FALSE) self.wide.setState(FALSE) def pan_move(self, direction): voltage = float(self.pan_speed.get()) if self.invert_pan.get(): voltage *= -1 if direction == "R": self.pan.setVoltage(voltage) elif direction == "L": self.pan.setVoltage(-1 * voltage) elif direction == "0": self.pan.setVoltage(0) def tilt_move(self, direction): voltage = float(self.tilt_speed.get()) if self.invert_tilt.get(): voltage *= -1 if direction == "+": self.tilt.setVoltage(voltage) elif direction == "-": self.tilt.setVoltage(-1 * voltage) elif direction == "0": self.tilt.setVoltage(0) def focus_type(self, state): if state == "ON": self.manual_select.setState(True) elif state == "OFF": self.manual_select.setState(False)
from Phidget22.Phidget import * from Phidget22.Devices.DigitalOutput import * from Phidget22.Devices.DigitalInput import * import time serial_number = 95358 digitalOutput = DigitalOutput() digitalOutput.setChannel(4) digitalOutput.openWaitForAttachment(5000) digitalOutput.setState(0) digitalOutput.setDeviceSerialNumber(serial_number) while True: res = input() if (res == "on"): digitalOutput.setState(1) elif (res == "off"): digitalOutput.setState(0) elif (res == "quit"): break digitalOutput.close()
class ControlFrame: 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) # Methods for Tool Camera def toggle_power_1(self): if self.power_1.getState() == True: self.power_1.setState(False) self.btn_power_1.config(bg="SystemButtonFace") elif self.power_1.getState() == False: self.power_1.setState(True) self.btn_power_1.config(bg=self.activeColor_1) def update_left_intensity_1(self, val): self.left_light_1.setVoltage(float(val)) def update_right_intensity_1(self, val): self.right_light_1.setVoltage(float(val)) def focus_1(self, direction): if direction == "+": self.near_1.setState(TRUE) elif direction == "-": self.far_1.setState(TRUE) elif direction == "0": self.far_1.setState(FALSE) self.near_1.setState(FALSE) def zoom_1(self, direction): if direction == "+": self.tele_1.setState(TRUE) elif direction == "-": self.wide_1.setState(TRUE) elif direction == "0": self.tele_1.setState(FALSE) self.wide_1.setState(FALSE) def pan_move_1(self, direction): voltage = float(self.pan_speed_1.get()) if self.invert_pan_1.get(): voltage *= -1 if direction == "R": self.pan_1.setVoltage(voltage) elif direction == "L": self.pan_1.setVoltage(-1 * voltage) elif direction == "0": self.pan_1.setVoltage(0) def tilt_move_1(self, direction): voltage = float(self.tilt_speed_1.get()) if self.invert_tilt_1.get(): voltage *= -1 if direction == "+": self.tilt_1.setVoltage(voltage) elif direction == "-": self.tilt_1.setVoltage(-1 * voltage) elif direction == "0": self.tilt_1.setVoltage(0) def focus_type_1(self, state): if state == "ON": self.manual_select_1.setState(True) elif state == "OFF": self.manual_select_1.setState(False) # Methods for Overview Camera def toggle_power_2(self): if self.power_2.getState() == True: self.power_2.setState(False) self.btn_power_2.config(bg="SystemButtonFace") elif self.power_2.getState() == False: self.power_2.setState(True) self.btn_power_2.config(bg=self.activeColor_2) def update_left_intensity_2(self, val): self.left_light_2.setVoltage(float(val)) def update_right_intensity_2(self, val): self.right_light_2.setVoltage(float(val)) def focus_2(self, direction): if direction == "+": self.near_2.setState(TRUE) elif direction == "-": self.far_2.setState(TRUE) elif direction == "0": self.far_2.setState(FALSE) self.near_2.setState(FALSE) def zoom_2(self, direction): if direction == "+": self.tele_2.setState(TRUE) elif direction == "-": self.wide_2.setState(TRUE) elif direction == "0": self.tele_2.setState(FALSE) self.wide_2.setState(FALSE) def pan_move_2(self, direction): voltage = float(self.pan_speed_2.get()) if self.invert_pan_2.get(): voltage *= -1 if direction == "R": self.pan_2.setVoltage(voltage) elif direction == "L": self.pan_2.setVoltage(-1 * voltage) elif direction == "0": self.pan_2.setVoltage(0) def tilt_move_2(self, direction): voltage = float(self.tilt_speed_2.get()) if self.invert_tilt_2.get(): voltage *= -1 if direction == "+": self.tilt_2.setVoltage(voltage) elif direction == "-": self.tilt_2.setVoltage(-1 * voltage) elif direction == "0": self.tilt_2.setVoltage(0) def focus_type_2(self, state): if state == "ON": self.manual_select_2.setState(True) elif state == "OFF": self.manual_select_2.setState(False)
class Multiplexer: def __init__(self): print('init mp') try: self.ch0 = DigitalOutput() self.ch1 = DigitalOutput() self.ch2 = DigitalOutput() self.ch3 = DigitalOutput() self.ch4 = DigitalOutput() self.ch5 = DigitalOutput() self.ch6 = DigitalOutput() self.ch7 = DigitalOutput() except RuntimeError as e: print("Runtime Exception %s" % e.details) print("Press Enter to Exit...\n") raise def ErrorEvent(self, e, eCode, description): print("Error %i : %s" % (eCode, description)) try: self.ch0.setOnErrorHandler(ErrorEvent) self.ch1.setOnErrorHandler(ErrorEvent) self.ch2.setOnErrorHandler(ErrorEvent) self.ch3.setOnErrorHandler(ErrorEvent) self.ch4.setOnErrorHandler(ErrorEvent) self.ch5.setOnErrorHandler(ErrorEvent) self.ch6.setOnErrorHandler(ErrorEvent) self.ch7.setOnErrorHandler(ErrorEvent) self.ch0.setChannel(0) self.ch1.setChannel(1) self.ch2.setChannel(2) self.ch3.setChannel(3) self.ch4.setChannel(4) self.ch5.setChannel(5) self.ch6.setChannel(6) self.ch7.setChannel(7) print( "Waiting for the Phidget DigitalOutput Objects to be attached..." ) self.ch0.openWaitForAttachment(5000) self.ch1.openWaitForAttachment(5000) self.ch2.openWaitForAttachment(5000) self.ch3.openWaitForAttachment(5000) self.ch4.openWaitForAttachment(5000) self.ch5.openWaitForAttachment(5000) self.ch6.openWaitForAttachment(5000) self.ch7.openWaitForAttachment(5000) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Press Enter to Exit...\n") raise def SelectChannel(self, channel): self.ch0.setState(0) self.ch1.setState(0) self.ch2.setState(0) self.ch3.setState(0) self.ch4.setState(0) self.ch5.setState(0) self.ch6.setState(0) self.ch7.setState(0) if channel < 0: return if channel == 0: self.ch0.setState(1) if channel == 1: self.ch1.setState(1) if channel == 2: self.ch2.setState(1) if channel == 3: self.ch3.setState(1) if channel == 4: self.ch4.setState(1) if channel == 5: self.ch5.setState(1) if channel == 6: self.ch6.setState(1) if channel == 7: self.ch7.setState(1) time.sleep(10) def ChannelsOff(self): self.SelectChannel(-1) def close(self): try: self.ch0.close() self.ch1.close() self.ch2.close() self.ch3.close() self.ch4.close() self.ch5.close() self.ch6.close() self.ch7.close() except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Press Enter to Exit...\n") raise print("Closed DigitalOutput device")