This commit is contained in:
Kseninia Mikhaylova 2024-10-28 13:33:53 +03:00
parent aad39b5736
commit d7f1edce9c
14 changed files with 10667 additions and 10 deletions

0
__init__.py Normal file
View File

10615
app.log

File diff suppressed because it is too large Load Diff

14
main.py
View File

@ -2,12 +2,13 @@ import json
import sys
import time
import argparse
import threading
import queue
from PyQt5.QtCore import QThread
from PyQt5.QtWidgets import QApplication
from robot.client_socket import SocketRobotArm
from gui.init import MainContentComponent
from logger import logger
class MyApp:
with open("./robots.json", "r") as file:
@ -15,6 +16,9 @@ class MyApp:
def __init__(self, mode):
self.mode = mode
# self.robot_thread = RobotThread()
# self.robot_thread.start()
# self.robot_thread.finished.connect(self.startGui)
self.startRobot()
self.startGui()
@ -29,6 +33,7 @@ class MyApp:
def startGui(self):
app = QApplication(sys.argv)
mainWindow = MainContentComponent(
get_status=self.get_status,
robotPanel={
@ -56,6 +61,11 @@ class MyApp:
def startRobot(self):
self.robot_app = SocketRobotArm()
# Запускаем SocketRobotArm в отдельном потоке
threading.Thread(target=self.run_robot_arm, daemon=True).start()
def run_robot_arm(self):
self.robot_app.start()
def updateRobot(self, robot):
if robot in self.robots:

0
robot/__init__.py Normal file
View File

View File

@ -13,7 +13,8 @@ import pybullet_data
from robot.func import *
from logger import logger
os.environ["LIBGL_ALWAYS_SOFTWARE"] = "1"
# os.environ["LIBGL_ALWAYS_SOFTWARE"] = "1"
class SocketRobotArm:
line_speed = 100.0
@ -44,16 +45,21 @@ class SocketRobotArm:
self.physics_client = None
self.body_id = None
threading.Thread(target=self.run_pybullet, daemon=True).start()
self.q_app = None
def __exit__(self, exc_type, exc_value, traceback):
print("exiting")
self.socket.close()
def start(self):
self.run_pybullet()
def run_pybullet(self):
self.physics_client = p.connect(p.GUI)
p.loadPlugin("eglRendererPlugin")
p.setGravity(0, 0, -9.81, physicsClientId=self.physics_client)
p.setAdditionalSearchPath(pybullet_data.getDataPath())
p.configureDebugVisualizer(p.COV_ENABLE_GUI, 0)
urdf_path = os.path.join("urdf", f"{self.urdf_filename}.urdf")
if not os.path.exists(urdf_path):
@ -63,10 +69,12 @@ class SocketRobotArm:
self.body_id = p.loadURDF(urdf_path, [0, 0, 0], useFixedBase=True)
logger.info(f"Загружена модель {urdf_path}, id: {self.body_id}")
threading.Thread(target=self.simulation_loop, daemon=True).start()
# self.cube_id = p.loadURDF("r2d2.urdf", [0, 0, 1], useFixedBase=0)
self.simulation_loop()
def simulation_loop(self):
logger.info(f"Загружена simulation loop")
logger.info(f"Нчат цикл симуляции")
while True:
bodyUniqueId = self.body_id
position, orientation = p.getBasePositionAndOrientation(bodyUniqueId)
@ -76,12 +84,20 @@ class SocketRobotArm:
num_joints = p.getNumJoints(bodyUniqueId)
joint_states = p.getJointStates(bodyUniqueId, range(num_joints))
joint_log = []
for i, state in enumerate(joint_states):
joint_position = state[0] # Угол
joint_velocity = state[1] # Угловая скорость
# logger.info(f"Joint {i} - Position: {joint_position}, Velocity: {joint_velocity}")
joint_log.append(
f"Joint {i} - Position: {joint_position}, Velocity: {joint_velocity}"
)
logger.info("\n".join(joint_log))
p.stepSimulation()
if self.q_app:
logger.info(self.q_app)
self.q_app.processEvents()
time.sleep(1 / 24) # 24 кадра в секунду
def get_pybullet_image(self):
@ -99,9 +115,6 @@ class SocketRobotArm:
renderer=p.ER_BULLET_HARDWARE_OPENGL,
physicsClientId=self.physics_client,
)
logger.info(f"Image size: {width}x{height}, RGB data length: {len(rgb)}")
return (rgb, width, height)

19
robot_arm.py Normal file
View File

@ -0,0 +1,19 @@
# run.py
import sys
import os
import time
# Добавляем путь к родительской директории
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), 'robot')))
from robot.client_socket import SocketRobotArm
if __name__ == "__main__":
robot_arm = SocketRobotArm()
robot_arm.start()
try:
while True:
time.sleep(1) # Просто удерживаем основной поток активным
except KeyboardInterrupt:
print("Программа завершена.")

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB