first commit
This commit is contained in:
commit
a0c4234dec
542
Code/Client/Client_Ui.py
Normal file
542
Code/Client/Client_Ui.py
Normal file
@ -0,0 +1,542 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Form implementation generated from reading ui file 'C:/Users/Freenove/Desktop/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_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.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.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.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.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.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.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.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.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.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.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.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.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.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, 91, 31))
|
||||||
|
font = QtGui.QFont()
|
||||||
|
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, 91, 31))
|
||||||
|
font = QtGui.QFont()
|
||||||
|
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, 91, 31))
|
||||||
|
font = QtGui.QFont()
|
||||||
|
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, 91, 31))
|
||||||
|
font = QtGui.QFont()
|
||||||
|
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.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.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))
|
||||||
|
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))
|
||||||
|
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))
|
||||||
|
self.Btn_Mode1.setObjectName(_fromUtf8("Btn_Mode1"))
|
||||||
|
self.Btn_Mode2 = QtGui.QRadioButton(Client)
|
||||||
|
self.Btn_Mode2.setGeometry(QtCore.QRect(340, 450, 90, 30))
|
||||||
|
self.Btn_Mode2.setObjectName(_fromUtf8("Btn_Mode2"))
|
||||||
|
self.Btn_Mode3 = QtGui.QRadioButton(Client)
|
||||||
|
self.Btn_Mode3.setGeometry(QtCore.QRect(340, 500, 90, 30))
|
||||||
|
self.Btn_Mode3.setObjectName(_fromUtf8("Btn_Mode3"))
|
||||||
|
self.Btn_Mode4 = QtGui.QRadioButton(Client)
|
||||||
|
self.Btn_Mode4.setGeometry(QtCore.QRect(340, 550, 90, 30))
|
||||||
|
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_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", "192.168.1.118", 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))
|
||||||
|
|
55
Code/Client/Command.py
Normal file
55
Code/Client/Command.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
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_START = "Start"
|
||||||
|
CMD_STOP = "Stop"
|
||||||
|
CMD_CLOSE = "CMD_CLOSE"
|
||||||
|
CMD_FORWARD = "CMD_MOTOR#1500#1500#1500#1500"
|
||||||
|
CMD_TURULEFT = "CMD_MOTOR#-1500#-1500#1500#1500"
|
||||||
|
CMD_BACKWARD = "CMD_MOTOR#-1500#-1500#-1500#-1500"
|
||||||
|
CMD_TURNRIGHT = "CMD_MOTOR#1500#1500#-1500#-1500"
|
||||||
|
CMD_MOTORSTOP = "CMD_MOTOR#0#0#0#0"
|
||||||
|
CMD_SERVO1 = "CMD_SERVO#1#0#"
|
||||||
|
CMD_SERVO2 = "CMD_SERVO#0#1#0#"
|
||||||
|
CMD_LED0_OFF = "CMD_LED#0#0#0#0"
|
||||||
|
CMD_LED0_ON = "CMD_LED#0#"
|
||||||
|
CMD_LED1_OFF = "CMD_LED#1#0#0#0"
|
||||||
|
CMD_LED1_ON = "CMD_LED#1#"
|
||||||
|
CMD_LED2_OFF = "CMD_LED#2#0#0#0"
|
||||||
|
CMD_LED2_ON = "CMD_LED#2#"
|
||||||
|
CMD_LED3_OFF = "CMD_LED#3#0#0#0"
|
||||||
|
CMD_LED3_ON = "CMD_LED#3#"
|
||||||
|
CMD_LED4_OFF = "CMD_LED#4#0#0#0"
|
||||||
|
CMD_LED4_ON = "CMD_LED#4#"
|
||||||
|
CMD_LED5_OFF = "CMD_LED#5#0#0#0"
|
||||||
|
CMD_LED5_ON = "CMD_LED#5#"
|
||||||
|
CMD_LED6_OFF = "CMD_LED#6#0#0#0"
|
||||||
|
CMD_LED6_ON = "CMD_LED#6#"
|
||||||
|
CMD_LED7_OFF = "CMD_LED#7#0#0#0"
|
||||||
|
CMD_LED7_ON = "CMD_LED#7#"
|
||||||
|
CMD_LED_MOD1 = "CMD_LED_MOD#one"
|
||||||
|
CMD_LED_MOD2 = "CMD_LED_MOD#two"
|
||||||
|
CMD_LED_MOD3 = "CMD_LED_MOD#three"
|
||||||
|
CMD_LED_MOD4 = "CMD_LED_MOD#four"
|
||||||
|
CMD_LED_OFF = "CMD_LED_MOD#0"
|
||||||
|
CMD_BUZZER_ON = "CMD_BUZZER#Start"
|
||||||
|
CMD_BUZZER_OFF = "CMD_BUZZER#Stop"
|
||||||
|
|
||||||
|
CMD_ULTRASONIC_ON = "CMD_SONIC#Start"
|
||||||
|
CMD_ULTRASONIC_OFF = "CMD_SONIC#Stop"
|
||||||
|
|
||||||
|
CMD_LIGHT_ON = "CMD_LIGHT#Start"
|
||||||
|
CMD_LIGHT_OFF = "CMD_LIGHT#Stop"
|
||||||
|
|
||||||
|
CMD_POWER_ON = "CMD_POWER#Start"
|
||||||
|
CMD_POWER_OFF = "CMD_POWER#Stop"
|
||||||
|
CMD_MODE =["CMD_MODE1","CMD_MODE2","CMD_MODE3","CMD_MODE4"]
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
653
Code/Client/Main.py
Normal file
653
Code/Client/Main.py
Normal file
@ -0,0 +1,653 @@
|
|||||||
|
#!/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.h=self.IP.text()
|
||||||
|
self.TCP=VideoStreaming()
|
||||||
|
self.servo1=90
|
||||||
|
self.servo2=20
|
||||||
|
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('20')
|
||||||
|
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(0)
|
||||||
|
self.VSlider_Servo2.setMaximum(150)
|
||||||
|
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_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 close(self):
|
||||||
|
timer.stop()
|
||||||
|
try:
|
||||||
|
self.TCP.sendData(cmd.CMD_POWER_OFF)
|
||||||
|
self.TCP.sendData(cmd.CMD_CLOSE)
|
||||||
|
stop_thread(self.streaming)
|
||||||
|
stop_thread(self.recv)
|
||||||
|
self.TCP.StopTcpcClient()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
os.remove("video.jpg")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
QCoreApplication.instance().quit()
|
||||||
|
os._exit(0)
|
||||||
|
|
||||||
|
def recvmassage(self):
|
||||||
|
self.receflag=1
|
||||||
|
try:
|
||||||
|
self.TCP.socket1_connect(self.h)
|
||||||
|
self.TCP.sendData(cmd.CMD_POWER_ON)
|
||||||
|
while True:
|
||||||
|
Alldata=self.TCP.recvData()
|
||||||
|
if Alldata==None:
|
||||||
|
pass
|
||||||
|
elif Alldata=='':
|
||||||
|
break
|
||||||
|
elif len(Alldata)>21:
|
||||||
|
continue
|
||||||
|
else :
|
||||||
|
Massage=Alldata.split("#")
|
||||||
|
if cmd.CMD_SONIC in Massage:
|
||||||
|
self.Ultrasonic.setText('Obstruction:%s cm'%Massage[1])
|
||||||
|
elif cmd.CMD_SERVO in Massage:
|
||||||
|
print Massage
|
||||||
|
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])*3-7)/1.40*100)
|
||||||
|
self.progress_Power.setValue(percent_power)
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
except :
|
||||||
|
pass
|
||||||
|
|
||||||
|
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 :
|
||||||
|
#print "You Pressed Key : ", event.key(), event.text()
|
||||||
|
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):
|
||||||
|
self.TCP.sendData(cmd.CMD_FORWARD)
|
||||||
|
|
||||||
|
def on_btn_Turn_Left(self):
|
||||||
|
self.TCP.sendData(cmd.CMD_TURULEFT)
|
||||||
|
|
||||||
|
def on_btn_BackWard(self):
|
||||||
|
self.TCP.sendData(cmd.CMD_BACKWARD)
|
||||||
|
|
||||||
|
def on_btn_Turn_Right(self):
|
||||||
|
self.TCP.sendData(cmd.CMD_TURNRIGHT)
|
||||||
|
|
||||||
|
def on_btn_Stop(self):
|
||||||
|
self.TCP.sendData(cmd.CMD_MOTORSTOP)
|
||||||
|
|
||||||
|
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>=150:
|
||||||
|
self.servo2=150
|
||||||
|
self.VSlider_Servo2.setValue(self.servo2)
|
||||||
|
self.TCP.sendData(cmd.CMD_SERVO2+str(self.servo2))
|
||||||
|
|
||||||
|
self.label_Servo2.setText("%d"%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)
|
||||||
|
self.TCP.sendData(cmd.CMD_SERVO1+str(self.servo1)+'#0')
|
||||||
|
|
||||||
|
self.label_Servo1.setText("%d"%self.servo1)
|
||||||
|
def on_btn_Down(self):
|
||||||
|
self.servo2=self.servo2-10
|
||||||
|
if self.servo2<=0:
|
||||||
|
self.servo2=0
|
||||||
|
self.VSlider_Servo2.setValue(self.servo2)
|
||||||
|
self.TCP.sendData(cmd.CMD_SERVO2+str(self.servo2))
|
||||||
|
|
||||||
|
self.label_Servo2.setText("%d"%self.servo2)
|
||||||
|
|
||||||
|
def on_btn_Home(self):
|
||||||
|
self.servo1=90
|
||||||
|
self.servo2=20
|
||||||
|
self.HSlider_Servo1.setValue(self.servo1)
|
||||||
|
self.label_Servo1.setText("%d"%self.servo1)
|
||||||
|
self.VSlider_Servo2.setValue(self.servo2)
|
||||||
|
self.label_Servo2.setText("%d"%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)
|
||||||
|
self.TCP.sendData(cmd.CMD_SERVO1+str(self.servo1)+'#0')
|
||||||
|
|
||||||
|
self.label_Servo1.setText("%d"%self.servo1)
|
||||||
|
|
||||||
|
|
||||||
|
def Change_Left_Right(self):#Left or Right
|
||||||
|
self.servo1=self.HSlider_Servo1.value()
|
||||||
|
self.TCP.sendData(cmd.CMD_SERVO1+str(self.servo1)+'#0')
|
||||||
|
self.label_Servo1.setText("%d"%self.servo1)
|
||||||
|
|
||||||
|
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_SERVO1+str(data)+'#0')
|
||||||
|
|
||||||
|
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_SERVO2+str(data))
|
||||||
|
|
||||||
|
|
||||||
|
def Change_Up_Down(self):#Up or Down
|
||||||
|
self.servo2=self.VSlider_Servo2.value()
|
||||||
|
self.TCP.sendData(cmd.CMD_SERVO2+str(self.servo2))
|
||||||
|
self.label_Servo2.setText("%d"%self.servo2)
|
||||||
|
|
||||||
|
def windowMinimumed(self):
|
||||||
|
self.showMinimized()
|
||||||
|
|
||||||
|
|
||||||
|
def on_btn_Buzzer(self):
|
||||||
|
if self.Btn_Buzzer.text()=='Buzzer':
|
||||||
|
self.TCP.sendData(cmd.CMD_BUZZER_ON)
|
||||||
|
self.Btn_Buzzer.setText('Noise')
|
||||||
|
else:
|
||||||
|
self.TCP.sendData(cmd.CMD_BUZZER_OFF)
|
||||||
|
self.Btn_Buzzer.setText('Buzzer')
|
||||||
|
|
||||||
|
def LedChange(self,b):
|
||||||
|
R=self.Color_R.text()
|
||||||
|
G=self.Color_G.text()
|
||||||
|
B=self.Color_B.text()
|
||||||
|
if b.text() == "Led1":
|
||||||
|
if b.isChecked() == True:
|
||||||
|
self.TCP.sendData(cmd.CMD_LED2_ON+str(R)+"#"+str(G)+"#"+str(B))
|
||||||
|
else:
|
||||||
|
self.TCP.sendData(cmd.CMD_LED2_OFF)
|
||||||
|
if b.text() == "Led2":
|
||||||
|
if b.isChecked() == True:
|
||||||
|
self.TCP.sendData(cmd.CMD_LED3_ON+str(R)+"#"+str(G)+"#"+str(B))
|
||||||
|
else:
|
||||||
|
self.TCP.sendData(cmd.CMD_LED3_OFF)
|
||||||
|
if b.text() == "Led3":
|
||||||
|
if b.isChecked() == True:
|
||||||
|
self.TCP.sendData(cmd.CMD_LED4_ON+str(R)+"#"+str(G)+"#"+str(B))
|
||||||
|
else:
|
||||||
|
self.TCP.sendData(cmd.CMD_LED4_OFF)
|
||||||
|
if b.text() == "Led4":
|
||||||
|
if b.isChecked() == True:
|
||||||
|
self.TCP.sendData(cmd.CMD_LED5_ON+str(R)+"#"+str(G)+"#"+str(B))
|
||||||
|
else:
|
||||||
|
self.TCP.sendData(cmd.CMD_LED5_OFF)
|
||||||
|
if b.text() == "Led5":
|
||||||
|
if b.isChecked() == True:
|
||||||
|
self.TCP.sendData(cmd.CMD_LED1_ON+str(R)+"#"+str(G)+"#"+str(B))
|
||||||
|
else:
|
||||||
|
self.TCP.sendData(cmd.CMD_LED1_OFF)
|
||||||
|
if b.text() == "Led6":
|
||||||
|
if b.isChecked() == True:
|
||||||
|
self.TCP.sendData(cmd.CMD_LED0_ON+str(R)+"#"+str(G)+"#"+str(B))
|
||||||
|
else:
|
||||||
|
self.TCP.sendData(cmd.CMD_LED0_OFF)
|
||||||
|
if b.text() == "Led7":
|
||||||
|
if b.isChecked() == True:
|
||||||
|
self.TCP.sendData(cmd.CMD_LED7_ON+str(R)+"#"+str(G)+"#"+str(B))
|
||||||
|
else:
|
||||||
|
self.TCP.sendData(cmd.CMD_LED7_OFF)
|
||||||
|
if b.text() == "Led8":
|
||||||
|
if b.isChecked() == True:
|
||||||
|
self.TCP.sendData(cmd.CMD_LED6_ON+str(R)+"#"+str(G)+"#"+str(B))
|
||||||
|
else:
|
||||||
|
self.TCP.sendData(cmd.CMD_LED6_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_MOD1)
|
||||||
|
else:
|
||||||
|
self.TCP.sendData(cmd.CMD_LED_OFF)
|
||||||
|
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_MOD2)
|
||||||
|
else:
|
||||||
|
self.TCP.sendData(cmd.CMD_LED_OFF)
|
||||||
|
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_MOD3)
|
||||||
|
else:
|
||||||
|
self.TCP.sendData(cmd.CMD_LED_OFF)
|
||||||
|
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_MOD4)
|
||||||
|
else:
|
||||||
|
self.TCP.sendData(cmd.CMD_LED_OFF)
|
||||||
|
def on_btn_Ultrasonic(self):
|
||||||
|
if self.Ultrasonic.text()=="Ultrasonic":
|
||||||
|
self.TCP.sendData(cmd.CMD_ULTRASONIC_ON)
|
||||||
|
else:
|
||||||
|
self.TCP.sendData(cmd.CMD_ULTRASONIC_OFF)
|
||||||
|
self.Ultrasonic.setText("Ultrasonic")
|
||||||
|
|
||||||
|
def on_btn_Light(self):
|
||||||
|
if self.Light.text() == "Light":
|
||||||
|
self.TCP.sendData(cmd.CMD_LIGHT_ON)
|
||||||
|
else:
|
||||||
|
self.TCP.sendData(cmd.CMD_LIGHT_OFF)
|
||||||
|
self.Light.setText("Light")
|
||||||
|
|
||||||
|
def on_btn_Mode(self,Mode):
|
||||||
|
if Mode.text() == "M-Free":
|
||||||
|
if Mode.isChecked() == True:
|
||||||
|
timer.start(34)
|
||||||
|
self.TCP.sendData(cmd.CMD_MODE[0])
|
||||||
|
|
||||||
|
if Mode.text() == "M-Light":
|
||||||
|
if Mode.isChecked() == True:
|
||||||
|
timer.stop()
|
||||||
|
self.TCP.sendData(cmd.CMD_MODE[1])
|
||||||
|
if Mode.text() == "M-Sonic":
|
||||||
|
if Mode.isChecked() == True:
|
||||||
|
timer.stop()
|
||||||
|
self.TCP.sendData(cmd.CMD_MODE[2])
|
||||||
|
|
||||||
|
if Mode.text() == "M-Line":
|
||||||
|
if Mode.isChecked() == True:
|
||||||
|
timer.stop()
|
||||||
|
self.TCP.sendData(cmd.CMD_MODE[3])
|
||||||
|
|
||||||
|
|
||||||
|
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 (self.h)
|
||||||
|
elif self.Btn_Connect.text()=="Disconnect":
|
||||||
|
self.Btn_Connect.setText( "Connect")
|
||||||
|
self.TCP.windows=0
|
||||||
|
self.receflag=0
|
||||||
|
try:
|
||||||
|
stop_thread(self.streaming)
|
||||||
|
stop_thread(self.recv)
|
||||||
|
self.TCP.sendData(cmd.CMD_POWER_OFF)
|
||||||
|
self.TCP.client_socket1.send(cmd.CMD_CLOSE)
|
||||||
|
self.TCP.StopTcpcClient()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def is_valid_jpg(self,jpg_file):
|
||||||
|
try:
|
||||||
|
|
||||||
|
if jpg_file.split('.')[-1].lower() == 'jpg':
|
||||||
|
with open(jpg_file, 'rb') as f:
|
||||||
|
f.seek(-2, 2)
|
||||||
|
buf = f.read()
|
||||||
|
f.close()
|
||||||
|
return buf.endswith(b'\xff\xd9')
|
||||||
|
else:
|
||||||
|
return false
|
||||||
|
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def is_valid_jpg1(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 IsValidImage(self,pathfile):
|
||||||
|
bValid = True
|
||||||
|
try:
|
||||||
|
Image.open(pathfile).verify()
|
||||||
|
except:
|
||||||
|
bValid = False
|
||||||
|
return bValid
|
||||||
|
def time(self):
|
||||||
|
self.TCP.video_Flag=False
|
||||||
|
if self.is_valid_jpg1('video.jpg') and self.IsValidImage('video.jpg') and self.is_valid_jpg('video.jpg'):
|
||||||
|
self.label_Video.setPixmap(QtGui.QPixmap(QtCore.QString.fromUtf8('video.jpg')))
|
||||||
|
self.TCP.video_Flag=True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
myshow=mywindow()
|
||||||
|
myshow.show();
|
||||||
|
sys.exit(app.exec_())
|
||||||
|
|
||||||
|
|
||||||
|
|
35
Code/Client/Thread.py
Normal file
35
Code/Client/Thread.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
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)
|
102
Code/Client/Video.py
Normal file
102
Code/Client/Video.py
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import numpy as np
|
||||||
|
import cv2
|
||||||
|
import socket
|
||||||
|
import io
|
||||||
|
import sys
|
||||||
|
from PIL import Image
|
||||||
|
from multiprocessing import Process
|
||||||
|
from Command import COMMAND as cmd
|
||||||
|
|
||||||
|
#socket.setdefaulttimeout(5) #new
|
||||||
|
class VideoStreaming:
|
||||||
|
def __init__(self):
|
||||||
|
self.face_cascade = cv2.CascadeClassifier(r'haarcascade_frontalface_default.xml')
|
||||||
|
self.video_Flag=True
|
||||||
|
self.connect_Flag=False #new
|
||||||
|
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)
|
||||||
|
print 'StartTcpClient'
|
||||||
|
def StopTcpcClient(self):
|
||||||
|
try:
|
||||||
|
self.connection.close()
|
||||||
|
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:
|
||||||
|
img = cv2.circle(img, (x+w/2,y+h/2), (w+h)/4, (0, 255, 0), 2)
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
cv2.imwrite('video.jpg', img)
|
||||||
|
|
||||||
|
def streaming(self,ip):
|
||||||
|
try:
|
||||||
|
stream_bytes = b' '
|
||||||
|
self.client_socket.connect((ip, 8000))
|
||||||
|
self.connection = self.client_socket.makefile('wb')
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
stream_bytes += self.connection.read(1024)
|
||||||
|
first = stream_bytes.find(b'\xff\xd8')
|
||||||
|
last = stream_bytes.find(b'\xff\xd9')
|
||||||
|
if first != -1 and last != -1 :
|
||||||
|
jpg = stream_bytes[first:last + 2]
|
||||||
|
stream_bytes = stream_bytes[last + 2:]
|
||||||
|
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
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def sendData(self,s):
|
||||||
|
if self.connect_Flag:
|
||||||
|
self.client_socket1.send(s)
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def recvData(self):
|
||||||
|
data=0
|
||||||
|
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?", e
|
||||||
|
self.connect_Flag=False
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
a=VideoStreaming()
|
||||||
|
pass
|
||||||
|
|
33314
Code/Client/haarcascade_frontalface_default.xml
Normal file
33314
Code/Client/haarcascade_frontalface_default.xml
Normal file
File diff suppressed because it is too large
Load Diff
64
Code/Server/ADC.py
Normal file
64
Code/Server/ADC.py
Normal 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)
|
||||||
|
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()
|
26
Code/Server/Buzzer.py
Normal file
26
Code/Server/Buzzer.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
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==cmd.CMD_START:
|
||||||
|
GPIO.output(Buzzer_Pin,True)
|
||||||
|
elif command==cmd.CMD_STOP:
|
||||||
|
GPIO.output(Buzzer_Pin,False)
|
||||||
|
else:
|
||||||
|
GPIO.output(Buzzer_Pin,False)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__=='__main__':
|
||||||
|
B=Buzzer()
|
||||||
|
B.run(cmd.CMD_START)
|
||||||
|
time.sleep(3)
|
||||||
|
B.run(cmd.CMD_STOP)
|
||||||
|
|
||||||
|
|
||||||
|
|
51
Code/Server/Command.py
Normal file
51
Code/Server/Command.py
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
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_START = "Start"
|
||||||
|
CMD_STOP = "Stop"
|
||||||
|
CMD_CLOSE = "CMD_CLOSE"
|
||||||
|
CMD_FORWARD = "CMD_MOTOR#1500#1500#1500#1500"
|
||||||
|
CMD_TURULEFT = "CMD_MOTOR#-1500#-1500#1500#1500"
|
||||||
|
CMD_BACKWARD = "CMD_MOTOR#-1500#-1500#-1500#-1500"
|
||||||
|
CMD_TURNRIGHT = "CMD_MOTOR#1500#1500#-1500#-1500"
|
||||||
|
CMD_MOTORSTOP = "CMD_MOTOR#0#0#0#0"
|
||||||
|
CMD_SERVO1 = "CMD_SERVO#1#0#"
|
||||||
|
CMD_SERVO2 = "CMD_SERVO#0#1#0#"
|
||||||
|
CMD_LED0_OFF = "CMD_LED#0#0#0#0"
|
||||||
|
CMD_LED0_ON = "CMD_LED#0#"
|
||||||
|
CMD_LED1_OFF = "CMD_LED#1#0#0#0"
|
||||||
|
CMD_LED1_ON = "CMD_LED#1#"
|
||||||
|
CMD_LED2_OFF = "CMD_LED#2#0#0#0"
|
||||||
|
CMD_LED2_ON = "CMD_LED#2#"
|
||||||
|
CMD_LED3_OFF = "CMD_LED#3#0#0#0"
|
||||||
|
CMD_LED3_ON = "CMD_LED#3#"
|
||||||
|
CMD_LED4_OFF = "CMD_LED#4#0#0#0"
|
||||||
|
CMD_LED4_ON = "CMD_LED#4#"
|
||||||
|
CMD_LED5_OFF = "CMD_LED#5#0#0#0"
|
||||||
|
CMD_LED5_ON = "CMD_LED#5#"
|
||||||
|
CMD_LED6_OFF = "CMD_LED#6#0#0#0"
|
||||||
|
CMD_LED6_ON = "CMD_LED#6#"
|
||||||
|
CMD_LED7_OFF = "CMD_LED#7#0#0#0"
|
||||||
|
CMD_LED7_ON = "CMD_LED#7#"
|
||||||
|
CMD_LED_MOD1 = "CMD_LED_MOD#one"
|
||||||
|
CMD_LED_MOD2 = "CMD_LED_MOD#two"
|
||||||
|
CMD_LED_MOD3 = "CMD_LED_MOD#three"
|
||||||
|
CMD_LED_MOD4 = "CMD_LED_MOD#four"
|
||||||
|
CMD_LED_OFF = "CMD_LED_MOD#0"
|
||||||
|
CMD_BUZZER_ON = "CMD_BUZZER#Start"
|
||||||
|
CMD_BUZZER_OFF = "CMD_BUZZER#Stop"
|
||||||
|
CMD_ULTRASONIC_ON = "CMD_SONIC#Start"
|
||||||
|
CMD_ULTRASONIC_OFF = "CMD_SONIC#Stop"
|
||||||
|
CMD_LIGHT_ON = "CMD_LIGHT#Start"
|
||||||
|
CMD_LIGHT_OFF = "CMD_LIGHT#Stop"
|
||||||
|
CMD_POWER_ON = "CMD_POWER#Start"
|
||||||
|
CMD_POWER_OFF = "CMD_POWER#Stop"
|
||||||
|
CMD_MODE =["CMD_MODE1","CMD_MODE2","CMD_MODE3","CMD_MODE4"]
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
42
Code/Server/Infrared_Obstacle_Avoidance.py
Normal file
42
Code/Server/Infrared_Obstacle_Avoidance.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
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 Infrared_Obstacle_Avoidance:
|
||||||
|
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:
|
||||||
|
PWM.setMotorModel(0,0,0,0)
|
||||||
|
|
||||||
|
Infrared=Infrared_Obstacle_Avoidance()
|
||||||
|
# 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)
|
124
Code/Server/Led.py
Normal file
124
Code/Server/Led.py
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
# -*-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):
|
||||||
|
# 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()
|
||||||
|
self.number='0'
|
||||||
|
def colorWipe(self,strip, color, wait_ms=50):
|
||||||
|
"""Wipe color across display a pixel at a time."""
|
||||||
|
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."""
|
||||||
|
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 < 85:
|
||||||
|
return Color(pos * 3, 255 - pos * 3, 0)
|
||||||
|
elif pos < 170:
|
||||||
|
pos -= 85
|
||||||
|
return Color(255 - pos * 3, 0, pos * 3)
|
||||||
|
else:
|
||||||
|
pos -= 170
|
||||||
|
return Color(0, pos * 3, 255 - pos * 3)
|
||||||
|
|
||||||
|
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):
|
||||||
|
self.strip.setPixelColor(index, Color(R,G,B))
|
||||||
|
self.strip.show()
|
||||||
|
def ledMode(self,n):
|
||||||
|
self.mode=n
|
||||||
|
while True:
|
||||||
|
if self.mode=='one':
|
||||||
|
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=='two':
|
||||||
|
self.theaterChaseRainbow(self.strip)
|
||||||
|
self.colorWipe(self.strip, Color(0,0,0),10)
|
||||||
|
elif self.mode=='three':
|
||||||
|
self.rainbow(self.strip)
|
||||||
|
self.colorWipe(self.strip, Color(0,0,0),10)
|
||||||
|
elif self.mode=='four':
|
||||||
|
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
37
Code/Server/Light.py
Normal 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(500,500,500,500)
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
74
Code/Server/Motor.py
Normal file
74
Code/Server/Motor.py
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
import time
|
||||||
|
from PCA9685 import PCA9685
|
||||||
|
class Motor:
|
||||||
|
def __init__(self):
|
||||||
|
self.pwm = PCA9685(0x40, debug=True)
|
||||||
|
self.pwm.setPWMFreq(50)
|
||||||
|
def left_Upper_Wheel(self,duty):
|
||||||
|
if duty>0:
|
||||||
|
self.pwm.setMotorPwm(1,0)
|
||||||
|
self.pwm.setMotorPwm(0,duty)
|
||||||
|
elif duty<0:
|
||||||
|
self.pwm.setMotorPwm(0,0)
|
||||||
|
self.pwm.setMotorPwm(1,abs(duty))
|
||||||
|
else:
|
||||||
|
self.pwm.setMotorPwm(0,4096)
|
||||||
|
self.pwm.setMotorPwm(1,4096)
|
||||||
|
def left_Lower_Wheel(self,duty):
|
||||||
|
if duty>0:
|
||||||
|
self.pwm.setMotorPwm(2,0)
|
||||||
|
self.pwm.setMotorPwm(3,duty)
|
||||||
|
elif duty<0:
|
||||||
|
self.pwm.setMotorPwm(3,0)
|
||||||
|
self.pwm.setMotorPwm(2,abs(duty))
|
||||||
|
else:
|
||||||
|
self.pwm.setMotorPwm(2,4096)
|
||||||
|
self.pwm.setMotorPwm(3,4096)
|
||||||
|
def right_Upper_Wheel(self,duty):
|
||||||
|
if duty>0:
|
||||||
|
self.pwm.setMotorPwm(7,0)
|
||||||
|
self.pwm.setMotorPwm(6,duty)
|
||||||
|
elif duty<0:
|
||||||
|
self.pwm.setMotorPwm(6,0)
|
||||||
|
self.pwm.setMotorPwm(7,abs(duty))
|
||||||
|
else:
|
||||||
|
self.pwm.setMotorPwm(6,4096)
|
||||||
|
self.pwm.setMotorPwm(7,4096)
|
||||||
|
def right_Lower_Wheel(self,duty):
|
||||||
|
if duty>0:
|
||||||
|
self.pwm.setMotorPwm(5,0)
|
||||||
|
self.pwm.setMotorPwm(4,duty)
|
||||||
|
elif duty<0:
|
||||||
|
self.pwm.setMotorPwm(4,0)
|
||||||
|
self.pwm.setMotorPwm(5,abs(duty))
|
||||||
|
else:
|
||||||
|
self.pwm.setMotorPwm(4,4096)
|
||||||
|
self.pwm.setMotorPwm(5,4096)
|
||||||
|
|
||||||
|
|
||||||
|
def setMotorModel(self,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()
|
92
Code/Server/PCA9685.py
Normal file
92
Code/Server/PCA9685.py
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
#!/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, pulse)
|
||||||
|
|
||||||
|
if __name__=='__main__':
|
||||||
|
|
||||||
|
pwm = PCA9685(0x40, debug=True)
|
||||||
|
pwm.setPWMFreq(50)
|
||||||
|
count=0;
|
||||||
|
while True:
|
||||||
|
for i in range(500,2500,10):
|
||||||
|
pwm.setServoPulse(8,i)
|
||||||
|
pwm.setServoPulse(9,i)
|
||||||
|
time.sleep(0.02)
|
||||||
|
|
||||||
|
for i in range(2500,500,-10):
|
||||||
|
pwm.setServoPulse(8,i)
|
||||||
|
pwm.setServoPulse(9,i)
|
||||||
|
time.sleep(0.02)
|
||||||
|
count=count+1
|
||||||
|
if count > 5 :
|
||||||
|
break
|
||||||
|
|
||||||
|
|
36
Code/Server/Thread.py
Normal file
36
Code/Server/Thread.py
Normal 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)
|
111
Code/Server/Ultrasonic.py
Normal file
111
Code/Server/Ultrasonic.py
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
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]
|
||||||
|
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[1])
|
||||||
|
def run_motor(self,L,M,R):
|
||||||
|
if L < 30 and M < 30 and R <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:
|
||||||
|
self.PWM.setMotorModel(-1450,-1450,-1450,-1450)
|
||||||
|
time.sleep(0.1)
|
||||||
|
PWM.setMotorModel(1500,1500,-1500,-1500)
|
||||||
|
elif R < 30 and M < 30:
|
||||||
|
self.PWM.setMotorModel(-1450,-1450,-1450,-1450)
|
||||||
|
time.sleep(0.1)
|
||||||
|
PWM.setMotorModel(-1500,-1500,1500,1500)
|
||||||
|
elif L < 30 :
|
||||||
|
PWM.setMotorModel(2000,2000,-500,-500)
|
||||||
|
if L < 20 :
|
||||||
|
PWM.setMotorModel(1500,1500,-1500,-1500)
|
||||||
|
elif R < 30 :
|
||||||
|
PWM.setMotorModel(-500,-500,2000,2000)
|
||||||
|
if L < 20 :
|
||||||
|
PWM.setMotorModel(-1500,-1500,1500,1500)
|
||||||
|
elif 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)
|
||||||
|
else :
|
||||||
|
self.PWM.setMotorModel(550,550,550,550)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
self.PWM=Motor()
|
||||||
|
self.pwm_S=Servo()
|
||||||
|
|
||||||
|
self.pwm_S.setServoPwm(1,0,30,0)
|
||||||
|
R = self.get_distance()
|
||||||
|
time.sleep(0.2)
|
||||||
|
|
||||||
|
self.pwm_S.setServoPwm(1,0,90,0)
|
||||||
|
L = self.get_distance()
|
||||||
|
time.sleep(0.2)
|
||||||
|
|
||||||
|
self.pwm_S.setServoPwm(1,0,150,0)
|
||||||
|
M = self.get_distance()
|
||||||
|
time.sleep(0.2)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
self.pwm_S.setServoPwm(1,0,30,0)
|
||||||
|
R = self.get_distance()
|
||||||
|
self.run_motor(L,M,R)
|
||||||
|
time.sleep(0.2)
|
||||||
|
|
||||||
|
self.pwm_S.setServoPwm(1,0,90,0)
|
||||||
|
L = self.get_distance()
|
||||||
|
self.run_motor(L,M,R)
|
||||||
|
time.sleep(0.2)
|
||||||
|
|
||||||
|
self.pwm_S.setServoPwm(1,0,150,0)
|
||||||
|
M = self.get_distance()
|
||||||
|
self.run_motor(L,M,R)
|
||||||
|
time.sleep(0.2)
|
||||||
|
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(1,0,90,20)
|
||||||
|
|
122
Code/Server/main.py
Normal file
122
Code/Server/main.py
Normal 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 video
|
||||||
|
|
||||||
|
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.myvideo=video()
|
||||||
|
self.SendVideo=Thread(target=self.myvideo.sendvideo)
|
||||||
|
self.ReadData=Thread(target=self.myvideo.readdata)
|
||||||
|
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.myvideo.StartTcpServer()
|
||||||
|
self.ReadData=Thread(target=self.myvideo.readdata)
|
||||||
|
self.SendVideo=Thread(target=self.myvideo.sendvideo)
|
||||||
|
self.SendVideo.start()
|
||||||
|
self.ReadData.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)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
self.myvideo.server_socket.shutdown(2)
|
||||||
|
self.myvideo.server_socket1.shutdown(2)
|
||||||
|
self.myvideo.StopTcpServer()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
print "Close Server"
|
||||||
|
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.myvideo.StartTcpServer()
|
||||||
|
self.SendVideo=Thread(target=self.myvideo.sendvideo)
|
||||||
|
self.ReadData=Thread(target=self.myvideo.readdata)
|
||||||
|
self.SendVideo.start()
|
||||||
|
self.ReadData.start()
|
||||||
|
print "Open TCP"
|
||||||
|
elif self.label.text()=='Server On':
|
||||||
|
self.label.setText("Server Off")
|
||||||
|
self.Button_Server.setText("On")
|
||||||
|
try:
|
||||||
|
time.sleep(0.1)
|
||||||
|
stop_thread(self.SendVideo)
|
||||||
|
stop_thread(self.ReadData)
|
||||||
|
except:
|
||||||
|
print 'stop_thread error'
|
||||||
|
|
||||||
|
self.myvideo.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()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
307
Code/Server/server.py
Normal file
307
Code/Server/server.py
Normal file
@ -0,0 +1,307 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import io
|
||||||
|
import socket
|
||||||
|
import struct
|
||||||
|
import time
|
||||||
|
import picamera
|
||||||
|
import gzip
|
||||||
|
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 Infrared_Obstacle_Avoidance import *
|
||||||
|
from threading import Timer
|
||||||
|
from threading import Thread
|
||||||
|
from Command import COMMAND as cmd
|
||||||
|
|
||||||
|
|
||||||
|
class video:
|
||||||
|
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=Infrared_Obstacle_Avoidance()
|
||||||
|
self.Mode = 'one'
|
||||||
|
self.sonic=False
|
||||||
|
self.Light=False
|
||||||
|
self.Power=False
|
||||||
|
|
||||||
|
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 "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 SocketAccept(self):
|
||||||
|
self.connection1,self.client_address1 = self.server_socket1.accept()
|
||||||
|
self.connection,self.client_address = self.server_socket.accept()
|
||||||
|
self.connection=self.connection.makefile('rb')
|
||||||
|
def sendvideo(self):
|
||||||
|
try:
|
||||||
|
self.connection,self.client_address = self.server_socket.accept()
|
||||||
|
self.connection=self.connection.makefile('rb')
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
with picamera.PiCamera() as camera:
|
||||||
|
|
||||||
|
camera.resolution = (400,300) # pi camera resolution
|
||||||
|
|
||||||
|
camera.framerate = 15 # 15 frames/sec
|
||||||
|
|
||||||
|
time.sleep(2) # give 2 secs for camera to initilize
|
||||||
|
|
||||||
|
start = time.time()
|
||||||
|
|
||||||
|
stream = io.BytesIO()
|
||||||
|
|
||||||
|
# send jpeg format video stream
|
||||||
|
|
||||||
|
for foo in camera.capture_continuous(stream, 'jpeg', use_video_port = True):
|
||||||
|
try:
|
||||||
|
self.connection.write(struct.pack('<L', stream.tell()))
|
||||||
|
|
||||||
|
self.connection.flush()
|
||||||
|
|
||||||
|
stream.seek(0)
|
||||||
|
|
||||||
|
self.connection.write(stream.read())
|
||||||
|
if time.time() - start > 600:
|
||||||
|
|
||||||
|
break
|
||||||
|
|
||||||
|
stream.seek(0)
|
||||||
|
|
||||||
|
stream.truncate()
|
||||||
|
except:
|
||||||
|
break
|
||||||
|
self.connection.write(struct.pack('<L', 0))
|
||||||
|
except:
|
||||||
|
print "send video error"
|
||||||
|
|
||||||
|
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)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def readdata(self):
|
||||||
|
self.connection1,self.client_address1 = self.server_socket1.accept()
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
AllData=self.connection1.recv(1024)
|
||||||
|
if AllData==None:
|
||||||
|
pass
|
||||||
|
elif AllData=='':
|
||||||
|
self.Reset()
|
||||||
|
break
|
||||||
|
elif AllData==cmd.CMD_CLOSE :
|
||||||
|
self.Reset()
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
data=AllData.split("#")
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
if data==None:
|
||||||
|
continue
|
||||||
|
elif (cmd.CMD_MODE[0] in data) or (cmd.CMD_MODE[1] in data) or (cmd.CMD_MODE[2] in data) or (cmd.CMD_MODE[3] in data):
|
||||||
|
if cmd.CMD_MODE[0] in data:
|
||||||
|
self.stopMode()
|
||||||
|
self.Mode='one'
|
||||||
|
elif cmd.CMD_MODE[1] in data:
|
||||||
|
self.stopMode()
|
||||||
|
self.Mode='two'
|
||||||
|
self.lightRun=Thread(target=self.light.run)
|
||||||
|
self.lightRun.start()
|
||||||
|
elif cmd.CMD_MODE[2] in data:
|
||||||
|
self.stopMode()
|
||||||
|
self.Mode='three'
|
||||||
|
self.ultrasonicRun=threading.Thread(target=self.ultrasonic.run)
|
||||||
|
self.ultrasonicRun.start()
|
||||||
|
|
||||||
|
elif cmd.CMD_MODE[3] in data:
|
||||||
|
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)
|
||||||
|
self.connection1.send(data[0]+'#'+data[1])
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
elif cmd.CMD_SERVO 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.servo.setServoPwm(data1,data2,data3,data4)
|
||||||
|
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:
|
||||||
|
try:
|
||||||
|
self.LedMoD=data[1]
|
||||||
|
if self.LedMoD== '0':
|
||||||
|
stop_thread(Led_Mode)
|
||||||
|
self.led.ledMode(self.LedMoD)
|
||||||
|
time.sleep(0.1)
|
||||||
|
self.led.ledMode(self.LedMoD)
|
||||||
|
else :
|
||||||
|
Led_Mode=Thread(target=self.led.ledMode,args=(data[1],))
|
||||||
|
Led_Mode.start()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
elif cmd.CMD_SONIC in data:
|
||||||
|
if data[1]==cmd.CMD_START:
|
||||||
|
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]==cmd.CMD_START:
|
||||||
|
self.Light=True
|
||||||
|
self.lightTimer = threading.Timer(0.3,self.sendLight)
|
||||||
|
self.lightTimer.start()
|
||||||
|
else:
|
||||||
|
self.Light=False
|
||||||
|
elif cmd.CMD_POWER in data:
|
||||||
|
if data[1]==cmd.CMD_START:
|
||||||
|
self.Power=True
|
||||||
|
self.powerTimer = threading.Timer(0.7,self.sendPower)
|
||||||
|
self.powerTimer.start()
|
||||||
|
else:
|
||||||
|
self.Power=False
|
||||||
|
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))
|
||||||
|
except:
|
||||||
|
self.sonic=False
|
||||||
|
self.ultrasonicTimer = threading.Timer(0.13,self.sendUltrasonic)
|
||||||
|
self.ultrasonicTimer.start()
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
def sendLight(self):
|
||||||
|
if self.Light==True:
|
||||||
|
ADC_Light1=self.adc.recvADC(0)
|
||||||
|
ADC_Light2=self.adc.recvADC(1)
|
||||||
|
if ADC_Light1==self.adc.recvADC(0) and ADC_Light2==self.adc.recvADC(1):
|
||||||
|
try:
|
||||||
|
self.connection1.send(cmd.CMD_LIGHT+'#'+str(ADC_Light1)+'#'+str(ADC_Light2))
|
||||||
|
except:
|
||||||
|
self.Light=False
|
||||||
|
self.lightTimer = threading.Timer(0.11,self.sendLight)
|
||||||
|
self.lightTimer.start()
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
def sendPower(self):
|
||||||
|
if self.Power==True:
|
||||||
|
ADC_Power=self.adc.recvADC(2)
|
||||||
|
if ADC_Power==self.adc.recvADC(2):
|
||||||
|
try:
|
||||||
|
self.connection1.send(cmd.CMD_POWER+'#'+str(ADC_Power))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
self.Power==False
|
||||||
|
self.powerTimer = threading.Timer(10,self.sendPower)
|
||||||
|
self.powerTimer.start()
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
if __name__=='__main__':
|
||||||
|
ultrasonic=Ultrasonic()
|
||||||
|
Light=Light()
|
||||||
|
Light_run=Thread(target=Light.run)
|
||||||
|
Light_run.start()
|
||||||
|
time.sleep(10)
|
||||||
|
stop_thread(Light_run)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
127
Code/Server/server_ui.py
Normal file
127
Code/Server/server_ui.py
Normal 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))
|
||||||
|
|
42
Code/Server/servo.py
Normal file
42
Code/Server/servo.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
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,850)
|
||||||
|
def setServoPwm(self,channel1,channel2,angle1,angle2,error=10):
|
||||||
|
if channel1==1:
|
||||||
|
self.PwmServo.setServoPulse(8,2500-int((angle1+error)/0.09))
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
if channel2==1:
|
||||||
|
self.PwmServo.setServoPulse(9,500+int((angle2+error)/0.09))
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
pwm=Servo()
|
||||||
|
def loop():
|
||||||
|
for i in range(180):
|
||||||
|
pwm.setServoPwm(1,0,i,0)
|
||||||
|
time.sleep(0.01)
|
||||||
|
for i in range(180,0,-1):
|
||||||
|
pwm.setServoPwm(1,0,i,0)
|
||||||
|
time.sleep(0.01)
|
||||||
|
|
||||||
|
def destroy():
|
||||||
|
pwm.setServoPwm(1,1,90,20)
|
||||||
|
|
||||||
|
# Main program logic follows:
|
||||||
|
if __name__ == '__main__':
|
||||||
|
pwm.setServoPwm(1,1,90,20)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
173
Code/Server/test.py
Normal file
173
Code/Server/test.py
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
import time
|
||||||
|
try:
|
||||||
|
from Led import *
|
||||||
|
led=Led()
|
||||||
|
def test_Led():
|
||||||
|
try:
|
||||||
|
led.ledIndex(0,255,0,0) #Red
|
||||||
|
led.ledIndex(1,255,125,0) #orange
|
||||||
|
led.ledIndex(2,255,255,0) #yellow
|
||||||
|
led.ledIndex(3,0,255,0) #green
|
||||||
|
led.ledIndex(4,0,255,255) #cyan-blue
|
||||||
|
led.ledIndex(5,0,0,255) #blue
|
||||||
|
led.ledIndex(6,128,0,128) #purple
|
||||||
|
led.ledIndex(7,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 10s
|
||||||
|
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"
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
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 Infrared_Obstacle_Avoidance 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(1,0,i,0)
|
||||||
|
time.sleep(0.01)
|
||||||
|
for i in range(110,50,-1):
|
||||||
|
pwm.setServoPwm(1,0,i,0)
|
||||||
|
time.sleep(0.01)
|
||||||
|
for i in range(20,80,1):
|
||||||
|
pwm.setServoPwm(0,1,0,i)
|
||||||
|
time.sleep(0.01)
|
||||||
|
for i in range(80,20,-1):
|
||||||
|
pwm.setServoPwm(0,1,0,i)
|
||||||
|
time.sleep(0.01)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pwm.setServoPwm(1,1,90,20)
|
||||||
|
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(cmd.CMD_START)
|
||||||
|
time.sleep(1)
|
||||||
|
print "1S"
|
||||||
|
time.sleep(1)
|
||||||
|
print "2S"
|
||||||
|
time.sleep(1)
|
||||||
|
print "3S"
|
||||||
|
buzzer.run(cmd.CMD_STOP)
|
||||||
|
print "\nEnd of program"
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
buzzer.run(cmd.CMD_STOP)
|
||||||
|
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
Datasheet/PCA9685.pdf
Normal file
BIN
Datasheet/PCA9685.pdf
Normal file
Binary file not shown.
BIN
Datasheet/PCF8591.pdf
Normal file
BIN
Datasheet/PCF8591.pdf
Normal file
Binary file not shown.
BIN
InstallationPackage/rpi_ws281x.zip
Normal file
BIN
InstallationPackage/rpi_ws281x.zip
Normal file
Binary file not shown.
BIN
Picture/icon.png
Normal file
BIN
Picture/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 315 KiB |
57
README.md
Normal file
57
README.md
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
# Freenove Four Wheeled Smart Car Kit for Raspberry Pi
|
||||||
|
|
||||||
|
**Freenove_Four_wheeled_Smart_Car_Kit_for_Raspberry_Pi**
|
||||||
|
|
||||||
|
<img src='Picture/icon.png' width='30%'/>
|
||||||
|
|
||||||
|
## How to download
|
||||||
|
|
||||||
|
Please click the green "Clone or download" button, then click "Download ZIP" button in the pop-up window to download the zip file that contains all these files. Clicking the "Open in Desktop" button will lead you to install Github software instead of downloading these files.
|
||||||
|
<br>If you have any difficulties, please send email to our support for help.
|
||||||
|
|
||||||
|
## Files
|
||||||
|
### The files for this product and their introduction are as follows
|
||||||
|
Name | Description
|
||||||
|
-- | --
|
||||||
|
Code | Project code
|
||||||
|
Datasheet | Datasheet
|
||||||
|
Readme.md | Instructions
|
||||||
|
Tutorial.pdf | User Manual
|
||||||
|
Picture | Picture resource
|
||||||
|
InstallationPackage | Installation packages required for the project
|
||||||
|
|
||||||
|
|
||||||
|
## Support
|
||||||
|
* Freenove provides free and quick technical support, including but not limited to:
|
||||||
|
* Quality problems of products
|
||||||
|
* Problems in using products
|
||||||
|
* Questions for learning and technology
|
||||||
|
* Opinions and suggestions
|
||||||
|
* Ideas and thoughts
|
||||||
|
|
||||||
|
* Please send email to:
|
||||||
|
* support@freenove.com
|
||||||
|
<br>On working day, we usually reply to you within 24 hours.
|
||||||
|
|
||||||
|
## Copyright
|
||||||
|
<br>Freenove reserves all rights to the files for this product. No copies or plagiarizations are allowed for the purpose of commercial use.
|
||||||
|
<br>The code and circuit involved in this product are released as Creative Commons Attribution ShareAlike 3.0 (http://creativecommons.org/licenses/by-sa/3.0/legalcode). This means you can use them on your own derived works, in part or completely, as long as you also adopt the same license.
|
||||||
|
<br>Freenove brand and Freenove logo are copyright of Freenove Creative Technology Co., Ltd and cannot be used without formal permission.
|
||||||
|
|
||||||
|
## About
|
||||||
|
* Freenove is an open-source electronics platform. Freenove is committed to helping customer quickly realize the creative idea and product prototypes, making it easy to get started for enthusiasts of programing and electronics and launching innovative open source products. Our services include:
|
||||||
|
* Electronic components and modules
|
||||||
|
* Learning kits for Arduino
|
||||||
|
* Learning kits for Raspberry Pi
|
||||||
|
* Learning kits for micro:bit
|
||||||
|
* Learning kits for Technology
|
||||||
|
* Robot kits
|
||||||
|
* Auxiliary tools for creations
|
||||||
|
|
||||||
|
* Our code and circuit are open source. You can obtain the details and the latest information through visiting the following web sites:
|
||||||
|
* http://www.freenove.com
|
||||||
|
* https://github.com/freenove
|
||||||
|
|
||||||
|
* Your comments and suggestions are warmly welcomed, please send them to the following email address:
|
||||||
|
* support@freenove.com
|
||||||
|
|
Loading…
Reference in New Issue
Block a user