Exemple #1
0
 def __init__(self, parent=None):
     super(TestWindow, self).__init__(parent)
     self.setupUi(self)
     self.logo = LogoWidget(self)
     self.logoLayout.addWidget(self.logo)
     self.logo.setVisible(True)
     self.display_stats = False
     
     self.clickedButton = False
     
     # Attach event handler to bestButton
     self.bestButton.clicked.connect(self.bestClicked)
class MainWindow(QMainWindow, Ui_MainWindow):

    updGUI=pyqtSignal()
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        #self.teleop=TeleopWidget(self)
        #self.tlLayout.addWidget(self.teleop)
        #self.teleop.setVisible(True)
        self.pushButton.clicked.connect(self.playClicked)
        self.pushButton.setCheckable(True)
        self.updGUI.connect(self.updateGUI)
        self.camera1=CameraWidget(self)
        self.stopButton.clicked.connect(self.stopClicked)
        self.logo = LogoWidget(self)
        self.logoLayout.addWidget(self.logo)
        self.logo.setVisible(True)

    def updateGUI(self):
        #print ('update gui')
        self.camera1.updateImage()
        #self.sensorsWidget.sensorsUpdate.emit()
        #self.glWidget.update()

    def getSensor(self):
        return self.sensor

    def setSensor(self,sensor):
        self.sensor=sensor
        #self.camera1.initImages()

    def playClicked(self):
        self.sensor.setPlayButton(self.pushButton.isChecked())
        if self.pushButton.isChecked():
            self.pushButton.setText('RUNNING')
            self.pushButton.setStyleSheet("background-color: green")
        else:
            self.pushButton.setText('STOPPED')
            self.pushButton.setStyleSheet("background-color: red")

    def setAlgorithm(self, algorithm ):
        self.algorithm=algorithm

    def getAlgorithm(self):
        return self.algorithm

    def setXYValues(self,newX,newY):
        self.sensor.setV(-newY)
        self.sensor.setW(newX)

    def stopClicked(self):
        self.sensor.setV(0)
        self.sensor.setW(0)
 def __init__(self, parent=None):
     super(MainWindow, self).__init__(parent)
     self.setupUi(self)
     #self.teleop=TeleopWidget(self)
     #self.tlLayout.addWidget(self.teleop)
     #self.teleop.setVisible(True)
     self.pushButton.clicked.connect(self.playClicked)
     self.pushButton.setCheckable(True)
     self.updGUI.connect(self.updateGUI)
     self.camera1=CameraWidget(self)
     self.stopButton.clicked.connect(self.stopClicked)
     self.logo = LogoWidget(self)
     self.logoLayout.addWidget(self.logo)
     self.logo.setVisible(True)
Exemple #4
0
    def __init__(self, parent=None):
        super(TrainWindow, self).__init__(parent)
        self.setupUi(self)
        self.logo = LogoWidget(self)
        self.logoLayout.addWidget(self.logo)
        self.logo.setVisible(True)
        self.display_stats = False

        # Attach event handler to trainButton and generationButton
        self.trainButton.clicked.connect(self.trainClicked)
        self.trainButton.setCheckable(True)
        self.generationButton.clicked.connect(self.generationClicked)
        self.generationButton.setCheckable(True)

        self.updGUI.connect(self.updateGUI)
Exemple #5
0
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.graphic = GLWidget(self)
        self.graphicLayout.addWidget(self.graphic)
        self.graphic.setVisible(True)
        self.logo = LogoWidget(self)
        self.logoLayout.addWidget(self.logo)
        self.logo.setVisible(True)

        self.pushButton.clicked.connect(self.playClicked)
        self.pushButton.setCheckable(True)
        self.resetButton.clicked.connect(self.resetClicked)

        self.updGUI.connect(self.updateGUI)
        self.camera1 = CameraWidget(self)
Exemple #6
0
class TestWindow(QMainWindow, Ui_TestWindow):

    updGUI=pyqtSignal()
    def __init__(self, parent=None):
        super(TestWindow, self).__init__(parent)
        self.setupUi(self)
        self.logo = LogoWidget(self)
        self.logoLayout.addWidget(self.logo)
        self.logo.setVisible(True)
        self.display_stats = False
        
        self.clickedButton = False
        
        # Attach event handler to bestButton
        self.bestButton.clicked.connect(self.bestClicked)
        
    def updateGUI(self):
        pass
     
    # Event handler function of bestButton       
    def bestClicked(self):
        # Pass the generation number as a string
        generation = int(self.input_generation_2.value())
        self.display_stats = True
        if(self.clickedButton == False):
        	self.algorithm.run_state = "TEST" + str(generation)
        	self.algorithm.play()
        	self.clickedButton = True
        else:
        	self.algorithm.GA.run_state = "TEST" + str(generation)
        	self.algorithm.GA.initialize()
    	
    def update_plot(self):
    	self.plot.update_image()

    def setAlgorithm(self, algorithm):
        self.algorithm=algorithm
        _translate = QCoreApplication.translate
        self.input_generation_2.setMaximum(self.algorithm.latest_generation - 1)
        self.out_of_generation_2.setText(_translate("MainWindow", " / " + str(self.algorithm.latest_generation - 1)))

    def getAlgorithm(self):
        return self.algorithm

    def closeEvent(self, event):
        self.algorithm.kill()
        event.accept()
Exemple #7
0
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.teleop = TeleopWidget(self)
        self.map = MapWidget(self)
        self.tlLayout.addWidget(self.teleop)
        self.teleop.setVisible(True)
        self.mapLayout.addWidget(self.map)
        self.map.setVisible(True)

        self.verticalLayout_2.addWidget(self.stopButton, 3)

        self.logo = LogoWidget(self, 60, 60)
        self.verticalLayout_2.addWidget(self.logo, 4)
        self.logo.setVisible(True)

        self.playButton.clicked.connect(self.playClicked)
        self.playButton.setCheckable(True)
        self.updGUI.connect(self.updateGUI)
        #self.camera1=CameraWidget(self)

        self.stopButton.clicked.connect(self.stopClicked)
Exemple #8
0
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.teleop=TeleopWidget(self)
        self.map=MapWidget(self)
        self.tlLayout.addWidget(self.teleop)
        self.teleop.setVisible(True)
        self.mapLayout.addWidget(self.map)
        self.map.setVisible(True)


        self.verticalLayout_2.addWidget(self.stopButton,3)

        self.logo = LogoWidget(self, 60, 60)
        self.verticalLayout_2.addWidget(self.logo,4)
        self.logo.setVisible(True)

        self.playButton.clicked.connect(self.playClicked)
        self.playButton.setCheckable(True)
        self.updGUI.connect(self.updateGUI)
        self.camera1=CameraWidget(self)

        self.stopButton.clicked.connect(self.stopClicked)
Exemple #9
0
class MainWindow(QMainWindow, Ui_MainWindow):

    updGUI = pyqtSignal()

    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.teleop = TeleopWidget(self)
        self.map = MapWidget(self)
        self.tlLayout.addWidget(self.teleop)
        self.teleop.setVisible(True)
        self.mapLayout.addWidget(self.map)
        self.map.setVisible(True)

        self.verticalLayout_2.addWidget(self.stopButton, 3)

        self.logo = LogoWidget(self, 60, 60)
        self.verticalLayout_2.addWidget(self.logo, 4)
        self.logo.setVisible(True)

        self.playButton.clicked.connect(self.playClicked)
        self.playButton.setCheckable(True)
        self.updGUI.connect(self.updateGUI)
        #self.camera1=CameraWidget(self)

        self.stopButton.clicked.connect(self.stopClicked)

    def updateGUI(self):
        #self.camera1.updateImage()
        (cx, cy) = self.algorithm.getCarDirection()
        (ox, oy) = self.algorithm.getObstaclesDirection()
        (ax, ay) = self.algorithm.getAverageDirection()
        (tx, ty, id) = self.algorithm.getCurrentTarget()
        self.map.setCarArrow(cx, cy)
        self.map.setObstaclesArrow(ox, oy)
        self.map.setAverageArrow(ax, ay)
        if (self.pose3d):
            self.map.setTarget(tx, ty,
                               self.pose3d.getPose3d().x,
                               self.pose3d.getPose3d().y,
                               self.pose3d.getPose3d().yaw, id)
        laserdata = self.laser.getLaserData()
        if (laserdata):
            self.map.setLaserValues(laserdata)
        self.map.update()

    #def getCamera(self):
    #return self.camera

    #def setCamera(self,camera):
    #self.camera=camera

    def getPose3D(self):
        return self.pose3d

    def setPose3D(self, pose3d):
        self.pose3d = pose3d

    def getLaser(self):
        return self.laser

    def setLaser(self, laser):
        self.laser = laser

    def getMotors(self):
        return self.motors

    def setMotors(self, motors):
        self.motors = motors

    def playClicked(self):
        if self.playButton.isChecked():
            icon = QtGui.QIcon()
            self.playButton.setStyleSheet("background-color: #ec7063")
            icon.addPixmap(QtGui.QPixmap(":/images/stop.png"),
                           QtGui.QIcon.Normal, QtGui.QIcon.Off)
            self.playButton.setIcon(icon)
            self.algorithm.play()
        else:
            icon = QtGui.QIcon()
            self.playButton.setStyleSheet("background-color: #7dcea0")
            icon.addPixmap(QtGui.QPixmap(":/images/play.png"),
                           QtGui.QIcon.Normal, QtGui.QIcon.Off)
            self.playButton.setIcon(icon)
            self.algorithm.stop()
            self.motors.sendV(0)
            self.motors.sendW(0)
            #self.motors.sendVelocities()
            self.teleop.returnToOrigin()

    def setAlgorithm(self, algorithm):
        self.algorithm = algorithm

    def getAlgorithm(self):
        return self.algorithm

    def setXYValues(self, newX, newY):
        myW = -newX * self.motors.getMaxW()
        myV = -newY * self.motors.getMaxV()
        self.motors.sendV(myV)
        self.motors.sendW(myW)
        #self.motors.sendVelocities(self.motors)

    def stopClicked(self):
        self.motors.sendV(0)
        self.motors.sendW(0)
        # self.motors.sendVelocities()
        self.teleop.returnToOrigin()
Exemple #10
0
class MainWindow(QMainWindow, Ui_MainWindow):

    updGUI=pyqtSignal()
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.teleop=TeleopWidget(self)
        self.map=MapWidget(self)
        self.tlLayout.addWidget(self.teleop)
        self.teleop.setVisible(True)
        self.mapLayout.addWidget(self.map)
        self.map.setVisible(True)


        self.verticalLayout_2.addWidget(self.stopButton,3)

        self.logo = LogoWidget(self, 60, 60)
        self.verticalLayout_2.addWidget(self.logo,4)
        self.logo.setVisible(True)

        self.playButton.clicked.connect(self.playClicked)
        self.playButton.setCheckable(True)
        self.updGUI.connect(self.updateGUI)
        self.camera1=CameraWidget(self)

        self.stopButton.clicked.connect(self.stopClicked)

    def updateGUI(self):
        self.camera1.updateImage()
        (cx, cy) = self.algorithm.getCarDirection()
        (ox, oy) = self.algorithm.getObstaclesDirection()
        (ax, ay) = self.algorithm.getAverageDirection()
        (tx, ty, id) = self.algorithm.getCurrentTarget()
        self.map.setCarArrow(cx, cy)
        self.map.setObstaclesArrow(ox, oy)
        self.map.setAverageArrow(ax, ay)
        if (self.pose3d):
            self.map.setTarget(tx, ty, self.pose3d.getPose3d().x/1000, self.pose3d.getPose3d().y/1000, self.pose3d.getPose3d().yaw, id)
        laserdata = self.laser.getLaserData()
        if (laserdata):
            self.map.setLaserValues(laserdata)
        self.map.update()

    def getCamera(self):
        return self.camera

    def setCamera(self,camera):
        self.camera=camera

    def getPose3D(self):
        return self.pose3d

    def setPose3D(self,pose3d):
        self.pose3d=pose3d

    def getLaser(self):
        return self.laser

    def setLaser(self,laser):
        self.laser=laser

    def getMotors(self):
        return self.motors

    def setMotors(self,motors):
        self.motors=motors

    def playClicked(self):
        if self.playButton.isChecked():
            icon = QtGui.QIcon()
            self.playButton.setStyleSheet("background-color: #ec7063")
            icon.addPixmap(QtGui.QPixmap(":/images/stop.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
            self.playButton.setIcon(icon)
            self.algorithm.play()
        else:
            icon = QtGui.QIcon()
            self.playButton.setStyleSheet("background-color: #7dcea0")
            icon.addPixmap(QtGui.QPixmap(":/images/play.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
            self.playButton.setIcon(icon)
            self.algorithm.stop()
            self.motors.sendV(0)
            self.motors.sendW(0)
            #self.motors.sendVelocities()
            self.teleop.returnToOrigin()

    def setAlgorithm(self, algorithm ):
        self.algorithm=algorithm

    def getAlgorithm(self):
        return self.algorithm

    def setXYValues(self,newX,newY):
        myW=-newX*self.motors.getMaxW()
        myV=-newY*self.motors.getMaxV()
        self.motors.sendV(myV)
        self.motors.sendW(myW)
        #self.motors.sendVelocities(self.motors)

    def stopClicked(self):
        self.motors.sendV(0)
        self.motors.sendW(0)
        # self.motors.sendVelocities()
        self.teleop.returnToOrigin()
Exemple #11
0
class MainWindow(QMainWindow, Ui_MainWindow):

    updGUI=pyqtSignal()
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.teleop=TeleopWidget(self)
        self.tlLayout.addWidget(self.teleop)
        self.teleop.setVisible(True)
        self.logo = LogoWidget(self)
        self.logoLayout.addWidget(self.logo)
        self.logo.setVisible(True)



        self.pushButton.clicked.connect(self.playClicked)
        self.pushButton.setCheckable(True)
        self.updGUI.connect(self.updateGUI)
        self.camera1=CameraWidget(self)

        self.stopButton.clicked.connect(self.stopClicked)

    def updateGUI(self):
        #print 'update gui'
        self.camera1.updateImage()
        #self.sensorsWidget.sensorsUpdate.emit()

    def getCameraL(self):
        return self.cameraL

    def setCameraL(self,camera):
        self.cameraL=camera

    def getCameraR(self):
        return self.cameraR

    def setCameraR(self,camera):
        self.cameraR=camera

    def getMotors(self):
        return self.motors

    def setMotors(self,motors):
        self.motors=motors

    def playClicked(self):
        if self.pushButton.isChecked():
            self.pushButton.setText('RUNNING')
            self.playButton.setStyleSheet("background-color: #ec7063")
            self.algorithm.play()
        else:
            self.pushButton.setText('STOPPED')
            self.playButton.setStyleSheet("background-color: #7dcea0")
            self.algorithm.stop()

    def setAlgorithm(self, algorithm ):
        self.algorithm=algorithm

    def getAlgorithm(self):
        return self.algorithm

    def setXYValues(self,newX,newY):
        #print ("newX: %f, newY: %f" % (newX, newY) )
        myW=-newX*self.motors.getMaxW()
        myV=-newY*self.motors.getMaxV()
        self.motors.sendV(myV)
        self.motors.sendW(myW)

    def stopClicked(self):
        self.motors.sendV(0)
        self.motors.sendW(0)
        self.teleop.returnToOrigin()

    def closeEvent(self, event):
        self.algorithm.kill()
        self.cameraR.stop()
        self.cameraL.stop()
        event.accept()
Exemple #12
0
class MainWindow(QMainWindow, Ui_MainWindow):

    updGUI = pyqtSignal()

    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.teleop = TeleopWidget(self)
        self.map = MapWidget(self)
        self.tlLayout.addWidget(self.teleop)
        self.teleop.setVisible(True)
        self.mapLayout.addWidget(self.map)
        self.map.setVisible(True)

        self.logo = LogoWidget(self, 60, 60)
        self.runLayout.addWidget(self.logo)
        self.logo.setVisible(True)

        self.pushButton.clicked.connect(self.playClicked)
        self.pushButton.setCheckable(True)
        self.updGUI.connect(self.updateGUI)
        self.camera1 = CameraWidget(self)

        self.stopButton.clicked.connect(self.stopClicked)

    def updateGUI(self):
        self.camera1.updateImage()
        (cx, cy) = self.algorithm.getCarDirection()
        (ox, oy) = self.algorithm.getObstaclesDirection()
        (ax, ay) = self.algorithm.getAverageDirection()
        (tx, ty) = self.algorithm.getCurrentTarget()
        self.map.setCarArrow(cx, cy)
        self.map.setObstaclesArrow(ox, oy)
        self.map.setAverageArrow(ax, ay)
        if (self.pose3d):
            self.map.setTarget(tx, ty,
                               self.pose3d.getPose3d().x / 1000,
                               self.pose3d.getPose3d().y / 1000,
                               self.pose3d.getPose3d().yaw)
        laserdata = self.laser.getLaserData()
        if (laserdata):
            self.map.setLaserValues(laserdata)
        self.map.update()

    def getCameraL(self):
        return self.cameraL

    def setCameraL(self, camera):
        self.cameraL = camera

    def getCameraR(self):
        return self.cameraR

    def setCameraR(self, camera):
        self.cameraR = camera

    def getPose3D(self):
        return self.pose3d

    def setPose3D(self, pose3d):
        self.pose3d = pose3d

    def getLaser(self):
        return self.laser

    def setLaser(self, laser):
        self.laser = laser

    def getMotors(self):
        return self.motors

    def setMotors(self, motors):
        self.motors = motors

    def playClicked(self):
        if self.pushButton.isChecked():
            self.pushButton.setText('RUNNING')
            self.pushButton.setStyleSheet("background-color: green")
            self.algorithm.play()
        else:
            self.pushButton.setText('STOPPED')
            self.pushButton.setStyleSheet("background-color: red")
            self.algorithm.stop()

    def setAlgorithm(self, algorithm):
        self.algorithm = algorithm

    def getAlgorithm(self):
        return self.algorithm

    def setXYValues(self, newX, newY):
        myW = -newX * self.motors.getMaxW()
        myV = -newY * self.motors.getMaxV()
        self.motors.hasproxy().setV(myV)
        self.motors.hasproxy().setW(myW)
        #self.motors.sendVelocities(self.motors)

    def stopClicked(self):
        self.motors.hasproxy().setV(0)
        self.motors.hasproxy().setW(0)
        #self.motors.sendVelocities()
        self.teleop.returnToOrigin()
Exemple #13
0
class MainWindow(QMainWindow, Ui_MainWindow):

    updGUI=pyqtSignal()
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.teleop=TeleopWidget(self)
        self.tlLayout.addWidget(self.teleop)
        self.teleop.setVisible(True)
        self.logo = LogoWidget(self)
        self.logoLayout.addWidget(self.logo)
        self.logo.setVisible(True)

        self.pushButton.clicked.connect(self.playClicked)
        self.pushButton.setCheckable(True)
        self.updGUI.connect(self.updateGUI)
        self.camera1=CameraWidget(self)

        self.stopButton.clicked.connect(self.stopClicked)

    def updateGUI(self):
        #print 'update gui'
        self.camera1.updateImage()

    def getCamera(self):
        return self.camera

    def setCamera(self,camera):
        self.camera=camera

    def getMotors(self):
        return self.motors

    def setMotors(self,motors):
        self.motors=motors

    def playClicked(self):
        if self.pushButton.isChecked():
            self.pushButton.setText('Stop Code')
            self.pushButton.setStyleSheet("background-color: #7dcea0")
            self.algorithm.play()
        else:
            self.pushButton.setText('Play Code')
            self.pushButton.setStyleSheet("background-color: #ec7063")
            self.algorithm.stop()

    def setAlgorithm(self, algorithm ):
        self.algorithm=algorithm

    def getAlgorithm(self):
        return self.algorithm

    def setXYValues(self,newX,newY):
        #print ("newX: %f, newY: %f" % (newX, newY) )
        myW=-newX*self.motors.getMaxW()
        myV=-newY*self.motors.getMaxV()
        self.motors.sendV(myV)
        self.motors.sendW(myW)
        None

    def stopClicked(self):
        self.motors.sendV(0)
        self.motors.sendW(0)
        self.teleop.returnToOrigin()

    def closeEvent(self, event):
        self.algorithm.kill()
        self.camera.stop()
        event.accept()
Exemple #14
0
class MainWindow(QMainWindow, Ui_MainWindow):

    updGUI = pyqtSignal()

    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.teleop = TeleopWidget(self)
        self.tlLayout.addWidget(self.teleop)
        self.teleop.setVisible(True)
        self.logo = LogoWidget(self)
        self.logoLayout.addWidget(self.logo)
        self.logo.setVisible(True)

        self.buffer = []

        self.pushButton.clicked.connect(self.playClicked)
        self.pushButton.setCheckable(True)
        self.updGUI.connect(self.updateGUI)
        self.camera1 = CameraWidget(self)

        self.stopButton.clicked.connect(self.stopClicked)

    def updateGUI(self):
        #print 'update gui'
        self.camera1.updateImage()
        self.pose = self.pose_client.getPose3d()
        #self.sensorsWidget.sensorsUpdate.emit()

    def getCameraL(self):
        return self.cameraL

    def setPose(self, pose_client):
        self.pose_client = pose_client

    def setCameraL(self, camera):
        self.cameraL = camera

    def getCameraR(self):
        return self.cameraR

    def setCameraR(self, camera):
        self.cameraR = camera

    def getMotors(self):
        return self.motors

    def setMotors(self, motors):
        self.motors = motors

    def playClicked(self):
        if self.pushButton.isChecked():
            self.pushButton.setText('RUNNING')
            self.pushButton.setStyleSheet("background-color: green")
            self.algorithm.play()
        else:
            self.pushButton.setText('STOPPED')
            self.pushButton.setStyleSheet("background-color: red")
            self.algorithm.stop()

    def setAlgorithm(self, algorithm):
        self.algorithm = algorithm

    def getAlgorithm(self):
        return self.algorithm

    def setXYValues(self, newX, newY):
        # print ("newX: %f, newY: %f" % (newX, newY) )
        write = False

        myW = -newX * self.motors.getMaxW()
        myV = -newY * self.motors.getMaxV()
        # print "myV: ",myV,"myW: ",myW
        if write:
            pose = self.pose_client.getPose3d()
            self.buffer.append("{:f} {:f} {:f} {:f}\n".format(
                pose.x / 1000, pose.y / 1000, myV, myW))
            if len(self.buffer) == 10:
                with open(
                        "/home/f/PycharmProjects/Robotica/follow_line/laps/prueba.txt",
                        'a') as file:
                    file.write("".join(self.buffer))
                self.buffer = []

        self.motors.sendV(myV)
        self.motors.sendW(myW)

    def stopClicked(self):
        self.motors.sendV(0)
        self.motors.sendW(0)
        self.teleop.returnToOrigin()

    def closeEvent(self, event):
        self.algorithm.kill()
        self.cameraR.stop()
        self.cameraL.stop()
        event.accept()
Exemple #15
0
class MainWindow(QMainWindow, Ui_MainWindow):

    updGUI = pyqtSignal()

    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.graphic = GLWidget(self)
        self.graphicLayout.addWidget(self.graphic)
        self.graphic.setVisible(True)
        self.logo = LogoWidget(self)
        self.logoLayout.addWidget(self.logo)
        self.logo.setVisible(True)

        self.pushButton.clicked.connect(self.playClicked)
        self.pushButton.setCheckable(True)
        self.resetButton.clicked.connect(self.resetClicked)

        self.updGUI.connect(self.updateGUI)
        self.camera1 = CameraWidget(self)

        #self.stopButton.clicked.connect(self.stopClicked)

    def updateGUI(self):
        #print 'update gui'
        self.camera1.updateImage()
        self.graphic.updateGL()

    def plot(self):
        self.graphic.render_point(point[:3], point[3:], radius)

    def getCamera(self, lr):
        if (lr == 'left'):
            return self.cameraL
        elif (lr == 'right'):
            return self.cameraR
        else:
            print("Invalid Camera")
            exit()

    def setCamera(self, camera, lr):
        if (lr == 'left'):
            self.cameraL = camera
        elif (lr == 'right'):
            self.cameraR = camera
        else:
            print("Invalid Camera")
            exit()

    def setPlot(self, listener):
        self.point = listener

    def getPlot(self):
        return self.point

    def playClicked(self):
        if self.pushButton.isChecked():
            self.pushButton.setText('Stop Code')
            self.pushButton.setStyleSheet("background-color: #7dcea0")
            self.algorithm.play()
        else:
            self.pushButton.setText('Play Code')
            self.pushButton.setStyleSheet("background-color: #ec7063")
            self.algorithm.stop()

    def resetClicked(self):
        self.graphic.reset_view()

    def setAlgorithm(self, algorithm):
        self.algorithm = algorithm

    def getAlgorithm(self):
        return self.algorithm

    def setXYValues(self, newX, newY):
        #print ("newX: %f, newY: %f" % (newX, newY) )
        myW = -newX * self.motors.getMaxW()
        myV = -newY * self.motors.getMaxV()
        self.motors.sendV(myV)
        self.motors.sendW(myW)
        None

    def stopClicked(self):
        self.motors.sendV(0)
        self.motors.sendW(0)
        self.teleop.returnToOrigin()

    def closeEvent(self, event):
        self.algorithm.kill()
        self.cameraL.stop()
        self.cameraR.stop()
        event.accept()
Exemple #16
0
class TrainWindow(QMainWindow, Ui_TrainWindow):

    updGUI=pyqtSignal()
    def __init__(self, parent=None):
        super(TrainWindow, self).__init__(parent)
        self.setupUi(self)
        self.logo = LogoWidget(self)
        self.logoLayout.addWidget(self.logo)
        self.logo.setVisible(True)
        self.display_stats = False

        # Attach event handler to trainButton and generationButton
        self.trainButton.clicked.connect(self.trainClicked)
        self.trainButton.setCheckable(True)
        self.generationButton.clicked.connect(self.generationClicked)
        self.generationButton.setCheckable(True)

        self.updGUI.connect(self.updateGUI)

    def updateGUI(self):
    	if(self.display_stats == True and self.algorithm.start_state == False):
        	self.update_stats()
        
    # Event handler function of trainButton
    def trainClicked(self):
        self.display_stats = True
        self.algorithm.run_state = "TRAIN"
        if self.trainButton.isChecked():
            self.trainButton.setText('Stop Training')
            self.algorithm.play()
        else:
            self.trainButton.setText('Start Training')
            self.algorithm.stop()
    
    # Event Handler function of TestButton       
    def generationClicked(self):
        generation = int(self.input_generation.value())
        self.algorithm.run_state = "CONTINUE" + str(generation)
        self.display_stats = True
        if self.generationButton.isChecked():
            self.generationButton.setText('Stop Training')
            self.algorithm.play()
        else:
	        self.generationButton.setText('Continue Training')
	        self.algorithm.stop()
    
    # Function to update the statistics       
    def update_stats(self):
        stats_array = self.algorithm.GA.return_stats()
        
        if(len(stats_array) == 4):
        	_translate = QCoreApplication.translate
        	self.generation_value.setText(_translate("MainWindow", str(stats_array[0])))
        	self.individual_value.setText(_translate("MainWindow", str(stats_array[1])))
        	self.best_fitness_value.setText(_translate("MainWindow", str(stats_array[2])))
        	self.timer_value.setText(_translate("MainWindow", str(stats_array[3])))
    	
    def update_plot(self):
    	self.plot.update_image()

    def setAlgorithm(self, algorithm):
        self.algorithm=algorithm
        _translate = QCoreApplication.translate
        self.input_generation.setMaximum(self.algorithm.latest_generation)
        self.out_of_generation.setText(_translate("MainWindow", " / " + str(self.algorithm.latest_generation)))
        self.last_generation.setText(_translate("MainWindow", str(self.algorithm.latest_generation)))

    def getAlgorithm(self):
        return self.algorithm

    def closeEvent(self, event):
        self.algorithm.kill()
        event.accept()