94 lines
2.7 KiB
Python
94 lines
2.7 KiB
Python
import json
|
|
import sys
|
|
import time
|
|
import argparse
|
|
import threading
|
|
from PyQt5.QtCore import QThread
|
|
from PyQt5.QtWidgets import QApplication
|
|
|
|
from robot.client_socket import SocketRobotArm
|
|
from gui.init import MainContentComponent
|
|
|
|
class MyApp:
|
|
with open("./robots.json", "r") as file:
|
|
robots = json.load(file)
|
|
|
|
def __init__(self, mode):
|
|
self.mode = mode
|
|
self.startRobot()
|
|
self.startGui()
|
|
|
|
def get_status(self):
|
|
if self.robot_app:
|
|
return self.robot_app.get_status()
|
|
else:
|
|
return self.def_robot_status()
|
|
|
|
def def_robot_status(self):
|
|
return SocketRobotArm.Status[1]
|
|
|
|
def startGui(self):
|
|
app = QApplication(sys.argv)
|
|
self.robot_app.q_app = app
|
|
mainWindow = MainContentComponent(
|
|
get_status=self.get_status,
|
|
robotPanel={
|
|
"robots": self.robots,
|
|
"updateRobot": self.updateRobot,
|
|
"status": self.get_status,
|
|
},
|
|
statusPanel={
|
|
"status": self.get_status,
|
|
},
|
|
imitatorPanel={
|
|
"world_coord": self.robot_app.get_world_coordinates,
|
|
"axis_coord": self.robot_app.get_axis_coordinates,
|
|
"command_count": self.robot_app.get_command_count,
|
|
"updateData": self.robot_app.upd_model,
|
|
},
|
|
visPanel={
|
|
"get_pybullet_image": self.robot_app.get_pybullet_image,
|
|
},
|
|
)
|
|
mainWindow.setWindowTitle("ROBOT GUI")
|
|
mainWindow.show()
|
|
|
|
sys.exit(app.exec_())
|
|
|
|
def startRobot(self):
|
|
self.robot_app = SocketRobotArm()
|
|
# Запускаем SocketRobotArm в отдельном потоке
|
|
threading.Thread(target=self.run_robot_arm, daemon=True).start()
|
|
|
|
def run_robot_arm(self):
|
|
time.sleep(1)
|
|
self.robot_app.start('GUI')
|
|
|
|
def updateRobot(self, robot):
|
|
if robot in self.robots:
|
|
selected_robot = robot
|
|
if self.mode == "test":
|
|
selected_robot = {"name": "test", "host": "127.0.0.1", "slave_id": 11}
|
|
|
|
if self.robot_app.status == "connected":
|
|
self.robot_app.close()
|
|
time.sleep(0.3)
|
|
else:
|
|
self.robot_app.connect(
|
|
selected_robot["host"], selected_robot["slave_id"]
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description="MyApp Command Line Interface")
|
|
parser.add_argument(
|
|
"--mode",
|
|
type=str,
|
|
choices=["test", "prod"],
|
|
default="prod",
|
|
help="Mode of operation",
|
|
)
|
|
# MyApp()
|
|
args = parser.parse_args()
|
|
app = MyApp(args.mode)
|