Update Code and Tutorial

This commit is contained in:
a838557765 2019-09-25 09:09:34 +08:00
parent 91a5944dfe
commit 816bae97f7
22 changed files with 36091 additions and 0 deletions

600
Code/Client/Client_Ui.py Normal file
View File

@ -0,0 +1,600 @@
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'F:/GUO/test/qss/Client_Ui.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_Client(object):
def setupUi(self, Client):
Client.setObjectName(_fromUtf8("Client"))
Client.resize(760, 610)
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(72, 72, 72))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
brush = QtGui.QBrush(QtGui.QColor(72, 72, 72))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(72, 72, 72))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(72, 72, 72))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
brush = QtGui.QBrush(QtGui.QColor(72, 72, 72))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(72, 72, 72))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(72, 72, 72))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
brush = QtGui.QBrush(QtGui.QColor(72, 72, 72))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(72, 72, 72))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
Client.setPalette(palette)
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(14)
Client.setFont(font)
Client.setStyleSheet(_fromUtf8("QWidget{\n"
"background:#484848;\n"
"}\n"
"QAbstractButton{\n"
"border-style:none;\n"
"border-radius:0px;\n"
"padding:5px;\n"
"color:#DCDCDC;\n"
"background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #484848,stop:1 #383838);\n"
"}\n"
"QAbstractButton:hover{\n"
"color:#FFFFFF;\n"
"background-color:#00BB9E;\n"
"}\n"
"QAbstractButton:pressed{\n"
"color:#DCDCDC;\n"
"border-style:solid;\n"
"border-width:0px 0px 0px 2px;\n"
"padding:4px 4px 4px 2px;\n"
"border-color:#00BB9E;\n"
"background-color:#444444;\n"
"}\n"
"QLabel{\n"
"color:#DCDCDC;\n"
"border:1px solid #242424;\n"
"background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #484848,stop:1 #383838);\n"
"}\n"
"QLabel:focus{\n"
"border:1px solid #00BB9E;\n"
"background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #646464,stop:1 #525252);\n"
"}\n"
"QLineEdit{\n"
"border:1px solid #242424;\n"
"border-radius:3px;\n"
"padding:2px;\n"
"background:none;\n"
"selection-background-color:#484848;\n"
"selection-color:#DCDCDC;\n"
"}\n"
"QLineEdit:focus,QLineEdit:hover{\n"
"border:1px solid #242424;\n"
"}\n"
"QLineEdit{\n"
"border:1px solid #242424;\n"
"border-radius:3px;\n"
"padding:2px;\n"
"background:none;\n"
"selection-background-color:#484848;\n"
"selection-color:#DCDCDC;\n"
"}\n"
"\n"
"QLineEdit:focus,QLineEdit:hover{\n"
"border:1px solid #242424;\n"
"}\n"
"QLineEdit{\n"
"lineedit-password-character:9679;\n"
"}\n"
"QSlider::groove:horizontal,QSlider::add-page:horizontal{\n"
"height:3px;\n"
"border-radius:3px;\n"
"background:#18181a;\n"
"}\n"
"\n"
"\n"
"QSlider::sub-page:horizontal{\n"
"height:8px;\n"
"border-radius:3px;\n"
"background:#008aff;\n"
"}\n"
"\n"
"\n"
"QSlider::handle:horizontal{\n"
"width:12px;\n"
"margin-top:-5px;\n"
"margin-bottom:-4px;\n"
"border-radius:6px;\n"
"background:qradialgradient(spread:pad,cx:0.5,cy:0.5,radius:0.5,fx:0.5,fy:0.5,stop:0.6 #565656,stop:0.8 #565656);\n"
"}\n"
"\n"
"\n"
"QSlider::groove:vertical,QSlider::sub-page:vertical{\n"
"width:3px;\n"
"border-radius:3px;\n"
"background:#18181a;\n"
"}\n"
"\n"
"\n"
"QSlider::add-page:vertical{\n"
"width:8px;\n"
"border-radius:3px;\n"
"background:#008aff;\n"
"}\n"
"\n"
"\n"
"QSlider::handle:vertical{\n"
"height:12px;\n"
"margin-left:-5px;\n"
"margin-right:-4px;\n"
"border-radius:6px;\n"
"background:qradialgradient(spread:pad,cx:0.5,cy:0.5,radius:0.5,fx:0.5,fy:0.5,stop:0.6 #565656,stop:0.8 #565656);\n"
"}\n"
""))
self.Btn_ForWard = QtGui.QPushButton(Client)
self.Btn_ForWard.setGeometry(QtCore.QRect(120, 450, 90, 30))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.Btn_ForWard.setFont(font)
self.Btn_ForWard.setStyleSheet(_fromUtf8(""))
self.Btn_ForWard.setObjectName(_fromUtf8("Btn_ForWard"))
self.name = QtGui.QLabel(Client)
self.name.setGeometry(QtCore.QRect(0, 1, 660, 40))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(28)
font.setBold(True)
font.setWeight(75)
self.name.setFont(font)
self.name.setStyleSheet(_fromUtf8(""))
self.name.setObjectName(_fromUtf8("name"))
self.Btn_Turn_Left = QtGui.QPushButton(Client)
self.Btn_Turn_Left.setGeometry(QtCore.QRect(10, 500, 90, 30))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.Btn_Turn_Left.setFont(font)
self.Btn_Turn_Left.setStyleSheet(_fromUtf8(""))
self.Btn_Turn_Left.setObjectName(_fromUtf8("Btn_Turn_Left"))
self.Btn_BackWard = QtGui.QPushButton(Client)
self.Btn_BackWard.setGeometry(QtCore.QRect(120, 550, 90, 30))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.Btn_BackWard.setFont(font)
self.Btn_BackWard.setStyleSheet(_fromUtf8(""))
self.Btn_BackWard.setObjectName(_fromUtf8("Btn_BackWard"))
self.Btn_Tracking_Faces = QtGui.QPushButton(Client)
self.Btn_Tracking_Faces.setGeometry(QtCore.QRect(240, 450, 90, 30))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.Btn_Tracking_Faces.setFont(font)
self.Btn_Tracking_Faces.setStyleSheet(_fromUtf8(""))
self.Btn_Tracking_Faces.setObjectName(_fromUtf8("Btn_Tracking_Faces"))
self.Btn_Turn_Right = QtGui.QPushButton(Client)
self.Btn_Turn_Right.setGeometry(QtCore.QRect(240, 500, 90, 30))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.Btn_Turn_Right.setFont(font)
self.Btn_Turn_Right.setStyleSheet(_fromUtf8(""))
self.Btn_Turn_Right.setObjectName(_fromUtf8("Btn_Turn_Right"))
self.Btn_Video = QtGui.QPushButton(Client)
self.Btn_Video.setGeometry(QtCore.QRect(240, 380, 90, 30))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.Btn_Video.setFont(font)
self.Btn_Video.setStyleSheet(_fromUtf8(""))
self.Btn_Video.setObjectName(_fromUtf8("Btn_Video"))
self.label_Video = QtGui.QLabel(Client)
self.label_Video.setGeometry(QtCore.QRect(1, 42, 400, 300))
self.label_Video.setText(_fromUtf8(""))
self.label_Video.setObjectName(_fromUtf8("label_Video"))
self.Btn_Down = QtGui.QPushButton(Client)
self.Btn_Down.setGeometry(QtCore.QRect(510, 480, 75, 30))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.Btn_Down.setFont(font)
self.Btn_Down.setStyleSheet(_fromUtf8(""))
self.Btn_Down.setObjectName(_fromUtf8("Btn_Down"))
self.Btn_Left = QtGui.QPushButton(Client)
self.Btn_Left.setGeometry(QtCore.QRect(440, 450, 75, 30))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.Btn_Left.setFont(font)
self.Btn_Left.setStyleSheet(_fromUtf8(""))
self.Btn_Left.setObjectName(_fromUtf8("Btn_Left"))
self.Btn_Home = QtGui.QPushButton(Client)
self.Btn_Home.setGeometry(QtCore.QRect(510, 450, 75, 30))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.Btn_Home.setFont(font)
self.Btn_Home.setStyleSheet(_fromUtf8(""))
self.Btn_Home.setObjectName(_fromUtf8("Btn_Home"))
self.Btn_Up = QtGui.QPushButton(Client)
self.Btn_Up.setGeometry(QtCore.QRect(510, 420, 75, 30))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.Btn_Up.setFont(font)
self.Btn_Up.setStyleSheet(_fromUtf8(""))
self.Btn_Up.setObjectName(_fromUtf8("Btn_Up"))
self.Btn_Right = QtGui.QPushButton(Client)
self.Btn_Right.setGeometry(QtCore.QRect(580, 450, 75, 30))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.Btn_Right.setFont(font)
self.Btn_Right.setStyleSheet(_fromUtf8(""))
self.Btn_Right.setObjectName(_fromUtf8("Btn_Right"))
self.Window_Close = QtGui.QPushButton(Client)
self.Window_Close.setGeometry(QtCore.QRect(710, 1, 50, 40))
self.Window_Close.setObjectName(_fromUtf8("Window_Close"))
self.IP = QtGui.QLineEdit(Client)
self.IP.setGeometry(QtCore.QRect(10, 380, 101, 30))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.IP.setFont(font)
self.IP.setStyleSheet(_fromUtf8(""))
self.IP.setObjectName(_fromUtf8("IP"))
self.Btn_Connect = QtGui.QPushButton(Client)
self.Btn_Connect.setGeometry(QtCore.QRect(120, 380, 90, 30))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.Btn_Connect.setFont(font)
self.Btn_Connect.setObjectName(_fromUtf8("Btn_Connect"))
self.checkBox_Led1 = QtGui.QCheckBox(Client)
self.checkBox_Led1.setGeometry(QtCore.QRect(420, 120, 91, 31))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.checkBox_Led1.setFont(font)
self.checkBox_Led1.setObjectName(_fromUtf8("checkBox_Led1"))
self.label_Servo2 = QtGui.QLabel(Client)
self.label_Servo2.setGeometry(QtCore.QRect(710, 460, 41, 31))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(14)
self.label_Servo2.setFont(font)
self.label_Servo2.setObjectName(_fromUtf8("label_Servo2"))
self.checkBox_Led2 = QtGui.QCheckBox(Client)
self.checkBox_Led2.setGeometry(QtCore.QRect(420, 170, 91, 31))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.checkBox_Led2.setFont(font)
self.checkBox_Led2.setObjectName(_fromUtf8("checkBox_Led2"))
self.checkBox_Led3 = QtGui.QCheckBox(Client)
self.checkBox_Led3.setGeometry(QtCore.QRect(420, 220, 91, 31))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.checkBox_Led3.setFont(font)
self.checkBox_Led3.setObjectName(_fromUtf8("checkBox_Led3"))
self.checkBox_Led4 = QtGui.QCheckBox(Client)
self.checkBox_Led4.setGeometry(QtCore.QRect(420, 270, 91, 31))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.checkBox_Led4.setFont(font)
self.checkBox_Led4.setObjectName(_fromUtf8("checkBox_Led4"))
self.checkBox_Led5 = QtGui.QCheckBox(Client)
self.checkBox_Led5.setGeometry(QtCore.QRect(530, 120, 91, 31))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.checkBox_Led5.setFont(font)
self.checkBox_Led5.setObjectName(_fromUtf8("checkBox_Led5"))
self.checkBox_Led6 = QtGui.QCheckBox(Client)
self.checkBox_Led6.setGeometry(QtCore.QRect(530, 170, 91, 31))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.checkBox_Led6.setFont(font)
self.checkBox_Led6.setObjectName(_fromUtf8("checkBox_Led6"))
self.checkBox_Led7 = QtGui.QCheckBox(Client)
self.checkBox_Led7.setGeometry(QtCore.QRect(530, 220, 91, 31))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.checkBox_Led7.setFont(font)
self.checkBox_Led7.setObjectName(_fromUtf8("checkBox_Led7"))
self.checkBox_Led8 = QtGui.QCheckBox(Client)
self.checkBox_Led8.setGeometry(QtCore.QRect(530, 270, 91, 31))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.checkBox_Led8.setFont(font)
self.checkBox_Led8.setObjectName(_fromUtf8("checkBox_Led8"))
self.HSlider_Servo1 = QtGui.QSlider(Client)
self.HSlider_Servo1.setGeometry(QtCore.QRect(470, 530, 160, 22))
self.HSlider_Servo1.setStyleSheet(_fromUtf8(""))
self.HSlider_Servo1.setOrientation(QtCore.Qt.Horizontal)
self.HSlider_Servo1.setObjectName(_fromUtf8("HSlider_Servo1"))
self.VSlider_Servo2 = QtGui.QSlider(Client)
self.VSlider_Servo2.setGeometry(QtCore.QRect(680, 400, 22, 160))
self.VSlider_Servo2.setStyleSheet(_fromUtf8(""))
self.VSlider_Servo2.setOrientation(QtCore.Qt.Vertical)
self.VSlider_Servo2.setObjectName(_fromUtf8("VSlider_Servo2"))
self.label_Servo1 = QtGui.QLabel(Client)
self.label_Servo1.setGeometry(QtCore.QRect(530, 560, 41, 31))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(14)
self.label_Servo1.setFont(font)
self.label_Servo1.setObjectName(_fromUtf8("label_Servo1"))
self.checkBox_Led_Mode2 = QtGui.QCheckBox(Client)
self.checkBox_Led_Mode2.setGeometry(QtCore.QRect(640, 170, 101, 31))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.checkBox_Led_Mode2.setFont(font)
self.checkBox_Led_Mode2.setObjectName(_fromUtf8("checkBox_Led_Mode2"))
self.checkBox_Led_Mode3 = QtGui.QCheckBox(Client)
self.checkBox_Led_Mode3.setGeometry(QtCore.QRect(640, 220, 101, 31))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.checkBox_Led_Mode3.setFont(font)
self.checkBox_Led_Mode3.setObjectName(_fromUtf8("checkBox_Led_Mode3"))
self.checkBox_Led_Mode4 = QtGui.QCheckBox(Client)
self.checkBox_Led_Mode4.setGeometry(QtCore.QRect(640, 270, 101, 31))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.checkBox_Led_Mode4.setFont(font)
self.checkBox_Led_Mode4.setObjectName(_fromUtf8("checkBox_Led_Mode4"))
self.checkBox_Led_Mode1 = QtGui.QCheckBox(Client)
self.checkBox_Led_Mode1.setGeometry(QtCore.QRect(640, 120, 101, 31))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.checkBox_Led_Mode1.setFont(font)
self.checkBox_Led_Mode1.setObjectName(_fromUtf8("checkBox_Led_Mode1"))
self.Color_R = QtGui.QLineEdit(Client)
self.Color_R.setGeometry(QtCore.QRect(560, 90, 30, 20))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.Color_R.setFont(font)
self.Color_R.setObjectName(_fromUtf8("Color_R"))
self.Color_G = QtGui.QLineEdit(Client)
self.Color_G.setGeometry(QtCore.QRect(630, 90, 30, 20))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.Color_G.setFont(font)
self.Color_G.setObjectName(_fromUtf8("Color_G"))
self.Color_B = QtGui.QLineEdit(Client)
self.Color_B.setGeometry(QtCore.QRect(700, 90, 30, 20))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.Color_B.setFont(font)
self.Color_B.setObjectName(_fromUtf8("Color_B"))
self.HSlider_FineServo2 = QtGui.QSlider(Client)
self.HSlider_FineServo2.setGeometry(QtCore.QRect(480, 370, 160, 22))
self.HSlider_FineServo2.setOrientation(QtCore.Qt.Horizontal)
self.HSlider_FineServo2.setObjectName(_fromUtf8("HSlider_FineServo2"))
self.HSlider_FineServo1 = QtGui.QSlider(Client)
self.HSlider_FineServo1.setGeometry(QtCore.QRect(480, 320, 160, 22))
self.HSlider_FineServo1.setOrientation(QtCore.Qt.Horizontal)
self.HSlider_FineServo1.setObjectName(_fromUtf8("HSlider_FineServo1"))
self.label_FineServo1 = QtGui.QLabel(Client)
self.label_FineServo1.setGeometry(QtCore.QRect(650, 320, 41, 31))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(14)
self.label_FineServo1.setFont(font)
self.label_FineServo1.setObjectName(_fromUtf8("label_FineServo1"))
self.label_FineServo2 = QtGui.QLabel(Client)
self.label_FineServo2.setGeometry(QtCore.QRect(650, 360, 41, 31))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(14)
self.label_FineServo2.setFont(font)
self.label_FineServo2.setObjectName(_fromUtf8("label_FineServo2"))
self.Window_Min = QtGui.QPushButton(Client)
self.Window_Min.setGeometry(QtCore.QRect(660, 1, 50, 40))
self.Window_Min.setObjectName(_fromUtf8("Window_Min"))
self.R = QtGui.QLabel(Client)
self.R.setGeometry(QtCore.QRect(530, 90, 16, 20))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.R.setFont(font)
self.R.setObjectName(_fromUtf8("R"))
self.G = QtGui.QLabel(Client)
self.G.setGeometry(QtCore.QRect(600, 90, 16, 20))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.G.setFont(font)
self.G.setObjectName(_fromUtf8("G"))
self.B = QtGui.QLabel(Client)
self.B.setGeometry(QtCore.QRect(670, 90, 16, 20))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.B.setFont(font)
self.B.setObjectName(_fromUtf8("B"))
self.Led_Module = QtGui.QLabel(Client)
self.Led_Module.setGeometry(QtCore.QRect(410, 90, 111, 25))
self.Led_Module.setObjectName(_fromUtf8("Led_Module"))
self.Servo1 = QtGui.QLabel(Client)
self.Servo1.setGeometry(QtCore.QRect(420, 320, 54, 20))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.Servo1.setFont(font)
self.Servo1.setObjectName(_fromUtf8("Servo1"))
self.Servo2 = QtGui.QLabel(Client)
self.Servo2.setGeometry(QtCore.QRect(420, 370, 54, 20))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.Servo2.setFont(font)
self.Servo2.setObjectName(_fromUtf8("Servo2"))
self.progress_Power = QtGui.QProgressBar(Client)
self.progress_Power.setGeometry(QtCore.QRect(20, 550, 70, 30))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.progress_Power.setFont(font)
self.progress_Power.setStyleSheet(_fromUtf8("QProgressBar {\n"
"border: 2px solid grey;\n"
"border-radius: 5px;\n"
"background-color: #FFFFFF;\n"
"}\n"
"\n"
"QProgressBar::chunk {\n"
"background-color:#696969;\n"
"width: 20px;\n"
"}\n"
"\n"
"QProgressBar {\n"
"text-align: center; \n"
"color: rgb(152,251,152);\n"
"}\n"
""))
self.progress_Power.setProperty("value", 0)
self.progress_Power.setObjectName(_fromUtf8("progress_Power"))
self.Btn_Buzzer = QtGui.QPushButton(Client)
self.Btn_Buzzer.setGeometry(QtCore.QRect(120, 500, 90, 30))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.Btn_Buzzer.setFont(font)
self.Btn_Buzzer.setObjectName(_fromUtf8("Btn_Buzzer"))
self.Ultrasonic = QtGui.QPushButton(Client)
self.Ultrasonic.setGeometry(QtCore.QRect(401, 41, 180, 30))
self.Ultrasonic.setObjectName(_fromUtf8("Ultrasonic"))
self.Light = QtGui.QPushButton(Client)
self.Light.setGeometry(QtCore.QRect(581, 41, 179, 30))
self.Light.setObjectName(_fromUtf8("Light"))
self.Btn_Mode1 = QtGui.QRadioButton(Client)
self.Btn_Mode1.setGeometry(QtCore.QRect(340, 400, 90, 30))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.Btn_Mode1.setFont(font)
self.Btn_Mode1.setObjectName(_fromUtf8("Btn_Mode1"))
self.Btn_Mode2 = QtGui.QRadioButton(Client)
self.Btn_Mode2.setGeometry(QtCore.QRect(340, 450, 90, 30))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.Btn_Mode2.setFont(font)
self.Btn_Mode2.setObjectName(_fromUtf8("Btn_Mode2"))
self.Btn_Mode3 = QtGui.QRadioButton(Client)
self.Btn_Mode3.setGeometry(QtCore.QRect(340, 500, 90, 30))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.Btn_Mode3.setFont(font)
self.Btn_Mode3.setObjectName(_fromUtf8("Btn_Mode3"))
self.Btn_Mode4 = QtGui.QRadioButton(Client)
self.Btn_Mode4.setGeometry(QtCore.QRect(340, 550, 90, 30))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(10)
self.Btn_Mode4.setFont(font)
self.Btn_Mode4.setObjectName(_fromUtf8("Btn_Mode4"))
self.retranslateUi(Client)
QtCore.QMetaObject.connectSlotsByName(Client)
def retranslateUi(self, Client):
Client.setWindowTitle(_translate("Client", "freenove", None))
self.Btn_ForWard.setText(_translate("Client", "ForWard", None))
self.name.setText(_translate("Client", "Freenove", None))
self.Btn_Turn_Left.setText(_translate("Client", "Turn Left", None))
self.Btn_BackWard.setText(_translate("Client", "BackWard", None))
self.Btn_Turn_Right.setText(_translate("Client", "Turn Right", None))
self.Btn_Video.setText(_translate("Client", "Open Video", None))
self.Btn_Tracking_Faces.setText(_translate("Client", "Tracing-On", None))
self.Btn_Down.setText(_translate("Client", "Down", None))
self.Btn_Left.setText(_translate("Client", "Left", None))
self.Btn_Home.setText(_translate("Client", "Home", None))
self.Btn_Up.setText(_translate("Client", "Up", None))
self.Btn_Right.setText(_translate("Client", "Right", None))
self.Window_Close.setText(_translate("Client", "×", None))
self.IP.setText(_translate("Client", "IP address", None))
self.Btn_Connect.setText(_translate("Client", "Connect", None))
self.checkBox_Led1.setText(_translate("Client", "Led1", None))
self.label_Servo2.setText(_translate("Client", "0", None))
self.checkBox_Led2.setText(_translate("Client", "Led2", None))
self.checkBox_Led3.setText(_translate("Client", "Led3", None))
self.checkBox_Led4.setText(_translate("Client", "Led4", None))
self.checkBox_Led5.setText(_translate("Client", "Led5", None))
self.checkBox_Led6.setText(_translate("Client", "Led6", None))
self.checkBox_Led7.setText(_translate("Client", "Led7", None))
self.checkBox_Led8.setText(_translate("Client", "Led8", None))
self.label_Servo1.setText(_translate("Client", "90", None))
self.checkBox_Led_Mode2.setText(_translate("Client", "Led_Mode2", None))
self.checkBox_Led_Mode3.setText(_translate("Client", "Led_Mode3", None))
self.checkBox_Led_Mode4.setText(_translate("Client", "Led_Mode4", None))
self.checkBox_Led_Mode1.setText(_translate("Client", "Led_Mode1", None))
self.Color_R.setText(_translate("Client", "255", None))
self.Color_G.setText(_translate("Client", "0", None))
self.Color_B.setText(_translate("Client", "0", None))
self.label_FineServo1.setText(_translate("Client", "0", None))
self.label_FineServo2.setText(_translate("Client", "0", None))
self.Window_Min.setText(_translate("Client", "-", None))
self.R.setText(_translate("Client", "R", None))
self.G.setText(_translate("Client", "G", None))
self.B.setText(_translate("Client", "B", None))
self.Led_Module.setText(_translate("Client", "Led Module", None))
self.Servo1.setText(_translate("Client", "Servo 1", None))
self.Servo2.setText(_translate("Client", "Servo 2", None))
self.Btn_Buzzer.setText(_translate("Client", "Buzzer", None))
self.Ultrasonic.setText(_translate("Client", "Ultrasonic", None))
self.Light.setText(_translate("Client", "Light", None))
self.Btn_Mode1.setText(_translate("Client", "M-Free", None))
self.Btn_Mode2.setText(_translate("Client", "M-Light", None))
self.Btn_Mode3.setText(_translate("Client", "M-Sonic", None))
self.Btn_Mode4.setText(_translate("Client", "M-Line", None))

18
Code/Client/Command.py Normal file
View File

@ -0,0 +1,18 @@
class COMMAND:
CMD_MOTOR = "CMD_MOTOR"
CMD_LED = "CMD_LED"
CMD_LED_MOD = "CMD_LED_MOD"
CMD_SERVO = "CMD_SERVO"
CMD_BUZZER = "CMD_BUZZER"
CMD_SONIC = "CMD_SONIC"
CMD_LIGHT = "CMD_LIGHT"
CMD_POWER = "CMD_POWER"
CMD_CLOSE = "CMD_CLOSE"
CMD_LED_TYPE = "CMD_LED_TYPE"
CMD_START = "Start"
CMD_STOP = "Stop"
CMD_MODE ="CMD_MODE"
def __init__(self):
pass
#self.intervalChar
#self.endChar

639
Code/Client/Main.py Normal file
View File

@ -0,0 +1,639 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import numpy as np
import cv2
import socket
import os
import io
import time
import imghdr
import sys
from threading import Timer
from threading import Thread
from PIL import Image
from Command import COMMAND as cmd
from Thread import *
from Client_Ui import Ui_Client
from Video import *
from PyQt4.QtCore import *
from PyQt4 import QtGui, QtCore
from PyQt4.QtGui import *
from PyQt4.QtCore import pyqtSignature
from PyQt4.QtGui import (QApplication, QMainWindow, QGraphicsScene)
class mywindow(QMainWindow,Ui_Client):
def __init__(self):
global timer
super(mywindow,self).__init__()
self.setupUi(self)
self.endChar='\n'
self.intervalChar='#'
self.h=self.IP.text()
self.TCP=VideoStreaming()
self.servo1=90
self.servo2=90
self.label_FineServo2.setText("0")
self.label_FineServo1.setText("0")
self.m_DragPosition=self.pos()
self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
self.setMouseTracking(True)
self.Key_W=False
self.Key_A=False
self.Key_S=False
self.Key_D=False
self.Key_Space=False
self.setFocusPolicy(Qt.StrongFocus)
self.progress_Power.setMinimum(0)
self.progress_Power.setMaximum(100)
self.name.setAlignment(QtCore.Qt.AlignCenter)
self.label_Servo1.setText('90')
self.label_Servo2.setText('90')
self.label_Video.setAlignment(QtCore.Qt.AlignCenter|QtCore.Qt.AlignVCenter)
self.label_Servo1.setAlignment(QtCore.Qt.AlignCenter|QtCore.Qt.AlignVCenter)
self.label_Servo2.setAlignment(QtCore.Qt.AlignCenter|QtCore.Qt.AlignVCenter)
self.label_FineServo1.setAlignment(QtCore.Qt.AlignCenter|QtCore.Qt.AlignVCenter)
self.label_FineServo2.setAlignment(QtCore.Qt.AlignCenter|QtCore.Qt.AlignVCenter)
self.HSlider_Servo1.setMinimum(0)
self.HSlider_Servo1.setMaximum(180)
self.HSlider_Servo1.setSingleStep(1)
self.HSlider_Servo1.setValue(self.servo1)
self.HSlider_Servo1.valueChanged.connect(self.Change_Left_Right)
self.HSlider_FineServo1.setMinimum(-10)
self.HSlider_FineServo1.setMaximum(10)
self.HSlider_FineServo1.setSingleStep(1)
self.HSlider_FineServo1.setValue(0)
self.HSlider_FineServo1.valueChanged.connect(self.Fine_Tune_Left_Right)
self.HSlider_FineServo2.setMinimum(-10)
self.HSlider_FineServo2.setMaximum(10)
self.HSlider_FineServo2.setSingleStep(1)
self.HSlider_FineServo2.setValue(0)
self.HSlider_FineServo2.valueChanged.connect(self.Fine_Tune_Up_Down)
self.VSlider_Servo2.setMinimum(80)
self.VSlider_Servo2.setMaximum(180)
self.VSlider_Servo2.setSingleStep(1)
self.VSlider_Servo2.setValue(self.servo2)
self.VSlider_Servo2.valueChanged.connect(self.Change_Up_Down)
self.checkBox_Led1.setChecked(False)
self.checkBox_Led1.stateChanged.connect(lambda:self.LedChange(self.checkBox_Led1))
self.checkBox_Led2.setChecked(False)
self.checkBox_Led2.stateChanged.connect(lambda:self.LedChange(self.checkBox_Led2))
self.checkBox_Led3.setChecked(False)
self.checkBox_Led3.stateChanged.connect(lambda:self.LedChange(self.checkBox_Led3))
self.checkBox_Led4.setChecked(False)
self.checkBox_Led4.stateChanged.connect(lambda:self.LedChange(self.checkBox_Led4))
self.checkBox_Led5.setChecked(False)
self.checkBox_Led5.stateChanged.connect(lambda:self.LedChange(self.checkBox_Led5))
self.checkBox_Led6.setChecked(False)
self.checkBox_Led6.stateChanged.connect(lambda:self.LedChange(self.checkBox_Led6))
self.checkBox_Led7.setChecked(False)
self.checkBox_Led7.stateChanged.connect(lambda:self.LedChange(self.checkBox_Led7))
self.checkBox_Led8.setChecked(False)
self.checkBox_Led8.stateChanged.connect(lambda:self.LedChange(self.checkBox_Led8))
self.checkBox_Led_Mode1.setChecked(False)
self.checkBox_Led_Mode1.stateChanged.connect(lambda:self.LedChange(self.checkBox_Led_Mode1))
self.checkBox_Led_Mode2.setChecked(False)
self.checkBox_Led_Mode2.stateChanged.connect(lambda:self.LedChange(self.checkBox_Led_Mode2))
self.checkBox_Led_Mode3.setChecked(False)
self.checkBox_Led_Mode3.stateChanged.connect(lambda:self.LedChange(self.checkBox_Led_Mode3))
self.checkBox_Led_Mode4.setChecked(False)
self.checkBox_Led_Mode4.stateChanged.connect(lambda:self.LedChange(self.checkBox_Led_Mode4))
self.Btn_Mode1.setChecked(True)
self.Btn_Mode1.toggled.connect(lambda:self.on_btn_Mode(self.Btn_Mode1))
self.Btn_Mode2.setChecked(False)
self.Btn_Mode2.toggled.connect(lambda:self.on_btn_Mode(self.Btn_Mode2))
self.Btn_Mode3.setChecked(False)
self.Btn_Mode3.toggled.connect(lambda:self.on_btn_Mode(self.Btn_Mode3))
self.Btn_Mode4.setChecked(False)
self.Btn_Mode4.toggled.connect(lambda:self.on_btn_Mode(self.Btn_Mode4))
self.Ultrasonic.clicked.connect(self.on_btn_Ultrasonic)
self.Light.clicked.connect(self.on_btn_Light)
self.Btn_ForWard.pressed.connect(self.on_btn_ForWard)
self.Btn_ForWard.released.connect(self.on_btn_Stop)
self.Btn_Turn_Left.pressed.connect(self.on_btn_Turn_Left)
self.Btn_Turn_Left.released.connect(self.on_btn_Stop)
self.Btn_BackWard.pressed.connect(self.on_btn_BackWard)
self.Btn_BackWard.released.connect(self.on_btn_Stop)
self.Btn_Turn_Right.pressed.connect(self.on_btn_Turn_Right)
self.Btn_Turn_Right.released.connect(self.on_btn_Stop)
self.Btn_Video.clicked.connect(self.on_btn_video)
self.Btn_Up.clicked.connect(self.on_btn_Up)
self.Btn_Left.clicked.connect(self.on_btn_Left)
self.Btn_Down.clicked.connect(self.on_btn_Down)
self.Btn_Home.clicked.connect(self.on_btn_Home)
self.Btn_Right.clicked.connect(self.on_btn_Right)
self.Btn_Tracking_Faces.clicked.connect(self.Tracking_Face)
self.Btn_Buzzer.pressed.connect(self.on_btn_Buzzer)
self.Btn_Buzzer.released.connect(self.on_btn_Buzzer)
self.Btn_Connect.clicked.connect(self.on_btn_Connect)
self.Window_Min.clicked.connect(self.windowMinimumed)
self.Window_Close.clicked.connect(self.close)
timer = QTimer(self)
self.connect(timer, SIGNAL("timeout()"), self.time)
def mousePressEvent(self, event):
if event.button()==Qt.LeftButton:
self.m_drag=True
self.m_DragPosition=event.globalPos()-self.pos()
event.accept()
def mouseMoveEvent(self, QMouseEvent):
if QMouseEvent.buttons() and Qt.LeftButton:
self.move(QMouseEvent.globalPos()-self.m_DragPosition)
QMouseEvent.accept()
def mouseReleaseEvent(self, QMouseEvent):
self.m_drag=False
def keyPressEvent(self, event):
if(event.key() == Qt.Key_Up):
self.on_btn_Up()
elif(event.key() == Qt.Key_Left):
self.on_btn_Left()
elif(event.key() == Qt.Key_Down):
self.on_btn_Down()
elif(event.key() == Qt.Key_Right):
self.on_btn_Right()
elif(event.key() == Qt.Key_Home):
self.on_btn_Home()
if(event.key() == Qt.Key_Q):
if self.Btn_Mode1.isChecked() == True:
self.Btn_Mode2.setChecked(True)
elif self.Btn_Mode2.isChecked() == True:
self.Btn_Mode3.setChecked(True)
elif self.Btn_Mode3.isChecked() == True:
self.Btn_Mode4.setChecked(True)
elif self.Btn_Mode4.isChecked() == True:
self.Btn_Mode1.setChecked(True)
if(event.key() == Qt.Key_L):
count=0
if self.checkBox_Led_Mode1.isChecked() == True:
self.checkBox_Led_Mode2.setChecked(True)
elif self.checkBox_Led_Mode2.isChecked() == True:
self.checkBox_Led_Mode3.setChecked(True)
elif self.checkBox_Led_Mode3.isChecked() == True:
self.checkBox_Led_Mode4.setChecked(True)
elif self.checkBox_Led_Mode4.isChecked() == True:
self.checkBox_Led_Mode1.setChecked(True)
for i in range(1,5):
checkBox_Led_Mode=getattr(self,"checkBox_Led_Mode%d"%i)
if checkBox_Led_Mode.isChecked() == False:
count+=1
else:
break
if count ==4:
self.checkBox_Led_Mode1.setChecked(True)
if(event.key() == Qt.Key_C):
self.on_btn_Connect()
if(event.key() == Qt.Key_V):
self.on_btn_video()
if(event.key() == Qt.Key_1):
if self.checkBox_Led1.isChecked() == True:
self.checkBox_Led1.setChecked(False)
else:
self.checkBox_Led1.setChecked(True)
elif(event.key() == Qt.Key_2):
if self.checkBox_Led2.isChecked() == True:
self.checkBox_Led2.setChecked(False)
else:
self.checkBox_Led2.setChecked(True)
elif(event.key() == Qt.Key_3):
if self.checkBox_Led3.isChecked() == True:
self.checkBox_Led3.setChecked(False)
else:
self.checkBox_Led3.setChecked(True)
elif(event.key() == Qt.Key_4):
if self.checkBox_Led4.isChecked() == True:
self.checkBox_Led4.setChecked(False)
else:
self.checkBox_Led4.setChecked(True)
elif(event.key() == Qt.Key_5):
if self.checkBox_Led5.isChecked() == True:
self.checkBox_Led5.setChecked(False)
else:
self.checkBox_Led5.setChecked(True)
elif(event.key() == Qt.Key_6):
if self.checkBox_Led6.isChecked() == True:
self.checkBox_Led6.setChecked(False)
else:
self.checkBox_Led6.setChecked(True)
elif(event.key() == Qt.Key_7):
if self.checkBox_Led7.isChecked() == True:
self.checkBox_Led7.setChecked(False)
else:
self.checkBox_Led7.setChecked(True)
elif(event.key() == Qt.Key_8):
if self.checkBox_Led8.isChecked() == True:
self.checkBox_Led8.setChecked(False)
else:
self.checkBox_Led8.setChecked(True)
if event.isAutoRepeat():
pass
else :
if event.key() == Qt.Key_W:
self.on_btn_ForWard()
self.Key_W=True
elif event.key() == Qt.Key_S:
self.on_btn_BackWard()
self.Key_S=True
elif event.key() == Qt.Key_A:
self.on_btn_Turn_Left()
self.Key_A=True
elif event.key() == Qt.Key_D:
self.on_btn_Turn_Right()
self.Key_D=True
elif event.key() == Qt.Key_Space:
self.on_btn_Buzzer()
self.Key_Space=True
def keyReleaseEvent(self, event):
if(event.key() == Qt.Key_W):
time.sleep(0.05)
if(event.key() == Qt.Key_W):
if not(event.isAutoRepeat()) and self.Key_W==True:
self.on_btn_Stop()
self.Key_W=False
elif(event.key() == Qt.Key_A):
if not(event.isAutoRepeat()) and self.Key_A==True:
self.on_btn_Stop()
self.Key_A=False
elif(event.key() == Qt.Key_S):
if not(event.isAutoRepeat()) and self.Key_S==True:
self.on_btn_Stop()
self.Key_S=False
elif(event.key() == Qt.Key_D):
if not(event.isAutoRepeat()) and self.Key_D==True:
self.on_btn_Stop()
self.Key_D=False
if(event.key() == Qt.Key_Space):
if not(event.isAutoRepeat()) and self.Key_Space==True:
self.on_btn_Buzzer()
self.Key_Space=False
def on_btn_ForWard(self):
ForWard=self.intervalChar+str(1500)+self.intervalChar+str(1500)+self.intervalChar+str(1500)+self.intervalChar+str(1500)+self.endChar
self.TCP.sendData(cmd.CMD_MOTOR+ForWard)
def on_btn_Turn_Left(self):
Turn_Left=self.intervalChar+str(-1500)+self.intervalChar+str(-1500)+self.intervalChar+str(1500)+self.intervalChar+str(1500)+self.endChar
self.TCP.sendData(cmd.CMD_MOTOR+ Turn_Left)
def on_btn_BackWard(self):
BackWard=self.intervalChar+str(-1500)+self.intervalChar+str(-1500)+self.intervalChar+str(-1500)+self.intervalChar+str(-1500)+self.endChar
self.TCP.sendData(cmd.CMD_MOTOR+BackWard)
def on_btn_Turn_Right(self):
Turn_Right=self.intervalChar+str(1500)+self.intervalChar+str(1500)+self.intervalChar+str(-1500)+self.intervalChar+str(-1500)+self.endChar
self.TCP.sendData(cmd.CMD_MOTOR+Turn_Right)
def on_btn_Stop(self):
Stop=self.intervalChar+str(0)+self.intervalChar+str(0)+self.intervalChar+str(0)+self.intervalChar+str(0)+self.endChar
self.TCP.sendData(cmd.CMD_MOTOR+Stop)
def on_btn_video(self):
if self.Btn_Video.text()=='Open Video':
timer.start(34)
self.Btn_Video.setText('Close Video')
elif self.Btn_Video.text()=='Close Video':
timer.stop()
self.Btn_Video.setText('Open Video')
def on_btn_Up(self):
self.servo2=self.servo2+10
if self.servo2>=180:
self.servo2=180
self.VSlider_Servo2.setValue(self.servo2)
def on_btn_Left(self):
self.servo1=self.servo1-10
if self.servo1<=0:
self.servo1=0
self.HSlider_Servo1.setValue(self.servo1)
def on_btn_Down(self):
self.servo2=self.servo2-10
if self.servo2<=80:
self.servo2=80
self.VSlider_Servo2.setValue(self.servo2)
def on_btn_Right(self):
self.servo1=self.servo1+10
if self.servo1>=180:
self.servo1=180
self.HSlider_Servo1.setValue(self.servo1)
def on_btn_Home(self):
self.servo1=90
self.servo2=90
self.HSlider_Servo1.setValue(self.servo1)
self.VSlider_Servo2.setValue(self.servo2)
def on_btn_Buzzer(self):
if self.Btn_Buzzer.text()=='Buzzer':
self.TCP.sendData(cmd.CMD_BUZZER+self.intervalChar+'1'+self.endChar)
self.Btn_Buzzer.setText('Noise')
else:
self.TCP.sendData(cmd.CMD_BUZZER+self.intervalChar+'0'+self.endChar)
self.Btn_Buzzer.setText('Buzzer')
def on_btn_Ultrasonic(self):
if self.Ultrasonic.text()=="Ultrasonic":
self.TCP.sendData(cmd.CMD_SONIC+self.intervalChar+'1'+self.endChar)
else:
self.TCP.sendData(cmd.CMD_SONIC+self.intervalChar+'0'+self.endChar)
self.Ultrasonic.setText("Ultrasonic")
def on_btn_Light(self):
if self.Light.text() == "Light":
self.TCP.sendData(cmd.CMD_LIGHT+self.intervalChar+'1'+self.endChar)
else:
self.TCP.sendData(cmd.CMD_LIGHT+self.intervalChar+'0'+self.endChar)
self.Light.setText("Light")
def Change_Left_Right(self):#Left or Right
self.servo1=self.HSlider_Servo1.value()
self.TCP.sendData(cmd.CMD_SERVO+self.intervalChar+'0'+self.intervalChar+str(self.servo1)+self.endChar)
self.label_Servo1.setText("%d"%self.servo1)
def Change_Up_Down(self):#Up or Down
self.servo2=self.VSlider_Servo2.value()
self.TCP.sendData(cmd.CMD_SERVO+self.intervalChar+'1'+self.intervalChar+str(self.servo2)+self.endChar)
self.label_Servo2.setText("%d"%self.servo2)
def Fine_Tune_Left_Right(self):#fine tune Left or Right
self.label_FineServo1.setText(str(self.HSlider_FineServo1.value()))
data=self.servo1+self.HSlider_FineServo1.value()
self.TCP.sendData(cmd.CMD_SERVO+self.intervalChar+'0'+self.intervalChar+str(data)+self.endChar)
def Fine_Tune_Up_Down(self):#fine tune Up or Down
self.label_FineServo2.setText(str(self.HSlider_FineServo2.value()))
data=self.servo2+self.HSlider_FineServo2.value()
self.TCP.sendData(cmd.CMD_SERVO+self.intervalChar+'1'+self.intervalChar+str(data)+self.endChar)
def windowMinimumed(self):
self.showMinimized()
def LedChange(self,b):
R=self.Color_R.text()
G=self.Color_G.text()
B=self.Color_B.text()
led_Off=self.intervalChar+str(0)+self.intervalChar+str(0)+self.intervalChar+str(0)+self.endChar
color=self.intervalChar+str(R)+self.intervalChar+str(G)+self.intervalChar+str(B)+self.endChar
if b.text() == "Led1":
self.led_Index=str(0x01)
if b.isChecked() == True:
self.TCP.sendData(cmd.CMD_LED+self.intervalChar+ self.led_Index+color)
else:
self.TCP.sendData(cmd.CMD_LED+self.intervalChar+ self.led_Index+led_Off)
if b.text() == "Led2":
self.led_Index=str(0x02)
if b.isChecked() == True:
self.TCP.sendData(cmd.CMD_LED+self.intervalChar+ self.led_Index+color)
else:
self.TCP.sendData(cmd.CMD_LED+self.intervalChar+ self.led_Index+led_Off)
if b.text() == "Led3":
self.led_Index=str(0x04)
if b.isChecked() == True:
self.TCP.sendData(cmd.CMD_LED+self.intervalChar+ self.led_Index+color)
else:
self.TCP.sendData(cmd.CMD_LED+self.intervalChar+ self.led_Index+led_Off)
if b.text() == "Led4":
self.led_Index=str(0x08)
if b.isChecked() == True:
self.TCP.sendData(cmd.CMD_LED+self.intervalChar+ self.led_Index+color)
else:
self.TCP.sendData(cmd.CMD_LED+self.intervalChar+ self.led_Index+led_Off)
if b.text() == "Led5":
self.led_Index=str(0x10)
if b.isChecked() == True:
self.TCP.sendData(cmd.CMD_LED+self.intervalChar+ self.led_Index+color)
else:
self.TCP.sendData(cmd.CMD_LED+self.intervalChar+ self.led_Index+led_Off)
if b.text() == "Led6":
self.led_Index=str(0x20)
if b.isChecked() == True:
self.TCP.sendData(cmd.CMD_LED+self.intervalChar+ self.led_Index+color)
else:
self.TCP.sendData(cmd.CMD_LED+self.intervalChar+ self.led_Index+led_Off)
if b.text() == "Led7":
self.led_Index=str(0x40)
if b.isChecked() == True:
self.TCP.sendData(cmd.CMD_LED+self.intervalChar+ self.led_Index+color)
else:
self.TCP.sendData(cmd.CMD_LED+self.intervalChar+ self.led_Index+led_Off)
if b.text() == "Led8":
self.led_Index=str(0x80)
if b.isChecked() == True:
self.TCP.sendData(cmd.CMD_LED+self.intervalChar+ self.led_Index+color)
else:
self.TCP.sendData(cmd.CMD_LED+self.intervalChar+ self.led_Index+led_Off)
if b.text() == "Led_Mode1":
if b.isChecked() == True:
self.checkBox_Led_Mode2.setChecked(False)
self.checkBox_Led_Mode3.setChecked(False)
self.checkBox_Led_Mode4.setChecked(False)
self.TCP.sendData(cmd.CMD_LED_MOD+self.intervalChar+'1'+self.endChar)
else:
self.TCP.sendData(cmd.CMD_LED_MOD+self.intervalChar+'0'+self.endChar)
if b.text() == "Led_Mode2":
if b.isChecked() == True:
self.checkBox_Led_Mode1.setChecked(False)
self.checkBox_Led_Mode3.setChecked(False)
self.checkBox_Led_Mode4.setChecked(False)
self.TCP.sendData(cmd.CMD_LED_MOD+self.intervalChar+'2'+self.endChar)
else:
self.TCP.sendData(cmd.CMD_LED_MOD+self.intervalChar+'0'+self.endChar)
if b.text() == "Led_Mode3":
if b.isChecked() == True:
self.checkBox_Led_Mode2.setChecked(False)
self.checkBox_Led_Mode1.setChecked(False)
self.checkBox_Led_Mode4.setChecked(False)
self.TCP.sendData(cmd.CMD_LED_MOD+self.intervalChar+'3'+self.endChar)
else:
self.TCP.sendData(cmd.CMD_LED_MOD+self.intervalChar+'0'+self.endChar)
if b.text() == "Led_Mode4":
if b.isChecked() == True:
self.checkBox_Led_Mode2.setChecked(False)
self.checkBox_Led_Mode3.setChecked(False)
self.checkBox_Led_Mode1.setChecked(False)
self.TCP.sendData(cmd.CMD_LED_MOD+self.intervalChar+'4'+self.endChar)
else:
self.TCP.sendData(cmd.CMD_LED_MOD+self.intervalChar+'0'+self.endChar)
def on_btn_Mode(self,Mode):
if Mode.text() == "M-Free":
if Mode.isChecked() == True:
timer.start(34)
self.TCP.sendData(cmd.CMD_MODE+self.intervalChar+'one'+self.endChar)
if Mode.text() == "M-Light":
if Mode.isChecked() == True:
timer.stop()
self.TCP.sendData(cmd.CMD_MODE+self.intervalChar+'two'+self.endChar)
if Mode.text() == "M-Sonic":
if Mode.isChecked() == True:
timer.stop()
self.TCP.sendData(cmd.CMD_MODE+self.intervalChar+'three'+self.endChar)
if Mode.text() == "M-Line":
if Mode.isChecked() == True:
timer.stop()
self.TCP.sendData(cmd.CMD_MODE+self.intervalChar+'four'+self.endChar)
def on_btn_Connect(self):
if self.Btn_Connect.text() == "Connect":
self.h=self.IP.text()
self.TCP.StartTcpClient(self.h,)
try:
self.streaming=Thread(target=self.TCP.streaming,args=(self.h,))
self.streaming.start()
except:
print 'video error'
try:
self.recv=Thread(target=self.recvmassage)
self.recv.start()
except:
print 'recv error'
self.Btn_Connect.setText( "Disconnect")
print ('Server address:'+str(self.h)+'\n')
elif self.Btn_Connect.text()=="Disconnect":
self.Btn_Connect.setText( "Connect")
try:
stop_thread(self.recv)
stop_thread(self.power)
stop_thread(self.streaming)
except:
pass
self.TCP.StopTcpcClient()
def close(self):
timer.stop()
try:
stop_thread(self.recv)
stop_thread(self.streaming)
except:
pass
self.TCP.StopTcpcClient()
try:
os.remove("video.jpg")
except:
pass
QCoreApplication.instance().quit()
os._exit(0)
def Power(self):
while True:
try:
self.TCP.sendData(cmd.CMD_POWER+self.endChar)
time.sleep(60)
except:
break
def recvmassage(self):
self.TCP.socket1_connect(self.h)
self.power=Thread(target=self.Power)
self.power.start()
restCmd=""
while True:
Alldata=restCmd+str(self.TCP.recvData())
restCmd=""
print (Alldata)
if Alldata=="":
break
else:
cmdArray=Alldata.split("\n")
if(cmdArray[-1] != ""):
restCmd=cmdArray[-1]
cmdArray=cmdArray[:-1]
for oneCmd in cmdArray:
Massage=oneCmd.split("#")
if cmd.CMD_SONIC in Massage:
self.Ultrasonic.setText('Obstruction:%s cm'%Massage[1])
elif cmd.CMD_LIGHT in Massage:
self.Light.setText("Left:"+Massage[1]+'V'+' '+"Right:"+Massage[2]+'V')
elif cmd. CMD_POWER in Massage:
percent_power=int((float(Massage[1])-7)/1.40*100)
self.progress_Power.setValue(percent_power)
def is_valid_jpg(self,jpg_file):
try:
bValid = True
if jpg_file.split('.')[-1].lower() == 'jpg':
with open(jpg_file, 'rb') as f:
buf=f.read()
if not buf.startswith(b'\xff\xd8'):
bValid = False
elif buf[6:10] in (b'JFIF', b'Exif'):
if not buf.rstrip(b'\0\r\n').endswith(b'\xff\xd9'):
bValid = False
else:
try:
Image.open(f).verify()
except:
bValid = False
else:
return bValid
except:
pass
return bValid
def Tracking_Face(self):
if self.Btn_Tracking_Faces.text()=="Tracing-On":
self.Btn_Tracking_Faces.setText("Tracing-Off")
else:
self.Btn_Tracking_Faces.setText("Tracing-On")
def find_Face(self,face_x,face_y):
if face_x!=0 and face_y!=0:
offset_x=float(face_x/400-0.5)*2
offset_y=float(face_y/300-0.5)*2
delta_degree_x = 4* offset_x
delta_degree_y = -4 * offset_y
self.servo1=self.servo1+delta_degree_x
self.servo2=self.servo2+delta_degree_y
if offset_x > -0.15 and offset_y >-0.15 and offset_x < 0.15 and offset_y <0.15:
pass
else:
self.HSlider_Servo1.setValue(self.servo1)
self.VSlider_Servo2.setValue(self.servo2)
def time(self):
self.TCP.video_Flag=False
if self.is_valid_jpg('video.jpg'):
self.label_Video.setPixmap(QtGui.QPixmap(QtCore.QString.fromUtf8('video.jpg')))
if self.Btn_Tracking_Faces.text()=="Tracing-Off":
self.find_Face(self.TCP.face_x,self.TCP.face_y)
self.TCP.video_Flag=True
if __name__ == '__main__':
app = QApplication(sys.argv)
myshow=mywindow()
myshow.show();
sys.exit(app.exec_())

27
Code/Client/Thread.py Normal file
View File

@ -0,0 +1,27 @@
import threading
import time
import inspect
import ctypes
def _async_raise(tid, exctype):
"""raises the exception, performs cleanup if needed"""
tid = ctypes.c_long(tid)
if not inspect.isclass(exctype):
exctype = type(exctype)
res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype))
if res == 0:
raise ValueError("invalid thread id")
elif res != 1:
ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, None)
raise SystemError("PyThreadState_SetAsyncExc failed")
def stop_thread(thread):
_async_raise(thread.ident, SystemExit)
def test():
while True:
print('-------')
time.sleep(0.05)
if __name__ == "__main__":
t = threading.Thread(target=test)
t.start()
time.sleep(0.2)
print("main thread sleep finish")
stop_thread(t)

101
Code/Client/Video.py Normal file
View File

@ -0,0 +1,101 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import numpy as np
import cv2
import socket
import io
import sys
import struct
from PIL import Image
from multiprocessing import Process
from Command import COMMAND as cmd
class VideoStreaming:
def __init__(self):
self.face_cascade = cv2.CascadeClassifier(r'haarcascade_frontalface_default.xml')
self.video_Flag=True
self.connect_Flag=False
self.face_x=0
self.face_y=0
def StartTcpClient(self,IP):
self.client_socket1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def StopTcpcClient(self):
try:
self.client_socket.shutdown(2)
self.client_socket1.shutdown(2)
self.client_socket.close()
self.client_socket1.close()
except:
pass
def IsValidImage4Bytes(self,buf):
bValid = True
if buf[6:10] in (b'JFIF', b'Exif'):
if not buf.rstrip(b'\0\r\n').endswith(b'\xff\xd9'):
bValid = False
else:
try:
Image.open(io.BytesIO(buf)).verify()
except:
bValid = False
return bValid
def face_detect(self,img):
if sys.platform.startswith('win'):
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces = self.face_cascade.detectMultiScale(gray,1.3,5)
if len(faces)>0 :
for (x,y,w,h) in faces:
self.face_x=float(x+w/2.0)
self.face_y=float(y+h/2.0)
img = cv2.circle(img, (x+w/2,y+h/2), (w+h)/4, (0, 255, 0), 2)
else:
self.face_x=0
self.face_y=0
cv2.imwrite('video.jpg', img)
def streaming(self,ip):
stream_bytes = b' '
try:
self.client_socket.connect((ip, 8000))
self.connection = self.client_socket.makefile('rb')
except:
#print "command port connect failed"
pass
while True:
try:
stream_bytes= self.connection.read(4)
leng=struct.unpack('L', stream_bytes[:4])
jpg=self.connection.read(leng[0])
if self.IsValidImage4Bytes(jpg):
image = cv2.imdecode(np.frombuffer(jpg, dtype=np.uint8), cv2.IMREAD_COLOR)
if self.video_Flag:
self.face_detect(image)
except:
break
def sendData(self,s):
if self.connect_Flag:
self.client_socket1.send(s)
def recvData(self):
data=""
try:
data=self.client_socket1.recv(1024)
except:
pass
return data
def socket1_connect(self,ip):
try:
self.client_socket1.connect((ip, 5000))
self.connect_Flag=True
print "Connecttion Successful !"
except Exception, e:
print "Connect to server Faild!: Server IP is right? Server is opend?"
self.connect_Flag=False
if __name__ == '__main__':
pass

File diff suppressed because it is too large Load Diff

64
Code/Server/ADC.py Normal file
View File

@ -0,0 +1,64 @@
#!/usr/bin/env python3
#############################################################################
# Filename : ADC.py
# Description : ADC and DAC
# Author : freenove
# modification: 2018/09/15
########################################################################
import smbus
import time
class Adc:
def __init__(self):
self.address = 0x48 #default address of PCF8591
self.bus=smbus.SMBus(1)
self.cmd=0x40 #command
def analogRead(self,chn):#read ADC value,chn:0,1,2,3
value=[0,0,0,0,0,0,0,0,0]
for i in range(9):
value[i] = self.bus.read_byte_data(self.address,self.cmd+chn)
value=sorted(value)
return value[4]
def analogWrite(self,value):#write DAC value
self.bus.write_byte_data(address,cmd,value)
def loop(self):
while True:
self.value = self.analogRead(2) #read the ADC value of channel 0,1,2,3
#analogWrite(value) #write the DAC value
self.voltage = self.value / 256.0 * 3.3 #calculate the voltage value
print ('ADC Value : %d, Voltage : %.2f'%(self.value,self.voltage))
time.sleep(0.01)
def recvADC(self,channel):
while(1):
self.value = self.analogRead(channel) #read the ADC value of channel 0,1,2,
self.value1 = self.analogRead(channel)
if self.value==self.value1:
break;
self.voltage = self.value / 256.0 * 3.3 #calculate the voltage value
self.voltage = round(self.voltage,2)
return self.voltage
def destroy():
self.bus.close()
def loop():
while True:
adc=Adc()
Left_IDR=adc.recvADC(0)
print (Left_IDR)
Right_IDR=adc.recvADC(1)
print (Right_IDR)
Power=adc.recvADC(2)*3
print (Power)
time.sleep(1)
#print '----'
def destroy():
pass
# Main program logic follows:
if __name__ == '__main__':
print ('Program is starting ... ')
try:
loop()
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed.
destroy()

22
Code/Server/Buzzer.py Normal file
View File

@ -0,0 +1,22 @@
import time
import RPi.GPIO as GPIO
from Command import COMMAND as cmd
GPIO.setwarnings(False)
Buzzer_Pin = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(Buzzer_Pin,GPIO.OUT)
class Buzzer:
def run(self,command):
if command!="0":
GPIO.output(Buzzer_Pin,True)
else:
GPIO.output(Buzzer_Pin,False)
if __name__=='__main__':
B=Buzzer()
B.run('1')
time.sleep(3)
B.run('0')

12
Code/Server/Command.py Normal file
View File

@ -0,0 +1,12 @@
class COMMAND:
CMD_MOTOR = "CMD_MOTOR"
CMD_LED = "CMD_LED"
CMD_LED_MOD = "CMD_LED_MOD"
CMD_SERVO = "CMD_SERVO"
CMD_BUZZER = "CMD_BUZZER"
CMD_SONIC = "CMD_SONIC"
CMD_LIGHT = "CMD_LIGHT"
CMD_POWER = "CMD_POWER"
CMD_MODE ="CMD_MODE"
def __init__(self):
pass

148
Code/Server/Led.py Normal file
View File

@ -0,0 +1,148 @@
# -*-coding: utf-8 -*-
import time
from rpi_ws281x import *
# LED strip configuration:
LED_COUNT = 8 # Number of LED pixels.
LED_PIN = 18 # GPIO pin connected to the pixels (18 uses PWM!).
LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
LED_DMA = 10 # DMA channel to use for generating signal (try 10)
LED_BRIGHTNESS = 255 # Set to 0 for darkest and 255 for brightest
LED_INVERT = False # True to invert the signal (when using NPN transistor level shift)
LED_CHANNEL = 0 # set to '1' for GPIOs 13, 19, 41, 45 or 53
# Define functions which animate LEDs in various ways.
class Led:
def __init__(self):
#Control the sending order of color data
self.ORDER = "GRB"
# Create NeoPixel object with appropriate configuration.
self.strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
# Intialize the library (must be called once before other functions).
self.strip.begin()
def LED_TYPR(self,order,R_G_B):
B=R_G_B & 255
G=R_G_B >> 8 & 255
R=R_G_B >> 16 & 255
Led_type=["GRB","GBR","RGB", "RBG","BRG","BGR"]
color = [Color(G,R,B),Color(G,B,R),Color(R,G,B),Color(R,B,G),Color(B,R,G),Color(B,G,R)]
if order in Led_type:
return color[Led_type.index(order)]
def colorWipe(self,strip, color, wait_ms=50):
"""Wipe color across display a pixel at a time."""
color=self.LED_TYPR(self.ORDER,color)
for i in range(self.strip.numPixels()):
self.strip.setPixelColor(i, color)
self.strip.show()
time.sleep(wait_ms/1000.0)
def theaterChase(self,strip, color, wait_ms=50, iterations=10):
"""Movie theater light style chaser animation."""
color=self.LED_TYPR(self.ORDER,color)
for j in range(iterations):
for q in range(3):
for i in range(0,self.strip.numPixels(), 3):
self.strip.setPixelColor(i+q, color)
self.strip.show()
time.sleep(wait_ms/1000.0)
for i in range(0, self.strip.numPixels(), 3):
self.strip.setPixelColor(i+q, 0)
def wheel(self,pos):
"""Generate rainbow colors across 0-255 positions."""
if pos<0 or pos >255:
r=g=b=0
elif pos < 85:
r=pos * 3
g=255 - pos * 3
b=0
elif pos < 170:
pos -= 85
r=255 - pos * 3
g=0
b=pos * 3
else:
pos -= 170
r=0
g=pos * 3
b=255 - pos * 3
return self.LED_TYPR(self.ORDER,Color(r,g,b))
def rainbow(self,strip, wait_ms=20, iterations=1):
"""Draw rainbow that fades across all pixels at once."""
for j in range(256*iterations):
for i in range(self.strip.numPixels()):
self.strip.setPixelColor(i, self.wheel((i+j) & 255))
self.strip.show()
time.sleep(wait_ms/1000.0)
def rainbowCycle(self,strip, wait_ms=20, iterations=5):
"""Draw rainbow that uniformly distributes itself across all pixels."""
for j in range(256*iterations):
for i in range(self.strip.numPixels()):
self.strip.setPixelColor(i, self.wheel((int(i * 256 / self.strip.numPixels()) + j) & 255))
self.strip.show()
time.sleep(wait_ms/1000.0)
def theaterChaseRainbow(self,strip, wait_ms=50):
"""Rainbow movie theater light style chaser animation."""
for j in range(256):
for q in range(3):
for i in range(0, self.strip.numPixels(), 3):
self.strip.setPixelColor(i+q, self.wheel((i+j) % 255))
self.strip.show()
time.sleep(wait_ms/1000.0)
for i in range(0, strip.numPixels(), 3):
strip.setPixelColor(i+q, 0)
def ledIndex(self,index,R,G,B):
color=self.LED_TYPR(self.ORDER,Color(R,G,B))
for i in range(8):
if index & 0x01 == 1:
self.strip.setPixelColor(i,color)
self.strip.show()
index=index >> 1
def ledMode(self,n):
self.mode=n
while True:
if self.mode=='1':
self.colorWipe(self.strip, Color(255, 0, 0)) # Red wipe
self.colorWipe(self.strip, Color(0, 255, 0)) # Green wipe
self.colorWipe(self.strip, Color(0, 0, 255)) # Blue wipe
self.colorWipe(self.strip, Color(0,0,0),10)
elif self.mode=='2':
self.theaterChaseRainbow(self.strip)
self.colorWipe(self.strip, Color(0,0,0),10)
elif self.mode=='3':
self.rainbow(self.strip)
self.colorWipe(self.strip, Color(0,0,0),10)
elif self.mode=='4':
self.rainbowCycle(self.strip)
self.colorWipe(self.strip, Color(0,0,0),10)
else:
self.colorWipe(self.strip, Color(0,0,0),10)
break
led=Led()
# Main program logic follows:
if __name__ == '__main__':
print ('Program is starting ... ')
try:
while True:
print "Chaser animation"
led.colorWipe(led.strip, Color(255,0, 0)) # Red wipe
led.colorWipe(led.strip, Color(0, 255, 0)) # Green wipe
led.colorWipe(led.strip, Color(0, 0, 255)) # Blue wipe
led.theaterChaseRainbow(led.strip)
print "Rainbow animation"
led.rainbow(led.strip)
led.rainbowCycle(led.strip)
led.colorWipe(led.strip, Color(0,0,0),10)
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed.
led.colorWipe(led.strip, Color(0,0,0),10)

37
Code/Server/Light.py Normal file
View File

@ -0,0 +1,37 @@
import time
from Motor import *
from ADC import *
class Light:
def run(self):
try:
self.adc=Adc()
self.PWM=Motor()
self.PWM.setMotorModel(0,0,0,0)
while True:
L = self.adc.recvADC(0)
R = self.adc.recvADC(1)
if L < 2.99 and R < 2.99 :
self.PWM.setMotorModel(600,600,600,600)
elif abs(L-R)<0.15:
self.PWM.setMotorModel(0,0,0,0)
elif L > 3 or R > 3:
if L > R :
self.PWM.setMotorModel(-1200,-1200,1400,1400)
elif R > L :
self.PWM.setMotorModel(1400,1400,-1200,-1200)
except KeyboardInterrupt:
led_Car.PWM.setMotorModel(0,0,0,0)
if __name__=='__main__':
print ('Program is starting ... ')
led_Car=Light()
led_Car.run()

View File

@ -0,0 +1,41 @@
import time
from Motor import *
import RPi.GPIO as GPIO
IR01 = 14
IR02 = 15
IR03 = 23
GPIO.setmode(GPIO.BCM)
GPIO.setup(IR01,GPIO.IN)
GPIO.setup(IR02,GPIO.IN)
GPIO.setup(IR03,GPIO.IN)
class Line_Tracking:
def run(self):
while True:
self.LMR=0x00
if GPIO.input(IR01)==True:
self.LMR=(self.LMR | 4)
if GPIO.input(IR02)==True:
self.LMR=(self.LMR | 2)
if GPIO.input(IR03)==True:
self.LMR=(self.LMR | 1)
if self.LMR==2:
PWM.setMotorModel(800,800,800,800)
elif self.LMR==4:
PWM.setMotorModel(-1400,-1400,1400,1400)
elif self.LMR==6:
PWM.setMotorModel(-800,-800,1200,1200)
elif self.LMR==1:
PWM.setMotorModel(1400,1400,-1400,-1400)
elif self.LMR==3:
PWM.setMotorModel(1200,1200,-800,-800)
elif self.LMR==7:
pass
infrared=Line_Tracking()
# Main program logic follows:
if __name__ == '__main__':
print ('Program is starting ... ')
try:
infrared.run()
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed.
PWM.setMotorModel(0,0,0,0)

97
Code/Server/Motor.py Normal file
View File

@ -0,0 +1,97 @@
import time
from PCA9685 import PCA9685
class Motor:
def __init__(self):
self.pwm = PCA9685(0x40, debug=True)
self.pwm.setPWMFreq(50)
def duty_range(self,duty1,duty2,duty3,duty4):
if duty1>4095:
duty1=4095
elif duty1<-4095:
duty1=-4095
if duty2>4095:
duty2=4095
elif duty2<-4095:
duty2=-4095
if duty3>4095:
duty3=4095
elif duty3<-4095:
duty3=-4095
if duty4>4095:
duty4=4095
elif duty4<-4095:
duty4=-4095
return duty1,duty2,duty3,duty4
def left_Upper_Wheel(self,duty):
if duty>0:
self.pwm.setMotorPwm(0,0)
self.pwm.setMotorPwm(1,duty)
elif duty<0:
self.pwm.setMotorPwm(1,0)
self.pwm.setMotorPwm(0,abs(duty))
else:
self.pwm.setMotorPwm(0,4095)
self.pwm.setMotorPwm(1,4095)
def left_Lower_Wheel(self,duty):
if duty>0:
self.pwm.setMotorPwm(3,0)
self.pwm.setMotorPwm(2,duty)
elif duty<0:
self.pwm.setMotorPwm(2,0)
self.pwm.setMotorPwm(3,abs(duty))
else:
self.pwm.setMotorPwm(2,4095)
self.pwm.setMotorPwm(3,4095)
def right_Upper_Wheel(self,duty):
if duty>0:
self.pwm.setMotorPwm(6,0)
self.pwm.setMotorPwm(7,duty)
elif duty<0:
self.pwm.setMotorPwm(7,0)
self.pwm.setMotorPwm(6,abs(duty))
else:
self.pwm.setMotorPwm(6,4095)
self.pwm.setMotorPwm(7,4095)
def right_Lower_Wheel(self,duty):
if duty>0:
self.pwm.setMotorPwm(4,0)
self.pwm.setMotorPwm(5,duty)
elif duty<0:
self.pwm.setMotorPwm(5,0)
self.pwm.setMotorPwm(4,abs(duty))
else:
self.pwm.setMotorPwm(4,4095)
self.pwm.setMotorPwm(5,4095)
def setMotorModel(self,duty1,duty2,duty3,duty4):
duty1,duty2,duty3,duty4=self.duty_range(duty1,duty2,duty3,duty4)
self.left_Upper_Wheel(duty1)
self.left_Lower_Wheel(duty2)
self.right_Upper_Wheel(duty3)
self.right_Lower_Wheel(duty4)
PWM=Motor()
def loop():
PWM.setMotorModel(2000,2000,2000,2000) #Forward
time.sleep(3)
PWM.setMotorModel(-2000,-2000,-2000,-2000) #Back
time.sleep(3)
PWM.setMotorModel(-500,-500,2000,2000) #Left
time.sleep(3)
PWM.setMotorModel(2000,2000,-500,-500) #Right
time.sleep(3)
PWM.setMotorModel(0,0,0,0) #Stop
def destroy():
PWM.setMotorModel(0,0,0,0)
if __name__=='__main__':
try:
loop()
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed.
destroy()

76
Code/Server/PCA9685.py Normal file
View File

@ -0,0 +1,76 @@
#!/usr/bin/python
import time
import math
import smbus
# ============================================================================
# Raspi PCA9685 16-Channel PWM Servo Driver
# ============================================================================
class PCA9685:
# Registers/etc.
__SUBADR1 = 0x02
__SUBADR2 = 0x03
__SUBADR3 = 0x04
__MODE1 = 0x00
__PRESCALE = 0xFE
__LED0_ON_L = 0x06
__LED0_ON_H = 0x07
__LED0_OFF_L = 0x08
__LED0_OFF_H = 0x09
__ALLLED_ON_L = 0xFA
__ALLLED_ON_H = 0xFB
__ALLLED_OFF_L = 0xFC
__ALLLED_OFF_H = 0xFD
def __init__(self, address=0x40, debug=False):
self.bus = smbus.SMBus(1)
self.address = address
self.debug = debug
self.write(self.__MODE1, 0x00)
def write(self, reg, value):
"Writes an 8-bit value to the specified register/address"
self.bus.write_byte_data(self.address, reg, value)
def read(self, reg):
"Read an unsigned byte from the I2C device"
result = self.bus.read_byte_data(self.address, reg)
return result
def setPWMFreq(self, freq):
"Sets the PWM frequency"
prescaleval = 25000000.0 # 25MHz
prescaleval /= 4096.0 # 12-bit
prescaleval /= float(freq)
prescaleval -= 1.0
prescale = math.floor(prescaleval + 0.5)
oldmode = self.read(self.__MODE1);
newmode = (oldmode & 0x7F) | 0x10 # sleep
self.write(self.__MODE1, newmode) # go to sleep
self.write(self.__PRESCALE, int(math.floor(prescale)))
self.write(self.__MODE1, oldmode)
time.sleep(0.005)
self.write(self.__MODE1, oldmode | 0x80)
def setPWM(self, channel, on, off):
"Sets a single PWM channel"
self.write(self.__LED0_ON_L+4*channel, on & 0xFF)
self.write(self.__LED0_ON_H+4*channel, on >> 8)
self.write(self.__LED0_OFF_L+4*channel, off & 0xFF)
self.write(self.__LED0_OFF_H+4*channel, off >> 8)
def setMotorPwm(self,channel,duty):
self.setPWM(channel,0,duty)
def setServoPulse(self, channel, pulse):
"Sets the Servo Pulse,The PWM frequency must be 50HZ"
pulse = pulse*4096/20000 #PWM frequency is 50HZ,the period is 20000us
self.setPWM(channel, 0, int(pulse))
if __name__=='__main__':
pass

36
Code/Server/Thread.py Normal file
View File

@ -0,0 +1,36 @@
import threading
import time
import inspect
import ctypes
def _async_raise(tid, exctype):
"""raises the exception, performs cleanup if needed"""
tid = ctypes.c_long(tid)
if not inspect.isclass(exctype):
exctype = type(exctype)
res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype))
if res == 0:
raise ValueError("invalid thread id")
elif res != 1:
ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, None)
raise SystemError("PyThreadState_SetAsyncExc failed")
def stop_thread(thread):
for i in range(5):
_async_raise(thread.ident, SystemExit)
def test():
while True:
print('-------')
time.sleep(1)
if __name__ == "__main__":
t = threading.Thread(target=test)
t.start()
time.sleep(5)
print("main thread sleep finish")
stop_thread(t)

103
Code/Server/Ultrasonic.py Normal file
View File

@ -0,0 +1,103 @@
import time
from Motor import *
import RPi.GPIO as GPIO
from servo import *
from PCA9685 import PCA9685
GPIO.setwarnings(False)
trigger_pin = 27
echo_pin = 22
GPIO.setmode(GPIO.BCM)
GPIO.setup(trigger_pin,GPIO.OUT)
GPIO.setup(echo_pin,GPIO.IN)
class Ultrasonic:
def send_trigger_pulse(self):
GPIO.output(trigger_pin,True)
time.sleep(0.00015)
GPIO.output(trigger_pin,False)
def wait_for_echo(self,value,timeout):
count = timeout
while GPIO.input(echo_pin) != value and count>0:
count = count-1
def get_distance(self):
distance_cm=[0,0,0,0,0]
for i in range(3):
self.send_trigger_pulse()
self.wait_for_echo(True,10000)
start = time.time()
self.wait_for_echo(False,10000)
finish = time.time()
pulse_len = finish-start
distance_cm[i] = pulse_len/0.000058
distance_cm=sorted(distance_cm)
return int(distance_cm[2])
def run_motor(self,L,M,R):
if (L < 30 and M < 30 and R <30) or M < 30 :
self.PWM.setMotorModel(-1450,-1450,-1450,-1450)
time.sleep(0.1)
if L < R:
self.PWM.setMotorModel(1450,1450,-1450,-1450)
else :
self.PWM.setMotorModel(-1450,-1450,1450,1450)
elif L < 30 and M < 30:
PWM.setMotorModel(1500,1500,-1500,-1500)
elif R < 30 and M < 30:
PWM.setMotorModel(-1500,-1500,1500,1500)
elif L < 20 :
PWM.setMotorModel(2000,2000,-500,-500)
if L < 10 :
PWM.setMotorModel(1500,1500,-1000,-1000)
elif R < 20 :
PWM.setMotorModel(-500,-500,2000,2000)
if R < 10 :
PWM.setMotorModel(-1500,-1500,1500,1500)
else :
self.PWM.setMotorModel(600,600,600,600)
def run(self):
self.PWM=Motor()
self.pwm_S=Servo()
for i in range(30,151,60):
self.pwm_S.setServoPwm('0',i)
time.sleep(0.2)
if i==30:
L = self.get_distance()
elif i==90:
M = self.get_distance()
else:
R = self.get_distance()
while True:
for i in range(90,30,-60):
self.pwm_S.setServoPwm('0',i)
time.sleep(0.2)
if i==30:
L = self.get_distance()
elif i==90:
M = self.get_distance()
else:
R = self.get_distance()
self.run_motor(L,M,R)
for i in range(30,151,60):
self.pwm_S.setServoPwm('0',i)
time.sleep(0.2)
if i==30:
L = self.get_distance()
elif i==90:
M = self.get_distance()
else:
R = self.get_distance()
self.run_motor(L,M,R)
ultrasonic=Ultrasonic()
# Main program logic follows:
if __name__ == '__main__':
print ('Program is starting ... ')
try:
ultrasonic.run()
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed.
PWM.setMotorModel(0,0,0,0)
ultrasonic.pwm_S.setServoPwm('0',90)

122
Code/Server/main.py Normal file
View File

@ -0,0 +1,122 @@
import io
import os
import socket
import struct
import time
import picamera
import sys,getopt
from threading import Thread
from server_ui import Ui_server_ui
from PyQt4.QtCore import *
from Thread import *
from PyQt4 import QtGui, QtCore
from PyQt4.QtGui import *
from PyQt4.QtCore import pyqtSignature
from PyQt4.QtGui import (QApplication, QMainWindow, QGraphicsScene)
from server import Server
class mywindow(QMainWindow,Ui_server_ui):
def __init__(self):
super(mywindow,self).__init__()
self.setupUi(self)
self.user_ui=True
self.m_DragPosition=self.pos()
self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
self.setMouseTracking(True)
self.Button_Server.setText("On")
self.Button_Server.clicked.connect(self.on_pushButton)
self.pushButton_Close.clicked.connect(self.close)
self.pushButton_Min.clicked.connect(self.windowMinimumed)
self.TCP_Server=Server()
self.parseOpt()
def windowMinimumed(self):
self.showMinimized()
def mousePressEvent(self, event):
if event.button()==Qt.LeftButton:
self.m_drag=True
self.m_DragPosition=event.globalPos()-self.pos()
event.accept()
def mouseMoveEvent(self, QMouseEvent):
if QMouseEvent.buttons() and Qt.LeftButton:
self.move(QMouseEvent.globalPos()-self.m_DragPosition)
QMouseEvent.accept()
def mouseReleaseEvent(self, QMouseEvent):
self.m_drag=False
def parseOpt(self):
self.opts,self.args = getopt.getopt(sys.argv[1:],"tn")
for o,a in self.opts:
if o in ('-t'):
print "Open TCP"
self.TCP_Server.StartTcpServer()
self.ReadData=Thread(target=self.TCP_Server.readdata)
self.SendVideo=Thread(target=self.TCP_Server.sendvideo)
self.power=Thread(target=self.TCP_Server.Power)
self.SendVideo.start()
self.ReadData.start()
self.power.start()
self.label.setText("Server On")
self.Button_Server.setText("Off")
elif o in ('-n'):
self.user_ui=False
def close(self):
try:
stop_thread(self.SendVideo)
stop_thread(self.ReadData)
stop_thread(self.power)
except:
pass
try:
self.TCP_Server.server_socket.shutdown(2)
self.TCP_Server.server_socket1.shutdown(2)
self.TCP_Server.StopTcpServer()
except:
pass
print "Close TCP"
QCoreApplication.instance().quit()
os._exit(0)
def on_pushButton(self):
if self.label.text()=="Server Off":
self.label.setText("Server On")
self.Button_Server.setText("Off")
self.TCP_Server.tcp_Flag = True
print "Open TCP"
self.TCP_Server.StartTcpServer()
self.SendVideo=Thread(target=self.TCP_Server.sendvideo)
self.ReadData=Thread(target=self.TCP_Server.readdata)
self.power=Thread(target=self.TCP_Server.Power)
self.SendVideo.start()
self.ReadData.start()
self.power.start()
elif self.label.text()=='Server On':
self.label.setText("Server Off")
self.Button_Server.setText("On")
self.TCP_Server.tcp_Flag = False
try:
stop_thread(self.ReadData)
stop_thread(self.power)
stop_thread(self.SendVideo)
except:
pass
self.TCP_Server.StopTcpServer()
print "Close TCP"
if __name__ == '__main__':
app = QApplication(sys.argv)
myshow=mywindow()
if myshow.user_ui==True:
myshow.show();
sys.exit(app.exec_())
else:
try:
while(1):
pass
except KeyboardInterrupt:
myshow.close()

294
Code/Server/server.py Normal file
View File

@ -0,0 +1,294 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import io
import socket
import struct
import time
import picamera
import fcntl
import sys
import threading
from Motor import *
from servo import *
from Led import *
from Buzzer import *
from ADC import *
from Thread import *
from Light import *
from Ultrasonic import *
from Line_Tracking import *
from threading import Timer
from threading import Thread
from Command import COMMAND as cmd
class Server:
def __init__(self):
self.PWM=Motor()
self.servo=Servo()
self.led=Led()
self.ultrasonic=Ultrasonic()
self.buzzer=Buzzer()
self.adc=Adc()
self.light=Light()
self.infrared=Line_Tracking()
self.tcp_Flag = True
self.sonic=False
self.Light=False
self.Mode = 'one'
self.endChar='\n'
self.intervalChar='#'
def get_interface_ip(self):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s',
"wlan0"[:15]))[20:24])
def StartTcpServer(self):
HOST=str(self.get_interface_ip())
self.server_socket1 = socket.socket()
self.server_socket1.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEPORT,1)
self.server_socket1.bind((HOST, 5000))
self.server_socket1.listen(1)
self.server_socket = socket.socket()
self.server_socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEPORT,1)
self.server_socket.bind((HOST, 8000))
self.server_socket.listen(1)
print('Server address: '+HOST)
def StopTcpServer(self):
try:
self.connection.close()
self.connection1.close()
except Exception , e:
print '\n'+"No client connection"
def Reset(self):
self.StopTcpServer()
self.StartTcpServer()
self.SendVideo=Thread(target=self.sendvideo)
self.ReadData=Thread(target=self.readdata)
self.SendVideo.start()
self.ReadData.start()
def sendvideo(self):
try:
self.connection,self.client_address = self.server_socket.accept()
self.connection=self.connection.makefile('rb')
except:
pass
self.server_socket.close()
try:
with picamera.PiCamera() as camera:
camera.resolution = (400,300) # pi camera resolution
camera.framerate = 30 # 15 frames/sec
time.sleep(2) # give 2 secs for camera to initilize
start = time.time()
stream = io.BytesIO()
# send jpeg format video stream
print "Start transmit ... "
for foo in camera.capture_continuous(stream, 'jpeg', use_video_port = True):
try:
self.connection.flush()
stream.seek(0)
b = stream.read()
lengthBin = struct.pack('L', len(b))
self.connection.write(lengthBin)
self.connection.write(b)
if time.time() - start > 600:
break
stream.seek(0)
stream.truncate()
except :
print "End transmit ... "
break
except:
#print "Camera unintall"
pass
def stopMode(self):
try:
stop_thread(self.infraredRun)
self.PWM.setMotorModel(0,0,0,0)
except:
pass
try:
stop_thread(self.lightRun)
self.PWM.setMotorModel(0,0,0,0)
except:
pass
try:
stop_thread(self.ultrasonicRun)
self.PWM.setMotorModel(0,0,0,0)
self.servo.setServoPwm('0',90)
self.servo.setServoPwm('1',90)
except:
pass
def readdata(self):
try:
self.connection1,self.client_address1 = self.server_socket1.accept()
print "Client connection successful !"
except:
print "Client connect failed"
restCmd=""
self.server_socket1.close()
while True:
try:
AllData=restCmd+self.connection1.recv(1024)
except:
if self.tcp_Flag:
self.Reset()
break
if len(AllData) < 5:
restCmd=AllData
if restCmd=='' and self.tcp_Flag:
self.Reset()
break
restCmd=""
if AllData=='':
break
else:
cmdArray=AllData.split("\n")
if(cmdArray[-1] != ""):
restCmd=cmdArray[-1]
cmdArray=cmdArray[:-1]
for oneCmd in cmdArray:
data=oneCmd.split("#")
if data==None:
continue
elif cmd.CMD_MODE in data:
if data[1]=='one':
self.stopMode()
self.Mode='one'
elif data[1]=='two':
self.stopMode()
self.Mode='two'
self.lightRun=Thread(target=self.light.run)
self.lightRun.start()
elif data[1]=='three':
self.stopMode()
self.Mode='three'
self.ultrasonicRun=threading.Thread(target=self.ultrasonic.run)
self.ultrasonicRun.start()
elif data[1]=='four':
self.stopMode()
self.Mode='four'
self.infraredRun=threading.Thread(target=self.infrared.run)
self.infraredRun.start()
elif (cmd.CMD_MOTOR in data) and self.Mode=='one':
try:
data1=int(data[1])
data2=int(data[2])
data3=int(data[3])
data4=int(data[4])
if data1==None or data2==None or data2==None or data3==None:
continue
self.PWM.setMotorModel(data1,data2,data3,data4)
except:
pass
elif cmd.CMD_SERVO in data:
try:
data1=data[1]
data2=int(data[2])
if data1==None or data2==None:
continue
self.servo.setServoPwm(data1,data2)
except:
pass
elif cmd.CMD_LED in data:
try:
data1=int(data[1])
data2=int(data[2])
data3=int(data[3])
data4=int(data[4])
if data1==None or data2==None or data2==None or data3==None:
continue
self.led.ledIndex(data1,data2,data3,data4)
except:
pass
elif cmd.CMD_LED_MOD in data:
self.LedMoD=data[1]
if self.LedMoD== '0':
try:
stop_thread(Led_Mode)
except:
pass
self.led.ledMode(self.LedMoD)
time.sleep(0.1)
self.led.ledMode(self.LedMoD)
else :
try:
stop_thread(Led_Mode)
except:
pass
time.sleep(0.1)
Led_Mode=Thread(target=self.led.ledMode,args=(data[1],))
Led_Mode.start()
elif cmd.CMD_SONIC in data:
if data[1]=='1':
self.sonic=True
self.ultrasonicTimer = threading.Timer(0.5,self.sendUltrasonic)
self.ultrasonicTimer.start()
else:
self.sonic=False
elif cmd.CMD_BUZZER in data:
try:
self.buzzer.run(data[1])
except:
pass
elif cmd.CMD_LIGHT in data:
if data[1]=='1':
self.Light=True
self.lightTimer = threading.Timer(0.3,self.sendLight)
self.lightTimer.start()
else:
self.Light=False
elif cmd.CMD_POWER in data:
ADC_Power=self.adc.recvADC(2)*3
try:
self.connection1.send(cmd.CMD_POWER+'#'+str(ADC_Power)+'\n')
except:
pass
self.StopTcpServer()
def sendUltrasonic(self):
if self.sonic==True:
ADC_Ultrasonic=self.ultrasonic.get_distance()
if ADC_Ultrasonic==self.ultrasonic.get_distance():
try:
self.connection1.send(cmd.CMD_SONIC+"#"+str(ADC_Ultrasonic)+'\n')
except:
self.sonic=False
self.ultrasonicTimer = threading.Timer(0.13,self.sendUltrasonic)
self.ultrasonicTimer.start()
def sendLight(self):
if self.Light==True:
ADC_Light1=self.adc.recvADC(0)
ADC_Light2=self.adc.recvADC(1)
try:
self.connection1.send(cmd.CMD_LIGHT+'#'+str(ADC_Light1)+'#'+str(ADC_Light2)+'\n')
except:
self.Light=False
self.lightTimer = threading.Timer(0.17,self.sendLight)
self.lightTimer.start()
def Power(self):
while True:
ADC_Power=self.adc.recvADC(2)*3
time.sleep(3)
if ADC_Power < 6.8:
for i in range(4):
self.buzzer.run('1')
time.sleep(0.1)
self.buzzer.run('0')
time.sleep(0.1)
elif ADC_Power< 7:
for i in range(2):
self.buzzer.run('1')
time.sleep(0.1)
self.buzzer.run('0')
time.sleep(0.1)
else:
self.buzzer.run('0')
if __name__=='__main__':
passS

127
Code/Server/server_ui.py Normal file
View File

@ -0,0 +1,127 @@
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'C:/Users/Freenove/Desktop/test/qss/server_ui.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_server_ui(object):
def setupUi(self, server_ui):
server_ui.setObjectName(_fromUtf8("server_ui"))
server_ui.resize(400, 300)
server_ui.setStyleSheet(_fromUtf8("QWidget{\n"
"background:#484848;\n"
"}\n"
"QAbstractButton{\n"
"border-style:none;\n"
"border-radius:0px;\n"
"padding:5px;\n"
"color:#DCDCDC;\n"
"background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #484848,stop:1 #383838);\n"
"}\n"
"QAbstractButton:hover{\n"
"color:#FFFFFF;\n"
"background-color:#00BB9E;\n"
"}\n"
"QAbstractButton:pressed{\n"
"color:#DCDCDC;\n"
"border-style:solid;\n"
"border-width:0px 0px 0px 2px;\n"
"padding:4px 4px 4px 2px;\n"
"border-color:#00BB9E;\n"
"background-color:#444444;\n"
"}\n"
"QLabel{\n"
"color:#DCDCDC;\n"
"border:1px solid #484848;\n"
"background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #484848,stop:1 #383838);\n"
"}\n"
"QLabel:focus{\n"
"border:1px solid #00BB9E;\n"
"background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #646464,stop:1 #525252);\n"
"}\n"
"QLineEdit{\n"
"border:1px solid #242424;\n"
"border-radius:3px;\n"
"padding:2px;\n"
"background:none;\n"
"selection-background-color:#484848;\n"
"selection-color:#DCDCDC;\n"
"}\n"
"QLineEdit:focus,QLineEdit:hover{\n"
"border:1px solid #242424;\n"
"}\n"
"QLineEdit{\n"
"border:1px solid #242424;\n"
"border-radius:3px;\n"
"padding:2px;\n"
"background:none;\n"
"selection-background-color:#484848;\n"
"selection-color:#DCDCDC;\n"
"}\n"
"\n"
"QLineEdit:focus,QLineEdit:hover{\n"
"border:1px solid #242424;\n"
"}\n"
"QLineEdit{\n"
"lineedit-password-character:9679;\n"
"}"))
self.label = QtGui.QLabel(server_ui)
self.label.setGeometry(QtCore.QRect(100, 150, 200, 42))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(26)
self.label.setFont(font)
self.label.setObjectName(_fromUtf8("label"))
self.Button_Server = QtGui.QPushButton(server_ui)
self.Button_Server.setGeometry(QtCore.QRect(150, 220, 100, 40))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(12)
self.Button_Server.setFont(font)
self.Button_Server.setObjectName(_fromUtf8("Button_Server"))
self.label_2 = QtGui.QLabel(server_ui)
self.label_2.setGeometry(QtCore.QRect(0, 0, 301, 41))
font = QtGui.QFont()
font.setFamily(_fromUtf8("3ds"))
font.setPointSize(28)
font.setBold(True)
font.setWeight(75)
self.label_2.setFont(font)
self.label_2.setStyleSheet(_fromUtf8(""))
self.label_2.setObjectName(_fromUtf8("label_2"))
self.pushButton_Close = QtGui.QPushButton(server_ui)
self.pushButton_Close.setGeometry(QtCore.QRect(350, 0, 50, 40))
self.pushButton_Close.setObjectName(_fromUtf8("pushButton_Close"))
self.pushButton_Min = QtGui.QPushButton(server_ui)
self.pushButton_Min.setGeometry(QtCore.QRect(300, 0, 50, 40))
self.pushButton_Min.setObjectName(_fromUtf8("pushButton_Min"))
self.retranslateUi(server_ui)
QtCore.QMetaObject.connectSlotsByName(server_ui)
def retranslateUi(self, server_ui):
server_ui.setWindowTitle(_translate("server_ui", "Form", None))
self.label.setText(_translate("server_ui", "Server Off", None))
self.Button_Server.setText(_translate("server_ui", "Off", None))
self.label_2.setText(_translate("server_ui", "Freenove", None))
self.pushButton_Close.setText(_translate("server_ui", "×", None))
self.pushButton_Min.setText(_translate("server_ui", "-", None))

41
Code/Server/servo.py Normal file
View File

@ -0,0 +1,41 @@
import time
from PCA9685 import PCA9685
class Servo:
def __init__(self):
self.PwmServo = PCA9685(0x40, debug=True)
self.PwmServo.setPWMFreq(50)
self.PwmServo.setServoPulse(8,1500)
self.PwmServo.setServoPulse(9,1500)
def setServoPwm(self,channel,angle,error=10):
angle=int(angle)
if channel=='0':
self.PwmServo.setServoPulse(8,2500-int((angle+error)/0.09))
elif channel=='1':
self.PwmServo.setServoPulse(9,500+int((angle+error)/0.09))
elif channel=='2':
self.PwmServo.setServoPulse(10,500+int((angle+error)/0.09))
elif channel=='3':
self.PwmServo.setServoPulse(11,500+int((angle+error)/0.09))
elif channel=='4':
self.PwmServo.setServoPulse(12,500+int((angle+error)/0.09))
elif channel=='5':
self.PwmServo.setServoPulse(13,500+int((angle+error)/0.09))
elif channel=='6':
self.PwmServo.setServoPulse(14,500+int((angle+error)/0.09))
elif channel=='7':
self.PwmServo.setServoPulse(15,500+int((angle+error)/0.09))
# Main program logic follows:
if __name__ == '__main__':
pwm=Servo()
pwm.setServoPwm('0',90)
pwm.setServoPwm('1',90)

172
Code/Server/test.py Normal file
View File

@ -0,0 +1,172 @@
import time
from Led import *
led=Led()
def test_Led():
try:
led.ledIndex(0x01,255,0,0) #Red
led.ledIndex(0x02,255,125,0) #orange
led.ledIndex(0x04,255,255,0) #yellow
led.ledIndex(0x08,0,255,0) #green
led.ledIndex(0x10,0,255,255) #cyan-blue
led.ledIndex(0x20,0,0,255) #blue
led.ledIndex(0x40,128,0,128) #purple
led.ledIndex(0x80,255,255,255) #white'''
print "The LED has been lit, the color is red orange yellow green cyan-blue blue white"
time.sleep(3) #wait 3s
led.colorWipe(led.strip, Color(0,0,0)) #turn off the light
print "\nEnd of program"
except KeyboardInterrupt:
led.colorWipe(led.strip, Color(0,0,0)) #turn off the light
print "\nEnd of program"
from Motor import *
PWM=Motor()
def test_Motor():
try:
PWM.setMotorModel(1000,1000,1000,1000) #Forward
print "The car is moving forward"
time.sleep(1)
PWM.setMotorModel(-1000,-1000,-1000,-1000) #Back
print "The car is going backwards"
time.sleep(1)
PWM.setMotorModel(-1500,-1500,2000,2000) #Left
print "The car is turning left"
time.sleep(1)
PWM.setMotorModel(2000,2000,-1500,-1500) #Right
print "The car is turning right"
time.sleep(1)
PWM.setMotorModel(0,0,0,0) #Stop
print "\nEnd of program"
except KeyboardInterrupt:
PWM.setMotorModel(0,0,0,0)
print "\nEnd of program"
from Ultrasonic import *
ultrasonic=Ultrasonic()
def test_Ultrasonic():
try:
while True:
data=ultrasonic.get_distance() #Get the value
print ("Obstacle distance is "+str(data)+"CM")
time.sleep(1)
except KeyboardInterrupt:
print "\nEnd of program"
from Line_Tracking import *
def test_Infrared():
try:
while True:
if GPIO.input(IR01)!=True and GPIO.input(IR02)==True and GPIO.input(IR03)!=True:
print 'Middle'
elif GPIO.input(IR01)!=True and GPIO.input(IR02)!=True and GPIO.input(IR03)==True:
print 'Right'
elif GPIO.input(IR01)==True and GPIO.input(IR02)!=True and GPIO.input(IR03)!=True:
print 'Left'
except KeyboardInterrupt:
print "\nEnd of program"
from servo import *
pwm=Servo()
def test_Servo():
try:
while True:
for i in range(50,110,1):
pwm.setServoPwm('0',i)
time.sleep(0.01)
for i in range(110,50,-1):
pwm.setServoPwm('0',i)
time.sleep(0.01)
for i in range(80,150,1):
pwm.setServoPwm('1',i)
time.sleep(0.01)
for i in range(150,80,-1):
pwm.setServoPwm('1',i)
time.sleep(0.01)
except KeyboardInterrupt:
pwm.setServoPwm('0',90)
pwm.setServoPwm('1',90)
print "\nEnd of program"
from ADC import *
adc=Adc()
def test_Adc():
try:
while True:
Left_IDR=adc.recvADC(0)
print ("The photoresistor voltage on the left is "+str(Left_IDR)+"V")
Right_IDR=adc.recvADC(1)
print ("The photoresistor voltage on the right is "+str(Right_IDR)+"V")
Power=adc.recvADC(2)
print ("The battery voltage is "+str(Power*3)+"V")
time.sleep(1)
print '\n'
except KeyboardInterrupt:
print "\nEnd of program"
from Buzzer import *
buzzer=Buzzer()
def test_Buzzer():
try:
buzzer.run('1')
time.sleep(1)
print "1S"
time.sleep(1)
print "2S"
time.sleep(1)
print "3S"
buzzer.run('0')
print "\nEnd of program"
except KeyboardInterrupt:
buzzer.run('0')
print "\nEnd of program"
import cv2
def test_Camera():
try:
print "\nOpen camera"
capturing_Flag = True
cap = cv2.VideoCapture(0)
while(capturing_Flag):
ret, frame = cap.read()
cv2.imshow("Capture", frame)
cv2.waitKey(5)
cv2.destroyAllWindows()
except KeyboardInterrupt:
print "\nClose camera"
capturing_Flag = False
# Main program logic follows:
if __name__ == '__main__':
print ('Program is starting ... ')
import sys
if len(sys.argv)<2:
print "Parameter error: Please assign the device"
exit()
if sys.argv[1] == 'Led':
test_Led()
elif sys.argv[1] == 'Motor':
test_Motor()
elif sys.argv[1] == 'Ultrasonic':
test_Ultrasonic()
elif sys.argv[1] == 'Infrared':
test_Infrared()
elif sys.argv[1] == 'Servo':
test_Servo()
elif sys.argv[1] == 'ADC':
test_Adc()
elif sys.argv[1] == 'Buzzer':
test_Buzzer()
elif sys.argv[1] == 'Camera':
test_Camera()

BIN
Tutorial.pdf Normal file

Binary file not shown.