def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_Dialog() self.ui.setupUi(self) # Set your serial Port/Baudrate/time between two value changes(in second) Here. self.device = copter('/dev/ttyUSB0', 19200, 0) #def event(self, event): #print event.type() #if (event.type()==QtCore.QEvent.KeyPress) and (event.key()==QtCore.Qt.Key_Tab): #self.emit(QtCore.SIGNAL("tabPressed")) #return True #QtCore.QObject.connect(self.ui.verticalSlider, QtCore.SIGNAL("sliderMoved(int)"), self.adjust_rotor) #QtCore.QObject.connect(self.ui.verticalSlider, QtCore.SIGNAL("valueChanged(int)"), self.adjust_rotor) QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), QtCore.QCoreApplication.instance().quit) QtCore.QObject.connect(self.ui.dial, QtCore.SIGNAL("leftPressed"), lambda: self.device.adjust_direction('x', '-')) QtCore.QObject.connect(self.ui.dial, QtCore.SIGNAL("rightPressed"), lambda: self.device.adjust_direction('x', '+')) QtCore.QObject.connect(self.ui.dial, QtCore.SIGNAL("downPressed"), lambda: self.device.adjust_direction('y', '-')) QtCore.QObject.connect(self.ui.dial, QtCore.SIGNAL("upPressed"), lambda: self.device.adjust_direction('y', '+')) QtCore.QObject.connect(self.ui.dial, QtCore.SIGNAL("rotorUp"), lambda: self.device.adjust_rotor('+')) QtCore.QObject.connect(self.ui.dial, QtCore.SIGNAL("rotorDown"), lambda: self.device.adjust_rotor('-')) QtCore.QObject.connect(self.ui.dial, QtCore.SIGNAL("directionReleased"), self.device.init_direction)
# Test the tracking function of the copter. import tracker from helicopter import copter import time; # Set center calibaration, assuming it now. range = 0.5 # set successive samples sleep_time = 0; #open up copter. device=copter('/dev/ttyUSB0', 19200, 0) def move(): x,y = tracker.track(); if x > range: if x > 0: value = '+' else: value = '-' device.adjust_direction('x', value) if y > range: if y > 0: value = '+' else: value = '-'