JointContrallerWidget.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import time
  2. from concurrent.futures import ThreadPoolExecutor
  3. from PyQt5.QtCore import QTimer,Qt
  4. from PyQt5.QtWidgets import QFrame, QLabel, QPushButton,QCheckBox
  5. import Count
  6. import MapGLWidget as viewer
  7. class JointControlFrame(QFrame):
  8. threadPool_ = ThreadPoolExecutor(5)
  9. def __init__(self, robot1, robot2):
  10. QFrame.__init__(self)
  11. self.targetId_ = None
  12. self.begId_ = None
  13. self.robot1 = robot1
  14. self.robot2 = robot2
  15. self.robot1_parameters = dict()
  16. self.robot2_parameters = dict()
  17. self.InitUI()
  18. self.setFrameShape(self.StyledPanel)
  19. self.timer_ = QTimer()
  20. self.timer_.timeout.connect(self.Update)
  21. self.timer_.start(100)
  22. def testadjust(self, beg, target):
  23. autoDirect = True
  24. self.threadPool_.submit(self.robot1.Navigatting,
  25. beg, target, autoDirect)
  26. time.sleep(2)
  27. self.threadPool_.submit(self.robot2.Navigatting,
  28. beg, target, autoDirect)
  29. def InitUI(self):
  30. self.btnSend = QPushButton(self)
  31. self.btnSend.setGeometry(80, 5, 100, 40)
  32. self.btnSend.setText("双单车协动")
  33. self.btnSend.clicked.connect(self.btnSendClick)
  34. self.btnCancel = QPushButton(self)
  35. self.btnCancel.setGeometry(200, 5, 100, 40)
  36. self.btnCancel.setText(" 取消")
  37. self.btnCancel.clicked.connect(self.btnCancelClick)
  38. def Update(self):
  39. if self.robot1.IsNavigating() is True or self.robot2.IsNavigating() is True:
  40. if self.btnSend.isEnabled():
  41. self.btnSend.setEnabled(False)
  42. else:
  43. self.btnSend.setEnabled(True)
  44. def btnSendClick(self):
  45. autoDirect = True
  46. self.threadPool_.submit(self.robot1.Navigatting,
  47. self.robot1_parameters["begId_"], self.robot1_parameters["targetId_"], autoDirect, "DoubleAGV")
  48. time.sleep(0.5)
  49. self.threadPool_.submit(self.robot2.Navigatting,
  50. self.robot2_parameters["begId_"], self.robot2_parameters["targetId_"], autoDirect, "DoubleAGV")
  51. def btnCancelClick(self):
  52. self.threadPool_.submit(self.robot1.CancelNavTask)
  53. self.threadPool_.submit(self.robot2.CancelNavTask)
  54. def SetRobot1_BaTID(self, begId_, targetId_):
  55. self.robot1_parameters["begId_"] = begId_
  56. self.robot1_parameters["targetId_"] = targetId_
  57. def SetRobot2_BaTID(self, begId_, targetId_):
  58. self.robot2_parameters["begId_"] = begId_
  59. self.robot2_parameters["targetId_"] = targetId_
  60. class CountFrame(QFrame):
  61. def __init__(self):
  62. QFrame.__init__(self)
  63. self.InitUI()
  64. self.timer_ = QTimer()
  65. self.timer_.timeout.connect(self.UpdateUI)
  66. self.timer_.start(200)
  67. def InitUI(self):
  68. self.static1 = QLabel(self)
  69. self.static1.setText("重载导航次数 : /")
  70. #self.static1.setGeometry(5, 5, 100, 30)
  71. self.static2 = QLabel(self)
  72. self.static2.setText("单车导航次数 : /")
  73. #self.static2.setGeometry(5, 40, 100, 30)
  74. self.btnFrontCheck = QCheckBox("前车地图", self)
  75. self.btnFrontCheck.setGeometry(5, 5, 40, 30)
  76. self.btnFrontCheck.clicked.connect(self.FrontChecked)
  77. self.btnBackCheck = QCheckBox("后车地图", self)
  78. self.btnBackCheck.setGeometry(260, 40, 40, 30)
  79. self.btnBackCheck.clicked.connect(self.FrontChecked)
  80. self.btnMainCheck = QCheckBox("整车地图", self)
  81. self.btnMainCheck.setGeometry(310, 40, 40, 30)
  82. self.btnMainCheck.clicked.connect(self.FrontChecked)
  83. self.btnBaseCheck = QCheckBox("原始地图", self)
  84. self.btnBaseCheck.setGeometry(360, 40, 40, 30)
  85. self.btnBaseCheck.clicked.connect(self.FrontChecked)
  86. def UpdateUI(self):
  87. load_str = "重载导航次数 : %d" % (Count.TestCount().loadCount())
  88. single_str = "单车导航次数 : %d" % (Count.TestCount().singleCount())
  89. self.static1.setText(load_str)
  90. self.static2.setText(single_str)
  91. def FrontChecked(self):
  92. maps=[]
  93. if self.btnFrontCheck.checkState() == Qt.Checked:
  94. maps.append("Front")
  95. if self.btnBackCheck.checkState() == Qt.Checked:
  96. maps.append("Back")
  97. if self.btnMainCheck.checkState() == Qt.Checked:
  98. maps.append("Main")
  99. if self.btnBaseCheck.checkState() == Qt.Checked:
  100. maps.append("Base")
  101. view=viewer.MapGLWidget()
  102. view.SetMaps(maps)