[Jderobot-admin] jderobot-r911 - in trunk/src: components components/cameraview_py components/cameraview_py/main interfaces/python/jderobot

ahcorde en jderobot.org ahcorde en jderobot.org
Lun Mayo 6 08:42:15 CEST 2013


Author: ahcorde
Date: 2013-05-06 08:41:15 +0200 (Mon, 06 May 2013)
New Revision: 911

Added:
   trunk/src/components/cameraview_py/
   trunk/src/components/cameraview_py/main/
   trunk/src/components/cameraview_py/main/GUI.py
   trunk/src/components/cameraview_py/main/Sensor.py
   trunk/src/components/cameraview_py/main/ThreadControl.py
   trunk/src/components/cameraview_py/main/ThreadGUI.py
   trunk/src/components/cameraview_py/main/main.py
   trunk/src/interfaces/python/jderobot/README
   trunk/src/interfaces/python/jderobot/camera.ice
   trunk/src/interfaces/python/jderobot/common.ice
   trunk/src/interfaces/python/jderobot/containers.ice
   trunk/src/interfaces/python/jderobot/datetime.ice
   trunk/src/interfaces/python/jderobot/exceptions.ice
   trunk/src/interfaces/python/jderobot/image.ice
Log:
[ahcorde] Interfaces para Python a?\195?\177adidas en su carpeta
	Nuevo cameraview en python tirando de las interfaces python del repositorio


Added: trunk/src/components/cameraview_py/main/GUI.py
===================================================================
--- trunk/src/components/cameraview_py/main/GUI.py	                        (rev 0)
+++ trunk/src/components/cameraview_py/main/GUI.py	2013-05-06 06:41:15 UTC (rev 911)
@@ -0,0 +1,38 @@
+from PyQt4 import QtCore
+from PyQt4 import QtGui
+
+
+class GUI(QtGui.QWidget):
+    def __init__(self, sensor, parent=None):
+
+        self.sensor = sensor
+
+        QtGui.QWidget.__init__(self, parent)
+
+        self.InitUI();
+        
+    def InitUI(self):
+
+        self.labelImage = QtGui.QLabel();
+                            
+        mainLayout = QtGui.QGridLayout()
+        
+        mainLayout.addWidget(self.labelImage, 0, 0);
+
+        self.setLayout(mainLayout)
+        
+        QtCore.QObject.connect(self, QtCore.SIGNAL("aa"), self.update)
+
+        
+        #self.setImage()
+        
+    def updateImage(self):
+        img = self.sensor.getImage()
+        image = QtGui.QImage(img.data, img.shape[1], img.shape[0], img.shape[1]*img.shape[2], QtGui.QImage.Format_RGB888);
+        self.labelImage.setPixmap(QtGui.QPixmap.fromImage(image))
+    
+    def update(self):
+        self.updateImage()
+        
+    def updateGUI_recieved_signal(self):
+        self.emit(QtCore.SIGNAL("aa"), "lol")

Added: trunk/src/components/cameraview_py/main/Sensor.py
===================================================================
--- trunk/src/components/cameraview_py/main/Sensor.py	                        (rev 0)
+++ trunk/src/components/cameraview_py/main/Sensor.py	2013-05-06 06:41:15 UTC (rev 911)
@@ -0,0 +1,43 @@
+import sys, traceback, Ice
+import jderobot 
+import cv2  
+import numpy as np
+import threading  
+
+class Sensor:
+    def __init__(self):
+        try:
+            ic  =     ic = Ice.initialize(sys.argv)
+            base = ic.stringToProxy("cameraA:default -h localhost -p 9999")
+            self.cameraProxy = jderobot.CameraPrx.checkedCast(base)
+            if not self.cameraProxy:
+                raise RuntimeError("Invalid proxy")
+        
+            self.image = self.cameraProxy.getImageData();
+            self.height= self.image.description.height
+            self.width = self.image.description.width
+                
+            self.lock = threading.Lock()  
+
+        except:
+            traceback.print_exc()
+            status = 1
+    def update(self):
+        self.lock.acquire();
+        self.image = self.cameraProxy.getImageData();
+
+        self.lock.release();
+
+        
+    def getImage(self):
+        self.lock.acquire();
+        img = np.zeros((self.height, self.width, 3), np.uint8)
+        img = np.frombuffer(self.image.pixelData, dtype=np.uint8)
+        img.shape = self.height, self.width, 3
+        self.lock.release();
+        """
+        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
+        gray = cv2.Canny(gray, 150, 200)
+        gray = cv2.cvtColor(gray, cv2.COLOR_GRAY2RGB)
+        """
+        return img;

Added: trunk/src/components/cameraview_py/main/ThreadControl.py
===================================================================
--- trunk/src/components/cameraview_py/main/ThreadControl.py	                        (rev 0)
+++ trunk/src/components/cameraview_py/main/ThreadControl.py	2013-05-06 06:41:15 UTC (rev 911)
@@ -0,0 +1,24 @@
+import threading, time
+from datetime import datetime
+import cv2  
+
+time_cycle = 80;
+
+class MiThread(threading.Thread):  
+    def __init__(self, sensor):
+        self.sensor = sensor  
+        threading.Thread.__init__(self)  
+ 
+    def run(self):  
+        while(True):
+            
+            start_time = datetime.now()
+
+            self.sensor.update()
+            
+            finish_Time = datetime.now()
+            
+            dt = finish_Time - start_time
+            ms=(dt.days * 24 * 60 * 60 + dt.seconds) * 1000 + dt.microseconds / 1000.0
+            if(ms < time_cycle):
+                time.sleep((time_cycle-ms) / 1000.0);
\ No newline at end of file

Added: trunk/src/components/cameraview_py/main/ThreadGUI.py
===================================================================
--- trunk/src/components/cameraview_py/main/ThreadGUI.py	                        (rev 0)
+++ trunk/src/components/cameraview_py/main/ThreadGUI.py	2013-05-06 06:41:15 UTC (rev 911)
@@ -0,0 +1,31 @@
+import threading, time
+from datetime import datetime
+
+from PyQt4 import QtGui
+from PyQt4 import QtCore
+
+time_cycle = 50;
+
+class MiThread(threading.Thread):  
+    def __init__(self, gui):
+        self.gui = gui  
+        threading.Thread.__init__(self)  
+ 
+    def run(self):  
+
+        while(True):
+            
+            start_time = datetime.now()
+            
+            self.gui.updateGUI_recieved_signal()
+
+            finish_Time = datetime.now()
+            
+            dt = finish_Time - start_time
+            ms = (dt.days * 24 * 60 * 60 + dt.seconds) * 1000 + dt.microseconds / 1000.0
+            
+            if(ms < time_cycle):
+                time.sleep((time_cycle-ms) / 1000.0);
+                   
+          
+        
\ No newline at end of file

Added: trunk/src/components/cameraview_py/main/main.py
===================================================================
--- trunk/src/components/cameraview_py/main/main.py	                        (rev 0)
+++ trunk/src/components/cameraview_py/main/main.py	2013-05-06 06:41:15 UTC (rev 911)
@@ -0,0 +1,28 @@
+import sys
+sys.path.append("../../../interfaces/python/jderobot")
+import ThreadGUI,ThreadControl
+import Sensor
+import GUI
+from PyQt4 import QtCore
+from PyQt4 import QtGui
+
+
+
+
+
+if __name__ == '__main__': 
+    #main() 
+    sensor = Sensor.Sensor();      
+    app = QtGui.QApplication(sys.argv)
+
+
+    gui = GUI.GUI(sensor)
+  
+    gui.show()
+    
+    t1 = ThreadControl.MiThread(sensor)  
+    t1.start()
+    
+    t2 = ThreadGUI.MiThread(gui)  
+    t2.start()
+    sys.exit(app.exec_())

Added: trunk/src/interfaces/python/jderobot/README
===================================================================
--- trunk/src/interfaces/python/jderobot/README	                        (rev 0)
+++ trunk/src/interfaces/python/jderobot/README	2013-05-06 06:41:15 UTC (rev 911)
@@ -0,0 +1 @@
+slice2py -I. *.ice

Added: trunk/src/interfaces/python/jderobot/camera.ice
===================================================================
--- trunk/src/interfaces/python/jderobot/camera.ice	                        (rev 0)
+++ trunk/src/interfaces/python/jderobot/camera.ice	2013-05-06 06:41:15 UTC (rev 911)
@@ -0,0 +1,68 @@
+/*
+ *
+ *  Copyright (C) 1997-2010 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/. 
+ *
+ *  Author : David Lobato Bravo <dav.lobato en gmail.com>
+ *
+ */
+
+
+#ifndef CAMERA_ICE
+#define CAMERA_ICE
+
+
+#include <image.ice>
+
+module jderobot{
+  /**
+   * Static description of a camera
+   */
+  class CameraDescription
+  {
+    string name;
+    string shortDescription;
+    string streamingUri;
+    float fdistx;
+    float fdisty;
+    float u0;
+    float v0;
+    float skew;
+    float posx;
+    float posy;
+    float posz;
+    float foax;
+    float foay;
+    float foaz;
+    float roll;
+  };
+    
+  /**
+   * Camera interface
+   */
+  interface Camera extends ImageProvider
+  {
+    idempotent CameraDescription getCameraDescription();
+    int setCameraDescription(CameraDescription description);
+    
+    string startCameraStreaming();
+    
+    void stopCameraStreaming();
+    
+  };
+
+}; /*module*/
+
+#endif /*CAMERA_ICE*/

Added: trunk/src/interfaces/python/jderobot/common.ice
===================================================================
--- trunk/src/interfaces/python/jderobot/common.ice	                        (rev 0)
+++ trunk/src/interfaces/python/jderobot/common.ice	2013-05-06 06:41:15 UTC (rev 911)
@@ -0,0 +1,11 @@
+#ifndef COMMON_ICE
+#define COMMON_ICE
+
+#include <datetime.ice>
+#include <exceptions.ice>
+#include <containers.ice>
+
+module jderobot{
+}; /*module*/
+
+#endif /*COMMON_ICE*/

Added: trunk/src/interfaces/python/jderobot/containers.ice
===================================================================
--- trunk/src/interfaces/python/jderobot/containers.ice	                        (rev 0)
+++ trunk/src/interfaces/python/jderobot/containers.ice	2013-05-06 06:41:15 UTC (rev 911)
@@ -0,0 +1,17 @@
+
+#ifndef CONTAINERS_ICE
+#define CONTAINERS_ICE
+
+module jderobot{
+
+  //! A sequence of bytes.
+  sequence<byte> ByteSeq;
+  
+  //! A sequence of ints.
+  sequence<int> IntSeq;
+
+	//! A sequence of floats
+	sequence<float> seqFloat;
+}; /*module*/
+
+#endif /*CONTAINERS_ICE*/

Added: trunk/src/interfaces/python/jderobot/datetime.ice
===================================================================
--- trunk/src/interfaces/python/jderobot/datetime.ice	                        (rev 0)
+++ trunk/src/interfaces/python/jderobot/datetime.ice	2013-05-06 06:41:15 UTC (rev 911)
@@ -0,0 +1,15 @@
+#ifndef DATETIME_ICE
+#define DATETIME_ICE
+
+module jderobot{
+
+  struct Time
+  {
+    //! Number of seconds
+    long seconds;
+    //! Number of microseconds
+    long useconds;
+  };
+}; /*module*/
+
+#endif /*DATETIME_ICE*/

Added: trunk/src/interfaces/python/jderobot/exceptions.ice
===================================================================
--- trunk/src/interfaces/python/jderobot/exceptions.ice	                        (rev 0)
+++ trunk/src/interfaces/python/jderobot/exceptions.ice	2013-05-06 06:41:15 UTC (rev 911)
@@ -0,0 +1,36 @@
+#ifndef EXCEPTIONS_ICE
+#define EXCEPTIONS_ICE
+
+module jderobot{
+
+  exception JderobotException
+  {
+    //! Error description.
+    string what;
+  };
+  
+  //! Server failed to configure itself as requrested by client.
+  exception ConfigurationNotExistException extends JderobotException {};
+
+  /*!
+    Raised when the server does not have the requested data.
+    
+    Typically, this is because the server has not fully initialized yet.
+  */
+  exception DataNotExistException extends JderobotException {};
+  
+  //! Indicates a problem with robot hardware, e.g. sensors and actuators.
+  exception HardwareFailedException extends JderobotException {};
+
+  //! Raised when the server is unable to return a topic for subscription.
+  exception NoTopicException extends JderobotException {};
+
+  //! Raised when the server fails to subscribe client for periodic updates.
+  exception SubscriptionFailedException extends JderobotException {};
+
+  //! Raised when the server fails to push initial data to a new subscriber.
+  exception SubscriptionPushFailedException extends JderobotException {};
+
+}; /*module*/
+
+#endif /*EXCEPTIONS_ICE*/

Added: trunk/src/interfaces/python/jderobot/image.ice
===================================================================
--- trunk/src/interfaces/python/jderobot/image.ice	                        (rev 0)
+++ trunk/src/interfaces/python/jderobot/image.ice	2013-05-06 06:41:15 UTC (rev 911)
@@ -0,0 +1,83 @@
+/*
+ *
+ *  Copyright (C) 1997-2010 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/. 
+ *
+ *  Author : David Lobato Bravo <dav.lobato en gmail.com>
+ *	     Sara Marugán Alonso <smarugan en gsyc.es>
+ *
+ */
+
+#ifndef IMAGE_ICE
+#define IMAGE_ICE
+
+#include <common.ice>
+
+
+module jderobot{  
+
+
+  /**
+   *  Static description of the image source.
+   */
+  class ImageDescription 
+  {
+    int width; /**< %Image width [pixels] */
+    int height;/**< %Image height [pixels] */
+    int size;/**< %Image size [bytes] */
+    string format; /**< %Image format string */
+  };
+  
+
+  /**
+   * A single image served as a sequence of bytes
+   */
+  class ImageData
+  { 
+    Time timeStamp; /**< TimeStamp of Data */
+    ImageDescription description; /**< ImageDescription of Data, for convienence purposes */
+    ByteSeq pixelData; /**< The image data itself. The structure of this byte sequence
+			  depends on the image format and compression. */
+  };
+
+
+  //! Interface to the image consumer.
+  interface ImageConsumer
+  {
+    //! Transmits the data to the consumer.
+    void report( ImageData obj );
+  };
+
+
+  /** 
+   * Interface to the image provider.
+   */
+  interface ImageProvider
+  {
+    /** 
+     * Returns the image source description.
+     */
+    idempotent ImageDescription getImageDescription();
+
+    /**
+     * Returns the latest data.
+     */
+    ["amd"] idempotent ImageData getImageData()
+      throws DataNotExistException, HardwareFailedException;
+  };
+
+}; //module
+
+#endif //IMAGE_ICE



More information about the Jderobot-admin mailing list