|
@@ -1,82 +1,90 @@
|
|
|
+import datetime
|
|
|
import math
|
|
|
import random
|
|
|
+import time
|
|
|
+from concurrent.futures import ThreadPoolExecutor, as_completed, wait
|
|
|
+from PyQt5.QtWidgets import QWidget, QFrame, QLabel, QLineEdit, QPushButton, QComboBox, QCheckBox
|
|
|
+from PyQt5.QtGui import QPixmap, QPainter, QResizeEvent, QCloseEvent, QPaintEvent, QFont
|
|
|
+from PyQt5.QtCore import QSize, QTimer, Qt
|
|
|
|
|
|
-from PyQt5.QtWidgets import QWidget,QFrame,QLabel,QLineEdit,QPushButton,QComboBox,QCheckBox
|
|
|
-from PyQt5.QtGui import QPixmap,QPainter,QResizeEvent,QCloseEvent,QPaintEvent,QFont
|
|
|
-from PyQt5.QtCore import QSize,QTimer,Qt
|
|
|
+import auto_test
|
|
|
from RobotData import Robot
|
|
|
import dijkstra.Map as mp
|
|
|
-import threadPool
|
|
|
-from RobotTask import SingleNavTask,SingleClampCloseTask,\
|
|
|
- SingleClampOpenTask,LoadedNavTask,CancelTask
|
|
|
+from RobotTask import SingleNavTask, SingleClampCloseTask, \
|
|
|
+ SingleClampOpenTask, LoadedNavTask, CancelTask
|
|
|
+
|
|
|
+
|
|
|
class ControlFrame(QFrame):
|
|
|
- last_beg="**"
|
|
|
- begId_="------"
|
|
|
- targetId_="------"
|
|
|
- def __init__(self,config):
|
|
|
+ threadPool_ = ThreadPoolExecutor(2)
|
|
|
+ last_beg = "**"
|
|
|
+ begId_ = "------"
|
|
|
+ targetId_ = "------"
|
|
|
+
|
|
|
+ def __init__(self, config):
|
|
|
QFrame.__init__(self)
|
|
|
|
|
|
- self.street_nodes_=config['street_nodes']
|
|
|
- self.space_nodes_=config['space_nodes']
|
|
|
- self.label_=config['label']
|
|
|
- [id,ip,port,user,pawd]=config['mqtt']
|
|
|
- subtopics=config['subTopics']
|
|
|
- cmdTopic=config['cmdTopic']
|
|
|
- robotColor=config['robotColor']
|
|
|
+ self.street_nodes_ = config['street_nodes']
|
|
|
+ self.space_nodes_ = config['space_nodes']
|
|
|
+ self.label_ = config['label']
|
|
|
+ [id, ip, port, user, pawd] = config['mqtt']
|
|
|
+ subtopics = config['subTopics']
|
|
|
+ cmdTopic = config['cmdTopic']
|
|
|
+ robotColor = config['robotColor']
|
|
|
|
|
|
- self.all_nodes_=[]
|
|
|
+ self.all_nodes_ = []
|
|
|
for node in self.street_nodes_:
|
|
|
self.all_nodes_.append(node)
|
|
|
for node in self.space_nodes_:
|
|
|
self.all_nodes_.append(node)
|
|
|
|
|
|
- self.robot_=Robot(self.label_)
|
|
|
- self.robot_.connect(id,ip,port,user,pawd)
|
|
|
- self.robot_.SetSubDataTopic(subtopics,self.messageArrived)
|
|
|
+ self.robot_ = Robot(self.label_)
|
|
|
+ self.robot_.connect(id, ip, port, user, pawd)
|
|
|
+ self.robot_.SetSubDataTopic(subtopics, self.messageArrived)
|
|
|
self.robot_.SetCmdTopic(cmdTopic)
|
|
|
self.robot_.loop_start()
|
|
|
- self.robot_.SetColor(robotColor,robotColor)
|
|
|
+ self.robot_.SetColor(robotColor, robotColor)
|
|
|
|
|
|
- self.setGeometry(0,0,500,500)
|
|
|
+ self.setGeometry(0, 0, 500, 500)
|
|
|
self.InitUI()
|
|
|
self.setFrameShape(self.StyledPanel)
|
|
|
- self.timer_=QTimer()
|
|
|
+ self.timer_ = QTimer()
|
|
|
self.timer_.timeout.connect(self.Update)
|
|
|
self.timer_.start(100)
|
|
|
|
|
|
def messageArrived(self):
|
|
|
pass
|
|
|
- #self.gl.update()
|
|
|
+ # self.gl.update()
|
|
|
+
|
|
|
def InitUI(self):
|
|
|
|
|
|
- self.basestatic=QLabel(self)
|
|
|
+ self.basestatic = QLabel(self)
|
|
|
self.basestatic.setText(self.label_)
|
|
|
self.basestatic.setGeometry(20, 20, 80, 30)
|
|
|
|
|
|
- self.begstatic=QLabel(self)
|
|
|
+ self.begstatic = QLabel(self)
|
|
|
self.begstatic.setText(" 起点")
|
|
|
self.begstatic.setGeometry(90, 5, 80, 30)
|
|
|
- self.begQc=QComboBox(self)
|
|
|
+ self.begQc = QComboBox(self)
|
|
|
self.begQc.setGeometry(160, 5, 80, 30)
|
|
|
|
|
|
- self.endstatic=QLabel(self)
|
|
|
+ self.endstatic = QLabel(self)
|
|
|
self.endstatic.setText("去马路点")
|
|
|
self.endstatic.setGeometry(90, 50, 80, 30)
|
|
|
- self.endStreetQc=QComboBox(self)
|
|
|
+ self.endStreetQc = QComboBox(self)
|
|
|
self.endStreetQc.setGeometry(160, 50, 80, 30)
|
|
|
|
|
|
- self.endstatic=QLabel(self)
|
|
|
+ self.endstatic = QLabel(self)
|
|
|
self.endstatic.setText("去车位点")
|
|
|
self.endstatic.setGeometry(90, 95, 80, 30)
|
|
|
- self.endSpaceQc=QComboBox(self)
|
|
|
+ self.endSpaceQc = QComboBox(self)
|
|
|
self.endSpaceQc.setGeometry(160, 95, 80, 30)
|
|
|
|
|
|
- self.btnSend=QPushButton(self)
|
|
|
+ self.btnSend = QPushButton(self)
|
|
|
self.btnSend.setGeometry(150, 140, 100, 40)
|
|
|
self.btnSend.setText(" 启动导航")
|
|
|
self.btnSend.clicked.connect(self.btnSendClick)
|
|
|
|
|
|
- self.btnCancel=QPushButton(self)
|
|
|
+ self.btnCancel = QPushButton(self)
|
|
|
self.btnCancel.setGeometry(150, 190, 100, 40)
|
|
|
self.btnCancel.setText(" 取消导航")
|
|
|
self.btnCancel.clicked.connect(self.btnCancelClick)
|
|
@@ -89,73 +97,101 @@ class ControlFrame(QFrame):
|
|
|
self.endStreetQc.activated.connect(self.endStreetQCChanged)
|
|
|
self.endSpaceQc.activated.connect(self.endSpaceQCChanged)
|
|
|
|
|
|
- self.posestatic=QLabel(self)
|
|
|
+ self.posestatic = QLabel(self)
|
|
|
self.posestatic.setGeometry(260, 5, 100, 90)
|
|
|
|
|
|
- self.LedLabel=QLabel(self)
|
|
|
+ self.LedLabel = QLabel(self)
|
|
|
self.LedLabel.setGeometry(80, 160, 50, 50)
|
|
|
|
|
|
- #发送轴距
|
|
|
- self.wheelbasestatic=QLabel(self)
|
|
|
+ # 发送轴距
|
|
|
+ self.wheelbasestatic = QLabel(self)
|
|
|
self.wheelbasestatic.setText("轴距:")
|
|
|
self.wheelbasestatic.setGeometry(260, 90, 40, 30)
|
|
|
- self.WheelBaseEdit=QLineEdit(self)
|
|
|
+ self.WheelBaseEdit = QLineEdit(self)
|
|
|
self.WheelBaseEdit.setText("3.3")
|
|
|
self.WheelBaseEdit.setGeometry(300, 90, 50, 30)
|
|
|
|
|
|
- self.btnModelCheck=QCheckBox("双车模式",self)
|
|
|
- self.btnModelCheck.setGeometry(260, 140, 100, 40)
|
|
|
- self.btnModelCheck.stateChanged.connect(self.MainAgvchangecb)
|
|
|
+ self.btnModelCheck = QCheckBox("双车模式", self)
|
|
|
+ self.btnModelCheck.setGeometry(260, 130, 100, 40)
|
|
|
+ self.btnModelCheck.clicked.connect(self.MainAgvchangecb)
|
|
|
|
|
|
- self.btnClampCheck=QCheckBox("夹持",self)
|
|
|
- self.btnClampCheck.setGeometry(360, 140, 60, 40)
|
|
|
- self.btnClampCheck.stateChanged.connect(self.ClampClick)
|
|
|
+ self.btnClampCheck = QCheckBox("夹持", self)
|
|
|
+ self.btnClampCheck.setGeometry(260, 160, 60, 40)
|
|
|
+ self.btnClampCheck.clicked.connect(self.ClampClick)
|
|
|
|
|
|
- self.btnAuto=QCheckBox(self)
|
|
|
+ self.btnAuto = QCheckBox(self)
|
|
|
self.btnAuto.setText("自动测试")
|
|
|
- self.btnAuto.setGeometry(260, 190, 100, 40)
|
|
|
+ self.btnAuto.setGeometry(260, 195, 100, 40)
|
|
|
+ self.btnAuto.stateChanged.connect(self.AutoCheck)
|
|
|
|
|
|
def Update(self):
|
|
|
|
|
|
- if self.robot_.timedPose_.timeout()==False:
|
|
|
- x=self.robot_.timedPose_.statu.x
|
|
|
- y=self.robot_.timedPose_.statu.y
|
|
|
- yaw=self.robot_.timedPose_.statu.theta
|
|
|
- self.posestatic.setText("x : %.3f\ny : %.3f\nΘ : %.2f°"%(x,y,yaw*180/math.pi))
|
|
|
+ if self.robot_.timedRobotStatu_.timeout() == False:
|
|
|
+ x = self.robot_.timedRobotStatu_.statu.x
|
|
|
+ y = self.robot_.timedRobotStatu_.statu.y
|
|
|
+ yaw = self.robot_.timedRobotStatu_.statu.theta
|
|
|
+ self.posestatic.setText("x : %.3f\ny : %.3f\nΘ : %.2f°" % (x, y, yaw * 180 / math.pi))
|
|
|
|
|
|
- djks_map=mp.DijikstraMap()
|
|
|
- [label,pt]=djks_map.findNeastNode([x,y])
|
|
|
- if self.all_nodes_.index(label)>=0:
|
|
|
- if not label==self.last_beg:
|
|
|
+ djks_map = mp.DijikstraMap()
|
|
|
+ [label, pt] = djks_map.findNeastNode([x, y])
|
|
|
+ if self.all_nodes_.index(label) >= 0:
|
|
|
+ if not label == self.last_beg:
|
|
|
self.begQc.setCurrentText(label)
|
|
|
- self.last_beg=label
|
|
|
- print(" change beg ",self.last_beg)
|
|
|
+ self.last_beg = label
|
|
|
+ print(" change beg ", self.last_beg)
|
|
|
|
|
|
- statu="min-width: 32px; min-height: 32px;max-width:32px;\
|
|
|
+ statu = "min-width: 32px; min-height: 32px;max-width:32px;\
|
|
|
max-height: 32px;border-radius: 16px; border:1px solid black;background:green"
|
|
|
- if self.robot_.Connected()==False:
|
|
|
- statu="min-width: 32px; min-height: 32px;max-width:32px;\
|
|
|
+ if self.robot_.Connected() == False:
|
|
|
+ statu = "min-width: 32px; min-height: 32px;max-width:32px;\
|
|
|
max-height: 32px;border-radius: 16px; border:1px solid black;background:gray"
|
|
|
- #self.endQc.setEnabled(False)
|
|
|
- elif self.robot_.IsNavigating()==True:
|
|
|
- statu="min-width: 32px; min-height: 32px;max-width:32px;\
|
|
|
+ # self.endQc.setEnabled(False)
|
|
|
+ elif self.robot_.IsNavigating() == True:
|
|
|
+ statu = "min-width: 32px; min-height: 32px;max-width:32px;\
|
|
|
max-height: 32px;border-radius: 16px; border:1px solid black;background:yellow"
|
|
|
self.endStreetQc.setEnabled(False)
|
|
|
self.endSpaceQc.setEnabled(False)
|
|
|
self.btnModelCheck.setEnabled(False)
|
|
|
+ self.btnClampCheck.setEnabled(False)
|
|
|
else:
|
|
|
self.endStreetQc.setEnabled(True)
|
|
|
self.endSpaceQc.setEnabled(True)
|
|
|
self.btnModelCheck.setEnabled(True)
|
|
|
+ self.btnClampCheck.setEnabled(True)
|
|
|
self.LedLabel.setStyleSheet(statu)
|
|
|
|
|
|
-
|
|
|
self.wheelbasestatic.setVisible(self.robot_.IsMainAgv())
|
|
|
self.WheelBaseEdit.setVisible(self.robot_.IsMainAgv())
|
|
|
self.btnModelCheck.setVisible(self.robot_.IsMainAgv())
|
|
|
+ if self.robot_.IsMainModeStatu():
|
|
|
+ self.btnModelCheck.setCheckState(Qt.Checked)
|
|
|
+ else:
|
|
|
+ self.btnModelCheck.setCheckState(Qt.Unchecked)
|
|
|
|
|
|
- '''if self.btnAuto.checkState()==Qt.Checked:
|
|
|
- if self.robot_.IsNavigating()==False and self.robot_.Connected():
|
|
|
+ if self.robot_.IsClampClosed():
|
|
|
+ self.btnClampCheck.setCheckState(Qt.Checked)
|
|
|
+ else:
|
|
|
+ self.btnClampCheck.setCheckState(Qt.Unchecked)
|
|
|
+
|
|
|
+ if self.robot_.IsNavigating():
|
|
|
+ self.begId_ = self.robot_.begId_
|
|
|
+ self.targetId_ = self.robot_.targetId_
|
|
|
+ djks_map = mp.DijikstraMap()
|
|
|
+ beg_node = djks_map.GetVertex(self.begId_)
|
|
|
+ end_node = djks_map.GetVertex(self.targetId_)
|
|
|
+ if beg_node is not None:
|
|
|
+ self.begQc.setCurrentText(self.begId_)
|
|
|
+ if end_node is not None:
|
|
|
+ if isinstance(end_node, (mp.SpaceNode)):
|
|
|
+ self.endStreetQc.setCurrentText("------")
|
|
|
+ self.endSpaceQc.setCurrentText(self.targetId_)
|
|
|
+ if isinstance(end_node, (mp.StreetNode)):
|
|
|
+ self.endStreetQc.setCurrentText(self.targetId_)
|
|
|
+ self.endSpaceQc.setCurrentText("------")
|
|
|
+
|
|
|
+ if self.btnAuto.checkState() == Qt.Checked:
|
|
|
+ pass
|
|
|
+ '''if self.robot_.IsNavigating()==False and self.robot_.Connected():
|
|
|
beg=self.begQc.currentText()
|
|
|
djks_map=mp.DijikstraMap()
|
|
|
node=djks_map.GetVertex(beg)
|
|
@@ -163,60 +199,57 @@ class ControlFrame(QFrame):
|
|
|
if node is not None:
|
|
|
if isinstance(node,(mp.SpaceNode)):
|
|
|
end="O"
|
|
|
- self.endStreetQc.setCurrentText(end)
|
|
|
- self.endSpaceQc.setCurrentText("------")
|
|
|
if isinstance(node,(mp.StreetNode)):
|
|
|
end_nodes=["E","B","C","D"]
|
|
|
id=random.randint(0,1000)%4
|
|
|
- end=end_nodes[id]
|
|
|
- self.endSpaceQc.setCurrentText(end)
|
|
|
- self.endStreetQc.setCurrentText("------")
|
|
|
+ end=end_nodes[id]'''
|
|
|
|
|
|
- self.robot_.GeneratePath(beg,end)
|
|
|
- self.btnSendClick()'''
|
|
|
|
|
|
+ def AutoCheck(self):
|
|
|
+ if self.btnAuto.checkState()==Qt.Checked:
|
|
|
+ self.robot_.autoTest_=True
|
|
|
+ else:
|
|
|
+ self.robot_.autoTest_=False
|
|
|
def ClampClick(self):
|
|
|
- if self.btnClampCheck.checkState() == Qt.Checked:
|
|
|
- task=SingleClampCloseTask(self.robot_)
|
|
|
- threadPool.ThreadPool().InputTask(task)
|
|
|
- if self.btnClampCheck.checkState() == Qt.Unchecked:
|
|
|
- task=SingleClampOpenTask(self.robot_)
|
|
|
- threadPool.ThreadPool().InputTask(task)
|
|
|
+ if self.robot_.IsClampClosed() == False:
|
|
|
+ self.threadPool_.submit(self.robot_.ClampClose)
|
|
|
+ else:
|
|
|
+ self.threadPool_.submit(self.robot_.ClampOpen)
|
|
|
+
|
|
|
def MainAgvchangecb(self):
|
|
|
- if self.btnModelCheck.checkState() == Qt.Checked:
|
|
|
- leng=float(self.WheelBaseEdit.text())
|
|
|
- self.robot_.SwitchMoveMode(2,leng)
|
|
|
- if self.btnModelCheck.checkState() == Qt.Unchecked:
|
|
|
- self.robot_.SwitchMoveMode(1,0)
|
|
|
+ if self.robot_.IsMainModeStatu() == False:
|
|
|
+ leng = float(self.WheelBaseEdit.text())
|
|
|
+ self.threadPool_.submit(self.robot_.SwitchMoveMode, 2, leng)
|
|
|
+ else:
|
|
|
+ self.threadPool_.submit(self.robot_.SwitchMoveMode, 1, 0)
|
|
|
+
|
|
|
def endStreetQCChanged(self):
|
|
|
- id1=self.begQc.currentText()
|
|
|
- id2=self.endStreetQc.currentText()
|
|
|
- if not id1=="------" and not id2=="------":
|
|
|
- self.robot_.GeneratePath(id1,id2)
|
|
|
+ id1 = self.begQc.currentText()
|
|
|
+ id2 = self.endStreetQc.currentText()
|
|
|
+ if not id1 == "------" and not id2 == "------":
|
|
|
+ self.robot_.GeneratePath(id1, id2)
|
|
|
self.begId_=id1
|
|
|
self.targetId_=id2
|
|
|
- self.endSpaceQc.setCurrentText("------")
|
|
|
+
|
|
|
def endSpaceQCChanged(self):
|
|
|
- id1=self.begQc.currentText()
|
|
|
- id2=self.endSpaceQc.currentText()
|
|
|
- if not id1=="------" and not id2=="------":
|
|
|
- self.robot_.GeneratePath(id1,id2)
|
|
|
+ id1 = self.begQc.currentText()
|
|
|
+ id2 = self.endSpaceQc.currentText()
|
|
|
+ if not id1 == "------" and not id2 == "------":
|
|
|
+ self.robot_.GeneratePath(id1, id2)
|
|
|
self.begId_=id1
|
|
|
self.targetId_=id2
|
|
|
- self.endStreetQc.setCurrentText("------")
|
|
|
+
|
|
|
def btnSendClick(self):
|
|
|
- wheelbase=float(self.WheelBaseEdit.text())
|
|
|
- task=None
|
|
|
- if self.btnModelCheck.checkState()==Qt.Unchecked:
|
|
|
- task=SingleNavTask(self.robot_,self.begId_,self.targetId_)
|
|
|
- else:
|
|
|
- task=LoadedNavTask(self.robot_,self.begId_,self.targetId_,wheelbase)
|
|
|
- threadPool.ThreadPool().InputTask(task)
|
|
|
+ if self.btnAuto.checkState()==Qt.Checked:
|
|
|
+ self.threadPool_.submit(self.robot_.AutoTestNavClamp,
|
|
|
+ self.begId_, self.targetId_)
|
|
|
+ else :
|
|
|
+ self.threadPool_.submit(self.robot_.TestNavClampOnce,
|
|
|
+ self.begId_, self.targetId_)
|
|
|
|
|
|
def btnCancelClick(self):
|
|
|
+ self.threadPool_.submit(self.robot_.CancelNavTask)
|
|
|
self.btnAuto.setCheckState(Qt.Unchecked)
|
|
|
- task=CancelTask(self.robot_)
|
|
|
- threadPool.ThreadPool().InputTask(task)
|
|
|
|
|
|
|
|
|
class CountFrame(QFrame):
|
|
@@ -225,30 +258,21 @@ class CountFrame(QFrame):
|
|
|
|
|
|
self.InitUI()
|
|
|
|
|
|
- self.timer_=QTimer()
|
|
|
+ self.timer_ = QTimer()
|
|
|
self.timer_.timeout.connect(self.UpdateUI)
|
|
|
self.timer_.start(200)
|
|
|
|
|
|
def InitUI(self):
|
|
|
- self.static1=QLabel(self)
|
|
|
+ self.static1 = QLabel(self)
|
|
|
self.static1.setText("重载导航次数 : /")
|
|
|
self.static1.setGeometry(5, 5, 200, 30)
|
|
|
|
|
|
- self.static2=QLabel(self)
|
|
|
+ self.static2 = QLabel(self)
|
|
|
self.static2.setText("单车导航次数 : /")
|
|
|
self.static2.setGeometry(5, 40, 200, 30)
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
def UpdateUI(self):
|
|
|
- load_str="重载导航次数 : %d"%(threadPool.ThreadPool().loadCount())
|
|
|
- single_str="单车导航次数 : %d"%(threadPool.ThreadPool().singleCount())
|
|
|
+ load_str = "重载导航次数 : %d" % (auto_test.TestCount().loadCount())
|
|
|
+ single_str = "单车导航次数 : %d" % (auto_test.TestCount().singleCount())
|
|
|
self.static1.setText(load_str)
|
|
|
self.static2.setText(single_str)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|