vis start

This commit is contained in:
Kseninia Mikhaylova 2024-10-25 16:58:38 +03:00
parent 233417c50b
commit aad39b5736
16 changed files with 2367 additions and 76 deletions

2160
app.log

File diff suppressed because it is too large Load Diff

View File

@ -10,33 +10,21 @@ from gui.observable import Observable
from logger import logger from logger import logger
class RightPanel(QWidget): class MyPanel(QWidget):
def __init__(self, panels): def __init__(self, panels, color):
super().__init__() super().__init__()
layout = QVBoxLayout() layout = QVBoxLayout()
for panel in panels: for panel in panels:
layout.addWidget(panel) layout.addWidget(panel)
self.color = QColor(*color)
self.setLayout(layout) self.setLayout(layout)
self.initUI() self.initUI()
def initUI(self): def initUI(self):
palette = self.palette() palette = self.palette()
palette.setColor(QPalette.Window, QColor(169, 169, 169)) # DarkGray palette.setColor(QPalette.Window, self.color)
self.setAutoFillBackground(True)
self.setPalette(palette)
class MainPanel(QWidget):
def __init__(self, panels):
super().__init__()
layout = QVBoxLayout()
for panel in panels:
layout.addWidget(panel)
self.initUI()
def initUI(self):
palette = self.palette()
palette.setColor(QPalette.Window, QColor(255, 255, 255)) # White
self.setAutoFillBackground(True) self.setAutoFillBackground(True)
self.setPalette(palette) self.setPalette(palette)
@ -57,20 +45,22 @@ class MainContentComponent(QWidget):
imitatorArgs = kwargs.get("imitatorPanel", {}) imitatorArgs = kwargs.get("imitatorPanel", {})
self.imitatorPanel = Imitator(**imitatorArgs) self.imitatorPanel = Imitator(**imitatorArgs)
self.rightPanel = RightPanel( self.rightPanel = MyPanel(
panels=[ panels=[
self.statusPanel, self.statusPanel,
self.robotPanel, self.robotPanel,
self.imitatorPanel, self.imitatorPanel,
] ],
color=(169, 169, 169),
) )
visArgs = kwargs.get("visPanel", {}) visArgs = kwargs.get("visPanel", {})
self.visPanel = Visualize(**visArgs) self.visPanel = Visualize(**visArgs)
self.mainPanel = MainPanel( self.mainPanel = MyPanel(
panels=[ panels=[
self.visPanel, self.visPanel,
] ],
color=(200, 200, 200),
) )
layout = QHBoxLayout() layout = QHBoxLayout()
@ -93,7 +83,10 @@ class MainContentComponent(QWidget):
super().resizeEvent(event) super().resizeEvent(event)
def handle_value_change(self, new_value): def handle_value_change(self, new_value):
panels = [self.imitatorPanel, self.visPanel] panels = [
self.imitatorPanel,
self.visPanel,
]
for p in panels: for p in panels:
if new_value == "not_connected": if new_value == "not_connected":
p.setDisabled(True) p.setDisabled(True)

View File

@ -1,36 +1,63 @@
import time
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, QSizePolicy
from PyQt5.QtGui import QImage, QPixmap, QColor
from PyQt5.QtCore import Qt, QTimer
import numpy as np
from PIL import Image
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QSizePolicy
from PyQt5.QtGui import QImage, QPixmap
from PyQt5.QtCore import QTimer
from logger import logger from logger import logger
class Visualize(QWidget): class Visualize(QWidget):
def __init__(self, get_pybullet_image): def __init__(self, get_pybullet_image):
super().__init__() super().__init__()
self.get_pybullet_image = get_pybullet_image self.get_pybullet_image = get_pybullet_image
# Настройка компоновки # Настройка компоновки
self.layout = QVBoxLayout(self) self.layout = QVBoxLayout(self)
self.layout.setContentsMargins(0, 0, 0, 0) # Убираем отступы по краям self.layout.setContentsMargins(0, 0, 0, 0) # Убираем отступы по краям
self.h_layout = QHBoxLayout()
self.h_layout.setContentsMargins(0, 0, 0, 0) # Убираем отступы по краям
self.label = QLabel(self) self.label = QLabel(self)
self.label.setScaledContents(True) # Масштабирование изображения по размеру QLabel self.label.setScaledContents(True)
self.label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) # QLabel занимает всю доступную область self.label.setSizePolicy(
QSizePolicy.Expanding, QSizePolicy.Expanding
)
self.layout.addWidget(self.label) self.layout.addWidget(self.label)
# Таймер для обновления изображения # Таймер для обновления изображения
self.timer = QTimer() self.timer = QTimer()
self.timer.timeout.connect(self.update_image) self.timer.timeout.connect(self.update_image)
self.timer.start(100) # Обновление каждые 100 мс self.timer.start(1000) # Обновление каждые 100 мс
def update_image(self): def update_image(self):
(rgb, width, height) = self.get_pybullet_image() (rgb, width, height) = self.get_pybullet_image()
# logger.info('upd img') # logger.info(f"Image size: {width}x{height}, RGB data length: {len(rgb)}")
# rgbim = Image.fromarray(rgb)
# rgbim.save(f"test_img/rgbtest/{time.time() }.png")
# Преобразуем RGB данные в массив NumPy
rgb_array = np.array(rgb, dtype=np.uint8)
# Изменяем форму массива на (height, width, 4) для QImage
rgb_array = rgb_array.reshape(height, width, 4)
# Преобразование RGB-данных в QImage # Преобразование RGB-данных в QImage
image = QImage(rgb, width, height, QImage.Format_RGB888) image = QImage(rgb_array, width, height, QImage.Format_RGBA8888)
pixmap = QPixmap.fromImage(image) image = image.convertToFormat(QImage.Format_RGB888)
pixmap = QPixmap.fromImage(image)
# Обновление изображения на QLabel # Обновление изображения на QLabel
self.label.setPixmap(pixmap) self.label.setPixmap(pixmap)
self.label.repaint()
def paintEvent(self, event):
p = self.palette()
p.setColor(self.backgroundRole(), Qt.magenta)
self.setPalette(p)
super().paintEvent(event)

View File

@ -4,7 +4,7 @@ import logging
# Настройка логгера # Настройка логгера
logging.basicConfig( logging.basicConfig(
level=logging.DEBUG, # Уровень логирования level=logging.DEBUG, # Уровень логирования
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", format="%(asctime)s - %(name)s - %(levelname)s - %(message)s - %(filename)s - %(lineno)d",
handlers=[ handlers=[
logging.FileHandler("app.log"), # Запись в файл logging.FileHandler("app.log"), # Запись в файл
logging.StreamHandler(sys.stdout), # Вывод в консоль logging.StreamHandler(sys.stdout), # Вывод в консоль

94
poetry.lock generated
View File

@ -45,6 +45,98 @@ files = [
{file = "numpy-1.26.4.tar.gz", hash = "sha256:2a02aba9ed12e4ac4eb3ea9421c420301a0c6460d9830d74a9df87efa4912010"}, {file = "numpy-1.26.4.tar.gz", hash = "sha256:2a02aba9ed12e4ac4eb3ea9421c420301a0c6460d9830d74a9df87efa4912010"},
] ]
[[package]]
name = "pillow"
version = "11.0.0"
description = "Python Imaging Library (Fork)"
optional = false
python-versions = ">=3.9"
files = [
{file = "pillow-11.0.0-cp310-cp310-macosx_10_10_x86_64.whl", hash = "sha256:6619654954dc4936fcff82db8eb6401d3159ec6be81e33c6000dfd76ae189947"},
{file = "pillow-11.0.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:b3c5ac4bed7519088103d9450a1107f76308ecf91d6dabc8a33a2fcfb18d0fba"},
{file = "pillow-11.0.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a65149d8ada1055029fcb665452b2814fe7d7082fcb0c5bed6db851cb69b2086"},
{file = "pillow-11.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:88a58d8ac0cc0e7f3a014509f0455248a76629ca9b604eca7dc5927cc593c5e9"},
{file = "pillow-11.0.0-cp310-cp310-manylinux_2_28_aarch64.whl", hash = "sha256:c26845094b1af3c91852745ae78e3ea47abf3dbcd1cf962f16b9a5fbe3ee8488"},
{file = "pillow-11.0.0-cp310-cp310-manylinux_2_28_x86_64.whl", hash = "sha256:1a61b54f87ab5786b8479f81c4b11f4d61702830354520837f8cc791ebba0f5f"},
{file = "pillow-11.0.0-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:674629ff60030d144b7bca2b8330225a9b11c482ed408813924619c6f302fdbb"},
{file = "pillow-11.0.0-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:598b4e238f13276e0008299bd2482003f48158e2b11826862b1eb2ad7c768b97"},
{file = "pillow-11.0.0-cp310-cp310-win32.whl", hash = "sha256:9a0f748eaa434a41fccf8e1ee7a3eed68af1b690e75328fd7a60af123c193b50"},
{file = "pillow-11.0.0-cp310-cp310-win_amd64.whl", hash = "sha256:a5629742881bcbc1f42e840af185fd4d83a5edeb96475a575f4da50d6ede337c"},
{file = "pillow-11.0.0-cp310-cp310-win_arm64.whl", hash = "sha256:ee217c198f2e41f184f3869f3e485557296d505b5195c513b2bfe0062dc537f1"},
{file = "pillow-11.0.0-cp311-cp311-macosx_10_10_x86_64.whl", hash = "sha256:1c1d72714f429a521d8d2d018badc42414c3077eb187a59579f28e4270b4b0fc"},
{file = "pillow-11.0.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:499c3a1b0d6fc8213519e193796eb1a86a1be4b1877d678b30f83fd979811d1a"},
{file = "pillow-11.0.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c8b2351c85d855293a299038e1f89db92a2f35e8d2f783489c6f0b2b5f3fe8a3"},
{file = "pillow-11.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6f4dba50cfa56f910241eb7f883c20f1e7b1d8f7d91c750cd0b318bad443f4d5"},
{file = "pillow-11.0.0-cp311-cp311-manylinux_2_28_aarch64.whl", hash = "sha256:5ddbfd761ee00c12ee1be86c9c0683ecf5bb14c9772ddbd782085779a63dd55b"},
{file = "pillow-11.0.0-cp311-cp311-manylinux_2_28_x86_64.whl", hash = "sha256:45c566eb10b8967d71bf1ab8e4a525e5a93519e29ea071459ce517f6b903d7fa"},
{file = "pillow-11.0.0-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:b4fd7bd29610a83a8c9b564d457cf5bd92b4e11e79a4ee4716a63c959699b306"},
{file = "pillow-11.0.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:cb929ca942d0ec4fac404cbf520ee6cac37bf35be479b970c4ffadf2b6a1cad9"},
{file = "pillow-11.0.0-cp311-cp311-win32.whl", hash = "sha256:006bcdd307cc47ba43e924099a038cbf9591062e6c50e570819743f5607404f5"},
{file = "pillow-11.0.0-cp311-cp311-win_amd64.whl", hash = "sha256:52a2d8323a465f84faaba5236567d212c3668f2ab53e1c74c15583cf507a0291"},
{file = "pillow-11.0.0-cp311-cp311-win_arm64.whl", hash = "sha256:16095692a253047fe3ec028e951fa4221a1f3ed3d80c397e83541a3037ff67c9"},
{file = "pillow-11.0.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:d2c0a187a92a1cb5ef2c8ed5412dd8d4334272617f532d4ad4de31e0495bd923"},
{file = "pillow-11.0.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:084a07ef0821cfe4858fe86652fffac8e187b6ae677e9906e192aafcc1b69903"},
{file = "pillow-11.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8069c5179902dcdce0be9bfc8235347fdbac249d23bd90514b7a47a72d9fecf4"},
{file = "pillow-11.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f02541ef64077f22bf4924f225c0fd1248c168f86e4b7abdedd87d6ebaceab0f"},
{file = "pillow-11.0.0-cp312-cp312-manylinux_2_28_aarch64.whl", hash = "sha256:fcb4621042ac4b7865c179bb972ed0da0218a076dc1820ffc48b1d74c1e37fe9"},
{file = "pillow-11.0.0-cp312-cp312-manylinux_2_28_x86_64.whl", hash = "sha256:00177a63030d612148e659b55ba99527803288cea7c75fb05766ab7981a8c1b7"},
{file = "pillow-11.0.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:8853a3bf12afddfdf15f57c4b02d7ded92c7a75a5d7331d19f4f9572a89c17e6"},
{file = "pillow-11.0.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:3107c66e43bda25359d5ef446f59c497de2b5ed4c7fdba0894f8d6cf3822dafc"},
{file = "pillow-11.0.0-cp312-cp312-win32.whl", hash = "sha256:86510e3f5eca0ab87429dd77fafc04693195eec7fd6a137c389c3eeb4cfb77c6"},
{file = "pillow-11.0.0-cp312-cp312-win_amd64.whl", hash = "sha256:8ec4a89295cd6cd4d1058a5e6aec6bf51e0eaaf9714774e1bfac7cfc9051db47"},
{file = "pillow-11.0.0-cp312-cp312-win_arm64.whl", hash = "sha256:27a7860107500d813fcd203b4ea19b04babe79448268403172782754870dac25"},
{file = "pillow-11.0.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:bcd1fb5bb7b07f64c15618c89efcc2cfa3e95f0e3bcdbaf4642509de1942a699"},
{file = "pillow-11.0.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:0e038b0745997c7dcaae350d35859c9715c71e92ffb7e0f4a8e8a16732150f38"},
{file = "pillow-11.0.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0ae08bd8ffc41aebf578c2af2f9d8749d91f448b3bfd41d7d9ff573d74f2a6b2"},
{file = "pillow-11.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d69bfd8ec3219ae71bcde1f942b728903cad25fafe3100ba2258b973bd2bc1b2"},
{file = "pillow-11.0.0-cp313-cp313-manylinux_2_28_aarch64.whl", hash = "sha256:61b887f9ddba63ddf62fd02a3ba7add935d053b6dd7d58998c630e6dbade8527"},
{file = "pillow-11.0.0-cp313-cp313-manylinux_2_28_x86_64.whl", hash = "sha256:c6a660307ca9d4867caa8d9ca2c2658ab685de83792d1876274991adec7b93fa"},
{file = "pillow-11.0.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:73e3a0200cdda995c7e43dd47436c1548f87a30bb27fb871f352a22ab8dcf45f"},
{file = "pillow-11.0.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:fba162b8872d30fea8c52b258a542c5dfd7b235fb5cb352240c8d63b414013eb"},
{file = "pillow-11.0.0-cp313-cp313-win32.whl", hash = "sha256:f1b82c27e89fffc6da125d5eb0ca6e68017faf5efc078128cfaa42cf5cb38798"},
{file = "pillow-11.0.0-cp313-cp313-win_amd64.whl", hash = "sha256:8ba470552b48e5835f1d23ecb936bb7f71d206f9dfeee64245f30c3270b994de"},
{file = "pillow-11.0.0-cp313-cp313-win_arm64.whl", hash = "sha256:846e193e103b41e984ac921b335df59195356ce3f71dcfd155aa79c603873b84"},
{file = "pillow-11.0.0-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:4ad70c4214f67d7466bea6a08061eba35c01b1b89eaa098040a35272a8efb22b"},
{file = "pillow-11.0.0-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:6ec0d5af64f2e3d64a165f490d96368bb5dea8b8f9ad04487f9ab60dc4bb6003"},
{file = "pillow-11.0.0-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c809a70e43c7977c4a42aefd62f0131823ebf7dd73556fa5d5950f5b354087e2"},
{file = "pillow-11.0.0-cp313-cp313t-manylinux_2_28_x86_64.whl", hash = "sha256:4b60c9520f7207aaf2e1d94de026682fc227806c6e1f55bba7606d1c94dd623a"},
{file = "pillow-11.0.0-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:1e2688958a840c822279fda0086fec1fdab2f95bf2b717b66871c4ad9859d7e8"},
{file = "pillow-11.0.0-cp313-cp313t-win32.whl", hash = "sha256:607bbe123c74e272e381a8d1957083a9463401f7bd01287f50521ecb05a313f8"},
{file = "pillow-11.0.0-cp313-cp313t-win_amd64.whl", hash = "sha256:5c39ed17edea3bc69c743a8dd3e9853b7509625c2462532e62baa0732163a904"},
{file = "pillow-11.0.0-cp313-cp313t-win_arm64.whl", hash = "sha256:75acbbeb05b86bc53cbe7b7e6fe00fbcf82ad7c684b3ad82e3d711da9ba287d3"},
{file = "pillow-11.0.0-cp39-cp39-macosx_10_10_x86_64.whl", hash = "sha256:2e46773dc9f35a1dd28bd6981332fd7f27bec001a918a72a79b4133cf5291dba"},
{file = "pillow-11.0.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:2679d2258b7f1192b378e2893a8a0a0ca472234d4c2c0e6bdd3380e8dfa21b6a"},
{file = "pillow-11.0.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:eda2616eb2313cbb3eebbe51f19362eb434b18e3bb599466a1ffa76a033fb916"},
{file = "pillow-11.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:20ec184af98a121fb2da42642dea8a29ec80fc3efbaefb86d8fdd2606619045d"},
{file = "pillow-11.0.0-cp39-cp39-manylinux_2_28_aarch64.whl", hash = "sha256:8594f42df584e5b4bb9281799698403f7af489fba84c34d53d1c4bfb71b7c4e7"},
{file = "pillow-11.0.0-cp39-cp39-manylinux_2_28_x86_64.whl", hash = "sha256:c12b5ae868897c7338519c03049a806af85b9b8c237b7d675b8c5e089e4a618e"},
{file = "pillow-11.0.0-cp39-cp39-musllinux_1_2_aarch64.whl", hash = "sha256:70fbbdacd1d271b77b7721fe3cdd2d537bbbd75d29e6300c672ec6bb38d9672f"},
{file = "pillow-11.0.0-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:5178952973e588b3f1360868847334e9e3bf49d19e169bbbdfaf8398002419ae"},
{file = "pillow-11.0.0-cp39-cp39-win32.whl", hash = "sha256:8c676b587da5673d3c75bd67dd2a8cdfeb282ca38a30f37950511766b26858c4"},
{file = "pillow-11.0.0-cp39-cp39-win_amd64.whl", hash = "sha256:94f3e1780abb45062287b4614a5bc0874519c86a777d4a7ad34978e86428b8dd"},
{file = "pillow-11.0.0-cp39-cp39-win_arm64.whl", hash = "sha256:290f2cc809f9da7d6d622550bbf4c1e57518212da51b6a30fe8e0a270a5b78bd"},
{file = "pillow-11.0.0-pp310-pypy310_pp73-macosx_10_15_x86_64.whl", hash = "sha256:1187739620f2b365de756ce086fdb3604573337cc28a0d3ac4a01ab6b2d2a6d2"},
{file = "pillow-11.0.0-pp310-pypy310_pp73-macosx_11_0_arm64.whl", hash = "sha256:fbbcb7b57dc9c794843e3d1258c0fbf0f48656d46ffe9e09b63bbd6e8cd5d0a2"},
{file = "pillow-11.0.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5d203af30149ae339ad1b4f710d9844ed8796e97fda23ffbc4cc472968a47d0b"},
{file = "pillow-11.0.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:21a0d3b115009ebb8ac3d2ebec5c2982cc693da935f4ab7bb5c8ebe2f47d36f2"},
{file = "pillow-11.0.0-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:73853108f56df97baf2bb8b522f3578221e56f646ba345a372c78326710d3830"},
{file = "pillow-11.0.0-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:e58876c91f97b0952eb766123bfef372792ab3f4e3e1f1a2267834c2ab131734"},
{file = "pillow-11.0.0-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:224aaa38177597bb179f3ec87eeefcce8e4f85e608025e9cfac60de237ba6316"},
{file = "pillow-11.0.0-pp39-pypy39_pp73-macosx_11_0_arm64.whl", hash = "sha256:5bd2d3bdb846d757055910f0a59792d33b555800813c3b39ada1829c372ccb06"},
{file = "pillow-11.0.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:375b8dd15a1f5d2feafff536d47e22f69625c1aa92f12b339ec0b2ca40263273"},
{file = "pillow-11.0.0-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:daffdf51ee5db69a82dd127eabecce20729e21f7a3680cf7cbb23f0829189790"},
{file = "pillow-11.0.0-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:7326a1787e3c7b0429659e0a944725e1b03eeaa10edd945a86dead1913383944"},
{file = "pillow-11.0.0.tar.gz", hash = "sha256:72bacbaf24ac003fea9bff9837d1eedb6088758d41e100c1552930151f677739"},
]
[package.extras]
docs = ["furo", "olefile", "sphinx (>=8.1)", "sphinx-copybutton", "sphinx-inline-tabs", "sphinxext-opengraph"]
fpx = ["olefile"]
mic = ["olefile"]
tests = ["check-manifest", "coverage", "defusedxml", "markdown2", "olefile", "packaging", "pyroma", "pytest", "pytest-cov", "pytest-timeout"]
typing = ["typing-extensions"]
xmp = ["defusedxml"]
[[package]] [[package]]
name = "popsicle" name = "popsicle"
version = "0.9.6" version = "0.9.6"
@ -179,4 +271,4 @@ files = [
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "3.10.12" python-versions = "3.10.12"
content-hash = "674afa8962f34256e63f5d5af6be94013e2c39e9880191eb3caecc9f70dcf704" content-hash = "f85dffb2208f45a3e3405ff57e5215d35ca57ed3e846c4f1580cd20bb4111491"

View File

@ -13,6 +13,7 @@ pybullet = "^3.2.6"
numpy = "^1.20" numpy = "^1.20"
popsicle = "^0.9.6" popsicle = "^0.9.6"
pyqt5 = "^5.15.11" pyqt5 = "^5.15.11"
pillow = "^11.0.0"
[build-system] [build-system]

View File

@ -46,38 +46,50 @@ class SocketRobotArm:
self.body_id = None self.body_id = None
threading.Thread(target=self.run_pybullet, daemon=True).start() threading.Thread(target=self.run_pybullet, daemon=True).start()
# self.socket.connect((self.host, self.port))
# self.cycle_base()
def __exit__(self, exc_type, exc_value, traceback): def __exit__(self, exc_type, exc_value, traceback):
print("exiting") print("exiting")
self.socket.close() self.socket.close()
def run_pybullet(self): def run_pybullet(self):
self.physics_client = p.connect(p.GUI) self.physics_client = p.connect(p.GUI)
p.setGravity(0, 0, -9.81, physicsClientId=self.physics_client) p.setGravity(0, 0, -9.81, physicsClientId=self.physics_client)
p.setAdditionalSearchPath(pybullet_data.getDataPath()) p.setAdditionalSearchPath(pybullet_data.getDataPath())
urdf_path = os.path.join("urdf", f"{self.urdf_filename}.urdf") urdf_path = os.path.join("urdf", f"{self.urdf_filename}.urdf")
if not os.path.exists(urdf_path): if not os.path.exists(urdf_path):
raise FileNotFoundError(f"URDF file not found: {urdf_path}") raise FileNotFoundError(f"URDF file not found: {urdf_path}")
self.body_id = p.loadURDF( p.loadURDF("plane.urdf")
urdf_path, self.body_id = p.loadURDF(urdf_path, [0, 0, 0], useFixedBase=True)
[0, 0, 0], logger.info(f"Загружена модель {urdf_path}, id: {self.body_id}")
useFixedBase=True,
) threading.Thread(target=self.simulation_loop, daemon=True).start()
logger.info(f"Loaded URDF: {urdf_path} with body ID: {self.body_id}") def simulation_loop(self):
logger.info(f"Загружена simulation loop")
while True:
bodyUniqueId = self.body_id
position, orientation = p.getBasePositionAndOrientation(bodyUniqueId)
# logger.info(f"Position: {position}, Orientation: {orientation}")
# Получение состояния суставов
num_joints = p.getNumJoints(bodyUniqueId)
joint_states = p.getJointStates(bodyUniqueId, range(num_joints))
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}")
p.stepSimulation()
time.sleep(1 / 24) # 24 кадра в секунду
def get_pybullet_image(self): def get_pybullet_image(self):
p.stepSimulation()
width, height, rgb, _, _ = p.getCameraImage( width, height, rgb, _, _ = p.getCameraImage(
width=800, width=640,
height=800, height=640,
viewMatrix=p.computeViewMatrix( viewMatrix=p.computeViewMatrix(
cameraEyePosition=[0, 0, 1], cameraEyePosition=[2, 2, 2],
cameraTargetPosition=[0, 0, 0], cameraTargetPosition=[0, 0, 0],
cameraUpVector=[0, 0, 1], cameraUpVector=[0, 0, 1],
), ),
@ -87,6 +99,10 @@ class SocketRobotArm:
renderer=p.ER_BULLET_HARDWARE_OPENGL, renderer=p.ER_BULLET_HARDWARE_OPENGL,
physicsClientId=self.physics_client, physicsClientId=self.physics_client,
) )
logger.info(f"Image size: {width}x{height}, RGB data length: {len(rgb)}")
return (rgb, width, height) return (rgb, width, height)
def close(self): def close(self):
@ -172,17 +188,19 @@ class SocketRobotArm:
targetPosition=coordinates, targetPosition=coordinates,
) )
print(joint_angles) print(joint_angles)
return joint_angles logger.info(joint_angles)
def set_text(self, text): def set_text(self, text):
print(text) logger.info(text)
def set_joint(self, coordinates): def set_joint(self, coordinates):
logger.info('set joint') logger.info("set joints")
num_joints = p.getNumJoints(self.body_id) num_joints = p.getNumJoints(self.body_id)
if coordinates is None:
return
for joint_index in range(0, num_joints): for joint_index in range(0, num_joints):
# if not joint_index in coordinates: if coordinates[joint_index] is None:
# return return
p.setJointMotorControl2( p.setJointMotorControl2(
bodyUniqueId=self.body_id, bodyUniqueId=self.body_id,
jointIndex=joint_index, jointIndex=joint_index,

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@ -10,14 +10,14 @@
<link name="base_link"> <link name="base_link">
<visual> <visual>
<geometry> <geometry>
<mesh filename="/home/aarizona/projects/modbus_test/borunte_support/meshes/base_link.stl"/> <mesh filename="/home/aarizona/projects/modbus_test/urdf_support/borunte_support/meshes/base_link.stl"/>
</geometry> </geometry>
<origin rpy="0.0 0 0.0" xyz="0 0 0"/> <origin rpy="0.0 0 0.0" xyz="0 0 0"/>
<material name="Black"/> <material name="Black"/>
</visual> </visual>
<collision> <collision>
<geometry> <geometry>
<mesh filename="/home/aarizona/projects/modbus_test/borunte_support/meshes/base_link_collision.stl"/> <mesh filename="/home/aarizona/projects/modbus_test/urdf_support/borunte_support/meshes/base_link_collision.stl"/>
</geometry> </geometry>
<origin rpy="0.0 0 0.0" xyz="0 0 0"/> <origin rpy="0.0 0 0.0" xyz="0 0 0"/>
</collision> </collision>
@ -25,14 +25,14 @@
<link name="link_1"> <link name="link_1">
<visual> <visual>
<geometry> <geometry>
<mesh filename="/home/aarizona/projects/modbus_test/borunte_support/meshes/link_1.stl"/> <mesh filename="/home/aarizona/projects/modbus_test/urdf_support/borunte_support/meshes/link_1.stl"/>
</geometry> </geometry>
<origin rpy="0.0 0 0.0" xyz="0 0 0"/> <origin rpy="0.0 0 0.0" xyz="0 0 0"/>
<material name="DarkRed"/> <material name="DarkRed"/>
</visual> </visual>
<collision> <collision>
<geometry> <geometry>
<mesh filename="/home/aarizona/projects/modbus_test/borunte_support/meshes/link_1_collision.stl"/> <mesh filename="/home/aarizona/projects/modbus_test/urdf_support/borunte_support/meshes/link_1_collision.stl"/>
</geometry> </geometry>
<origin rpy="0.0 0 0.0" xyz="0 0 0"/> <origin rpy="0.0 0 0.0" xyz="0 0 0"/>
</collision> </collision>
@ -44,14 +44,14 @@
<link name="link_2"> <link name="link_2">
<visual> <visual>
<geometry> <geometry>
<mesh filename="/home/aarizona/projects/modbus_test/borunte_support/meshes/link_2.stl"/> <mesh filename="/home/aarizona/projects/modbus_test/urdf_support/borunte_support/meshes/link_2.stl"/>
</geometry> </geometry>
<origin rpy="0.0 0 0.0" xyz="0 0 0"/> <origin rpy="0.0 0 0.0" xyz="0 0 0"/>
<material name="DarkRed"/> <material name="DarkRed"/>
</visual> </visual>
<collision> <collision>
<geometry> <geometry>
<mesh filename="/home/aarizona/projects/modbus_test/borunte_support/meshes/link_2_collision.stl"/> <mesh filename="/home/aarizona/projects/modbus_test/urdf_support/borunte_support/meshes/link_2_collision.stl"/>
</geometry> </geometry>
<origin rpy="0.0 0 0.0" xyz="0 0 0"/> <origin rpy="0.0 0 0.0" xyz="0 0 0"/>
</collision> </collision>
@ -63,14 +63,14 @@
<link name="link_3"> <link name="link_3">
<visual> <visual>
<geometry> <geometry>
<mesh filename="/home/aarizona/projects/modbus_test/borunte_support/meshes/link_3.stl"/> <mesh filename="/home/aarizona/projects/modbus_test/urdf_support/borunte_support/meshes/link_3.stl"/>
</geometry> </geometry>
<origin rpy="0.0 0 0.0" xyz="0 0.01 0"/> <origin rpy="0.0 0 0.0" xyz="0 0.01 0"/>
<material name="DarkRed"/> <material name="DarkRed"/>
</visual> </visual>
<collision> <collision>
<geometry> <geometry>
<mesh filename="/home/aarizona/projects/modbus_test/borunte_support/meshes/link_3_collision.stl"/> <mesh filename="/home/aarizona/projects/modbus_test/urdf_support/borunte_support/meshes/link_3_collision.stl"/>
</geometry> </geometry>
<origin rpy="0.0 0 0.0" xyz="0 0.01 0"/> <origin rpy="0.0 0 0.0" xyz="0 0.01 0"/>
</collision> </collision>
@ -82,14 +82,14 @@
<link name="link_4"> <link name="link_4">
<visual> <visual>
<geometry> <geometry>
<mesh filename="/home/aarizona/projects/modbus_test/borunte_support/meshes/link_4.stl"/> <mesh filename="/home/aarizona/projects/modbus_test/urdf_support/borunte_support/meshes/link_4.stl"/>
</geometry> </geometry>
<origin rpy="0.0 0.0 0.0" xyz="0 0 0"/> <origin rpy="0.0 0.0 0.0" xyz="0 0 0"/>
<material name="DarkRed"/> <material name="DarkRed"/>
</visual> </visual>
<collision> <collision>
<geometry> <geometry>
<mesh filename="/home/aarizona/projects/modbus_test/borunte_support/meshes/link_4_collision.stl"/> <mesh filename="/home/aarizona/projects/modbus_test/urdf_support/borunte_support/meshes/link_4_collision.stl"/>
</geometry> </geometry>
<origin rpy="0.0 0 0.0" xyz="0 0 0"/> <origin rpy="0.0 0 0.0" xyz="0 0 0"/>
</collision> </collision>
@ -101,14 +101,14 @@
<link name="link_5"> <link name="link_5">
<visual> <visual>
<geometry> <geometry>
<mesh filename="/home/aarizona/projects/modbus_test/borunte_support/meshes/link_5.stl"/> <mesh filename="/home/aarizona/projects/modbus_test/urdf_support/borunte_support/meshes/link_5.stl"/>
</geometry> </geometry>
<origin rpy="0 0 0" xyz="0 0 0"/> <origin rpy="0 0 0" xyz="0 0 0"/>
<material name="DarkRed"/> <material name="DarkRed"/>
</visual> </visual>
<collision> <collision>
<geometry> <geometry>
<mesh filename="/home/aarizona/projects/modbus_test/borunte_support/meshes/link_5_collision.stl"/> <mesh filename="/home/aarizona/projects/modbus_test/urdf_support/borunte_support/meshes/link_5_collision.stl"/>
</geometry> </geometry>
<origin rpy="0 0 0" xyz="0 0 0"/> <origin rpy="0 0 0" xyz="0 0 0"/>
</collision> </collision>
@ -120,14 +120,14 @@
<link name="link_6"> <link name="link_6">
<visual> <visual>
<geometry> <geometry>
<mesh filename="/home/aarizona/projects/modbus_test/borunte_support/meshes/link_6.stl"/> <mesh filename="/home/aarizona/projects/modbus_test/urdf_support/borunte_support/meshes/link_6.stl"/>
</geometry> </geometry>
<origin rpy="0 0 0.0" xyz="0 0 0"/> <origin rpy="0 0 0.0" xyz="0 0 0"/>
<material name="DarkRed"/> <material name="DarkRed"/>
</visual> </visual>
<collision> <collision>
<geometry> <geometry>
<mesh filename="/home/aarizona/projects/modbus_test/borunte_support/meshes/link_6_collision.stl"/> <mesh filename="/home/aarizona/projects/modbus_test/urdf_support/borunte_support/meshes/link_6_collision.stl"/>
</geometry> </geometry>
<origin rpy="0 0 0.0" xyz="0 0 0"/> <origin rpy="0 0 0.0" xyz="0 0 0"/>
</collision> </collision>