From 9ea238d326e3dddb0c009351fe3d39254a219254 Mon Sep 17 00:00:00 2001 From: Aitor Martinez Date: Fri, 10 Mar 2017 09:46:33 +0100 Subject: [PATCH] [issue #707] Added Logo and JderobotComm to basic_component_py --- .../{main.py => basic_component.py} | 14 ++-- .../basic_component_py/basic_component_py.cfg | 18 +++-- src/tools/basic_component_py/generateGUI | 9 +++ src/tools/basic_component_py/gui/GUI.py | 27 ++++--- .../basic_component_py/gui/cameraWidget.py | 19 ++--- .../basic_component_py/gui/logoWidget.py | 44 ++++++++++++ src/tools/basic_component_py/gui/ui_gui.py | 12 +++- src/tools/basic_component_py/gui/ui_gui.ui | 31 +++++--- .../basic_component_py/resources/jderobot.svg | 11 +++ .../resources/resources.qrc | 1 + src/tools/basic_component_py/resources_rc.py | 70 ++++++++++++++++++- 11 files changed, 216 insertions(+), 40 deletions(-) rename src/tools/basic_component_py/{main.py => basic_component.py} (85%) create mode 100755 src/tools/basic_component_py/generateGUI create mode 100644 src/tools/basic_component_py/gui/logoWidget.py create mode 100644 src/tools/basic_component_py/resources/jderobot.svg diff --git a/src/tools/basic_component_py/main.py b/src/tools/basic_component_py/basic_component.py similarity index 85% rename from src/tools/basic_component_py/main.py rename to src/tools/basic_component_py/basic_component.py index a8964615c..9057c4b1e 100755 --- a/src/tools/basic_component_py/main.py +++ b/src/tools/basic_component_py/basic_component.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/python2 # -*- coding: utf-8 -*- # # Copyright (C) 1997-2016 JdeRobot Developers Team @@ -21,8 +21,7 @@ import sys -from parallelIce.cameraClient import CameraClient -from parallelIce.motors import Motors +import jderobotComm as comm from gui.threadGUI import ThreadGUI from gui.GUI import MainWindow from PyQt5.QtWidgets import QApplication @@ -34,8 +33,13 @@ if __name__ == '__main__': ic = EasyIce.initialize(sys.argv) - camera = CameraClient(ic,"basic_component.Camera",True) - motors = Motors(ic,"basic_component.Motors") + + #starting comm + ic, node = comm.init(ic) + + + camera = comm.getCameraClient(ic,"basic_component.Camera") + motors = comm.getMotorsClient(ic,"basic_component.Motors") app = QApplication(sys.argv) frame = MainWindow() diff --git a/src/tools/basic_component_py/basic_component_py.cfg b/src/tools/basic_component_py/basic_component_py.cfg index 59cfc091c..262f8d9cb 100644 --- a/src/tools/basic_component_py/basic_component_py.cfg +++ b/src/tools/basic_component_py/basic_component_py.cfg @@ -1,8 +1,16 @@ -basic_component.Camera.Proxy=cam_turtlebot_right:default -h localhost -p 8994 -basic_component.Camera.Format=RGB8 - +############ Motors ####################### +# 0 -> Deactivate, 1 -> Ice , 2 -> ROS +basic_component.Motors.Server=1 basic_component.Motors.Proxy=Motors:default -h localhost -p 8999 +basic_component.Motors.Topic=/cmd_vel_mux/input/teleop +basic_component.Motors.Name=FolowLineMotors -#basic_component.Motors.maxV = 5 -#basic_component.Motors.maxW = 0.5 + +############ Camera ####################### +# 0 -> Deactivate, 1 -> Ice , 2 -> ROS +basic_component.Camera.Server=1 +basic_component.Camera.Proxy=cam_turtlebot_right:default -h localhost -p 8994 +basic_component.Camera.Format=RGB8 +basic_component.Camera.Topic=/camera/rgb/image_raw +basic_component.Camera.Name=basic_component_pyCamera diff --git a/src/tools/basic_component_py/generateGUI b/src/tools/basic_component_py/generateGUI new file mode 100755 index 000000000..d2d26b788 --- /dev/null +++ b/src/tools/basic_component_py/generateGUI @@ -0,0 +1,9 @@ +#!/bin/bash + cd resources + pyrcc5 resources.qrc -o resources_rc.py + mv resources_rc.py .. + + cd ../gui + pyuic5 ui_gui.ui > ui_gui.py + cd .. + diff --git a/src/tools/basic_component_py/gui/GUI.py b/src/tools/basic_component_py/gui/GUI.py index 4bea97342..fe18f7640 100644 --- a/src/tools/basic_component_py/gui/GUI.py +++ b/src/tools/basic_component_py/gui/GUI.py @@ -21,10 +21,13 @@ from PyQt5.QtCore import pyqtSignal from PyQt5.QtWidgets import QMainWindow -from gui.ui_gui import Ui_MainWindow -from gui.teleopWidget import TeleopWidget -from gui.cameraWidget import CameraWidget -from gui.communicator import Communicator +from .ui_gui import Ui_MainWindow +from .teleopWidget import TeleopWidget +from .cameraWidget import CameraWidget +from .communicator import Communicator +from .logoWidget import LogoWidget + +from jderobotTypes import CMDVel class MainWindow(QMainWindow, Ui_MainWindow): @@ -38,6 +41,10 @@ def __init__(self, parent=None): self.tlLayout.addWidget(self.teleop) self.teleop.setVisible(True) + self.logo = LogoWidget(self, self.logoLayout.parent().width(), self.logoLayout.parent().height()) + self.logoLayout.addWidget(self.logo) + self.logo.setVisible(True) + self.updGUI.connect(self.updateGUI) self.cameraWidget = CameraWidget(self) @@ -64,9 +71,11 @@ def updateGUI(self): def setXYValues(self, newX, newY): self.XValue.setText(str(newX)) self.YValue.setText(str(newY)) - myW=-newX*self.motors.getMaxW() - myV=-newY*self.motors.getMaxV() - self.motors.setV(myV) - self.motors.setW(myW) - self.motors.sendVelocities() + if (self.motors): + vel = CMDVel() + myW=-newX*self.motors.getMaxW() + myV=-newY*self.motors.getMaxV() + vel.vx = myV + vel.az = myW + self.motors.sendVelocities(vel) diff --git a/src/tools/basic_component_py/gui/cameraWidget.py b/src/tools/basic_component_py/gui/cameraWidget.py index 7fcd803d8..5785af931 100644 --- a/src/tools/basic_component_py/gui/cameraWidget.py +++ b/src/tools/basic_component_py/gui/cameraWidget.py @@ -41,12 +41,13 @@ def initUI(self): def updateImage(self): - img = self.winParent.getCamera().getImage() - if img is not None: - image = QImage(img.data, img.shape[1], img.shape[0], - img.shape[1] * img.shape[2], QImage.Format_RGB888) - - size = QtCore.QSize(img.shape[1], img.shape[0]) - self.resize(size) - self.imgLabel.resize(size) - self.imgLabel.setPixmap(QPixmap.fromImage(image)) + if (self.winParent.getCamera()): + img = self.winParent.getCamera().getImage().data + if img is not None: + image = QImage(img.data, img.shape[1], img.shape[0], + img.shape[1] * img.shape[2], QImage.Format_RGB888) + + size = QtCore.QSize(img.shape[1], img.shape[0]) + self.resize(size) + self.imgLabel.resize(size) + self.imgLabel.setPixmap(QPixmap.fromImage(image)) diff --git a/src/tools/basic_component_py/gui/logoWidget.py b/src/tools/basic_component_py/gui/logoWidget.py new file mode 100644 index 000000000..3e7b80b02 --- /dev/null +++ b/src/tools/basic_component_py/gui/logoWidget.py @@ -0,0 +1,44 @@ +# +# Copyright (C) 1997-2015 JDE Developers Team +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. +# Authors : +# Alberto Martin Florido +# +import resources_rc +from PyQt5 import QtGui +from PyQt5.QtCore import pyqtSignal, QPointF, Qt, QPoint +from PyQt5.QtWidgets import QWidget, QGridLayout + +class LogoWidget(QWidget): + + def __init__(self,winParent, width=0, height=0): + super(LogoWidget, self).__init__() + self.winParent=winParent + qimage=QtGui.QImage() + qimage.load(':images/jderobot.svg') + if (width != 0 and height != 0): + self.qimage = qimage.scaled(0.8*width, 0.8*height, Qt.KeepAspectRatio) + #self.qimage = qimage.scaled(0.8*width, 0.8*height) + self.resize(width, height) + else: + self.qimage = qimage + + + def paintEvent(self, e): + + painter=QtGui.QPainter(self) + painter.drawImage(self.width()/2-self.qimage.width()/2, self.height()/2-self.qimage.height()/2, self.qimage) + + diff --git a/src/tools/basic_component_py/gui/ui_gui.py b/src/tools/basic_component_py/gui/ui_gui.py index 6a6ead682..584c1bc70 100644 --- a/src/tools/basic_component_py/gui/ui_gui.py +++ b/src/tools/basic_component_py/gui/ui_gui.py @@ -11,9 +11,9 @@ class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") - MainWindow.resize(400, 370) - MainWindow.setMinimumSize(QtCore.QSize(400, 370)) - MainWindow.setMaximumSize(QtCore.QSize(400, 370)) + MainWindow.resize(430, 400) + MainWindow.setMinimumSize(QtCore.QSize(430, 400)) + MainWindow.setMaximumSize(QtCore.QSize(800, 800)) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget) @@ -35,6 +35,12 @@ def setupUi(self, MainWindow): self.YValue.setGeometry(QtCore.QRect(150, 340, 41, 21)) self.YValue.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) self.YValue.setObjectName("YValue") + self.verticalLayoutWidget_2 = QtWidgets.QWidget(self.centralwidget) + self.verticalLayoutWidget_2.setGeometry(QtCore.QRect(350, 320, 80, 80)) + self.verticalLayoutWidget_2.setObjectName("verticalLayoutWidget_2") + self.logoLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_2) + self.logoLayout.setSpacing(0) + self.logoLayout.setObjectName("logoLayout") MainWindow.setCentralWidget(self.centralwidget) self.retranslateUi(MainWindow) diff --git a/src/tools/basic_component_py/gui/ui_gui.ui b/src/tools/basic_component_py/gui/ui_gui.ui index 738dcf164..64d606ea1 100644 --- a/src/tools/basic_component_py/gui/ui_gui.ui +++ b/src/tools/basic_component_py/gui/ui_gui.ui @@ -1,25 +1,25 @@ - MainWindow - +MainWindow + 0 0 - 400 - 370 + 430 + 400 - 400 - 370 + 430 + 400 - 400 - 370 + 800 + 800 @@ -95,6 +95,21 @@ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + 350 + 320 + 80 + 80 + + + + + 0 + + + diff --git a/src/tools/basic_component_py/resources/jderobot.svg b/src/tools/basic_component_py/resources/jderobot.svg new file mode 100644 index 000000000..2b49dfaa9 --- /dev/null +++ b/src/tools/basic_component_py/resources/jderobot.svg @@ -0,0 +1,11 @@ + + + + + + + + + JdeRobot + + diff --git a/src/tools/basic_component_py/resources/resources.qrc b/src/tools/basic_component_py/resources/resources.qrc index 5620b8083..49295fc7b 100644 --- a/src/tools/basic_component_py/resources/resources.qrc +++ b/src/tools/basic_component_py/resources/resources.qrc @@ -1,5 +1,6 @@ ball.png + jderobot.svg diff --git a/src/tools/basic_component_py/resources_rc.py b/src/tools/basic_component_py/resources_rc.py index a171dd791..473c4983e 100644 --- a/src/tools/basic_component_py/resources_rc.py +++ b/src/tools/basic_component_py/resources_rc.py @@ -128,6 +128,69 @@ \xfe\xf9\x5d\xdf\x48\xad\x86\x91\x5a\xed\x0b\x75\x88\xa3\xd5\x51\ \x8c\x56\x47\xff\xe7\xff\x7f\x03\x97\x54\x18\xa6\xd8\x35\x20\x89\ \x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82\ +\x00\x00\x03\xc6\ +\x3c\ +\x3f\x78\x6d\x6c\x20\x76\x65\x72\x73\x69\x6f\x6e\x3d\x22\x31\x2e\ +\x30\x22\x20\x65\x6e\x63\x6f\x64\x69\x6e\x67\x3d\x22\x55\x54\x46\ +\x2d\x38\x22\x20\x73\x74\x61\x6e\x64\x61\x6c\x6f\x6e\x65\x3d\x22\ +\x6e\x6f\x22\x3f\x3e\x0a\x3c\x21\x44\x4f\x43\x54\x59\x50\x45\x20\ +\x73\x76\x67\x20\x50\x55\x42\x4c\x49\x43\x20\x22\x2d\x2f\x2f\x57\ +\x33\x43\x2f\x2f\x44\x54\x44\x20\x53\x56\x47\x20\x31\x2e\x30\x2f\ +\x2f\x45\x4e\x22\x20\x22\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\ +\x2e\x77\x33\x2e\x6f\x72\x67\x2f\x54\x52\x2f\x32\x30\x30\x31\x2f\ +\x50\x52\x2d\x53\x56\x47\x2d\x32\x30\x30\x31\x30\x37\x31\x39\x2f\ +\x44\x54\x44\x2f\x73\x76\x67\x31\x30\x2e\x64\x74\x64\x22\x3e\x0a\ +\x3c\x73\x76\x67\x20\x77\x69\x64\x74\x68\x3d\x22\x31\x33\x63\x6d\ +\x22\x20\x68\x65\x69\x67\x68\x74\x3d\x22\x31\x35\x63\x6d\x22\x20\ +\x76\x69\x65\x77\x42\x6f\x78\x3d\x22\x37\x39\x20\x37\x39\x20\x32\ +\x34\x33\x20\x32\x39\x35\x22\x20\x78\x6d\x6c\x6e\x73\x3d\x22\x68\ +\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x77\x33\x2e\x6f\x72\x67\ +\x2f\x32\x30\x30\x30\x2f\x73\x76\x67\x22\x20\x78\x6d\x6c\x6e\x73\ +\x3a\x78\x6c\x69\x6e\x6b\x3d\x22\x68\x74\x74\x70\x3a\x2f\x2f\x77\ +\x77\x77\x2e\x77\x33\x2e\x6f\x72\x67\x2f\x31\x39\x39\x39\x2f\x78\ +\x6c\x69\x6e\x6b\x22\x3e\x0a\x20\x20\x3c\x65\x6c\x6c\x69\x70\x73\ +\x65\x20\x73\x74\x79\x6c\x65\x3d\x22\x66\x69\x6c\x6c\x3a\x20\x6e\ +\x6f\x6e\x65\x3b\x20\x66\x69\x6c\x6c\x2d\x6f\x70\x61\x63\x69\x74\ +\x79\x3a\x30\x3b\x20\x73\x74\x72\x6f\x6b\x65\x2d\x77\x69\x64\x74\ +\x68\x3a\x20\x38\x3b\x20\x73\x74\x72\x6f\x6b\x65\x3a\x20\x23\x66\ +\x66\x61\x35\x30\x30\x22\x20\x63\x78\x3d\x22\x31\x38\x34\x22\x20\ +\x63\x79\x3d\x22\x32\x31\x38\x22\x20\x72\x78\x3d\x22\x38\x37\x22\ +\x20\x72\x79\x3d\x22\x38\x34\x22\x2f\x3e\x0a\x20\x20\x3c\x65\x6c\ +\x6c\x69\x70\x73\x65\x20\x73\x74\x79\x6c\x65\x3d\x22\x66\x69\x6c\ +\x6c\x3a\x20\x6e\x6f\x6e\x65\x3b\x20\x66\x69\x6c\x6c\x2d\x6f\x70\ +\x61\x63\x69\x74\x79\x3a\x30\x3b\x20\x73\x74\x72\x6f\x6b\x65\x2d\ +\x77\x69\x64\x74\x68\x3a\x20\x38\x3b\x20\x73\x74\x72\x6f\x6b\x65\ +\x3a\x20\x23\x30\x38\x39\x31\x66\x38\x22\x20\x63\x78\x3d\x22\x31\ +\x36\x35\x22\x20\x63\x79\x3d\x22\x32\x33\x33\x22\x20\x72\x78\x3d\ +\x22\x35\x34\x22\x20\x72\x79\x3d\x22\x35\x34\x22\x2f\x3e\x0a\x20\ +\x20\x3c\x65\x6c\x6c\x69\x70\x73\x65\x20\x73\x74\x79\x6c\x65\x3d\ +\x22\x66\x69\x6c\x6c\x3a\x20\x6e\x6f\x6e\x65\x3b\x20\x66\x69\x6c\ +\x6c\x2d\x6f\x70\x61\x63\x69\x74\x79\x3a\x30\x3b\x20\x73\x74\x72\ +\x6f\x6b\x65\x2d\x77\x69\x64\x74\x68\x3a\x20\x38\x3b\x20\x73\x74\ +\x72\x6f\x6b\x65\x3a\x20\x23\x66\x66\x30\x30\x30\x30\x22\x20\x63\ +\x78\x3d\x22\x32\x30\x31\x22\x20\x63\x79\x3d\x22\x32\x30\x31\x22\ +\x20\x72\x78\x3d\x22\x31\x31\x37\x22\x20\x72\x79\x3d\x22\x31\x31\ +\x37\x22\x2f\x3e\x0a\x20\x20\x3c\x65\x6c\x6c\x69\x70\x73\x65\x20\ +\x73\x74\x79\x6c\x65\x3d\x22\x66\x69\x6c\x6c\x3a\x20\x6e\x6f\x6e\ +\x65\x3b\x20\x66\x69\x6c\x6c\x2d\x6f\x70\x61\x63\x69\x74\x79\x3a\ +\x30\x3b\x20\x73\x74\x72\x6f\x6b\x65\x2d\x77\x69\x64\x74\x68\x3a\ +\x20\x38\x3b\x20\x73\x74\x72\x6f\x6b\x65\x3a\x20\x23\x30\x62\x62\ +\x64\x30\x62\x22\x20\x63\x78\x3d\x22\x31\x35\x32\x22\x20\x63\x79\ +\x3d\x22\x32\x34\x35\x22\x20\x72\x78\x3d\x22\x32\x39\x22\x20\x72\ +\x79\x3d\x22\x32\x39\x22\x2f\x3e\x0a\x20\x20\x3c\x74\x65\x78\x74\ +\x20\x66\x6f\x6e\x74\x2d\x73\x69\x7a\x65\x3d\x22\x33\x39\x2e\x34\ +\x39\x39\x38\x22\x20\x73\x74\x79\x6c\x65\x3d\x22\x66\x69\x6c\x6c\ +\x3a\x20\x23\x30\x37\x32\x35\x39\x33\x3b\x74\x65\x78\x74\x2d\x61\ +\x6e\x63\x68\x6f\x72\x3a\x6d\x69\x64\x64\x6c\x65\x3b\x66\x6f\x6e\ +\x74\x2d\x66\x61\x6d\x69\x6c\x79\x3a\x73\x61\x6e\x73\x2d\x73\x65\ +\x72\x69\x66\x3b\x66\x6f\x6e\x74\x2d\x73\x74\x79\x6c\x65\x3a\x6e\ +\x6f\x72\x6d\x61\x6c\x3b\x66\x6f\x6e\x74\x2d\x77\x65\x69\x67\x68\ +\x74\x3a\x37\x30\x30\x22\x20\x78\x3d\x22\x32\x30\x35\x22\x20\x79\ +\x3d\x22\x33\x36\x35\x22\x3e\x0a\x20\x20\x20\x20\x3c\x74\x73\x70\ +\x61\x6e\x20\x78\x3d\x22\x32\x30\x35\x22\x20\x79\x3d\x22\x33\x36\ +\x35\x22\x3e\x4a\x64\x65\x52\x6f\x62\x6f\x74\x3c\x2f\x74\x73\x70\ +\x61\x6e\x3e\x0a\x20\x20\x3c\x2f\x74\x65\x78\x74\x3e\x0a\x3c\x2f\ +\x73\x76\x67\x3e\x0a\ " qt_resource_name = b"\ @@ -139,11 +202,16 @@ \x08\x2f\x5a\x47\ \x00\x62\ \x00\x61\x00\x6c\x00\x6c\x00\x2e\x00\x70\x00\x6e\x00\x67\ +\x00\x0c\ +\x07\x72\xc8\x67\ +\x00\x6a\ +\x00\x64\x00\x65\x00\x72\x00\x6f\x00\x62\x00\x6f\x00\x74\x00\x2e\x00\x73\x00\x76\x00\x67\ " qt_resource_struct = b"\ \x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\ -\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x02\ +\x00\x00\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x02\ +\x00\x00\x00\x28\x00\x00\x00\x00\x00\x01\x00\x00\x07\x51\ \x00\x00\x00\x12\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\ "