[Jderobot-admin] jderobot-r1234 - in trunk/src/stable/components: . basic_component basic_component/control basic_component/gui basic_component_qt basic_component_qt/control basic_component_qt/gui

fperez en jderobot.org fperez en jderobot.org
Jue Mayo 29 12:40:02 CEST 2014


Author: fperez
Date: 2014-05-29 12:40:01 +0200 (Thu, 29 May 2014)
New Revision: 1234

Added:
   trunk/src/stable/components/basic_component/
   trunk/src/stable/components/basic_component/CMakeLists.txt
   trunk/src/stable/components/basic_component/basic_component.cfg
   trunk/src/stable/components/basic_component/basic_component.cpp
   trunk/src/stable/components/basic_component/basic_component.glade
   trunk/src/stable/components/basic_component/control/
   trunk/src/stable/components/basic_component/control/control.cpp
   trunk/src/stable/components/basic_component/control/control.h
   trunk/src/stable/components/basic_component/control/threadcontrol.cpp
   trunk/src/stable/components/basic_component/control/threadcontrol.h
   trunk/src/stable/components/basic_component/gui/
   trunk/src/stable/components/basic_component/gui/gui.cpp
   trunk/src/stable/components/basic_component/gui/gui.h
   trunk/src/stable/components/basic_component/gui/threadgui.cpp
   trunk/src/stable/components/basic_component/gui/threadgui.h
   trunk/src/stable/components/basic_component/shared.cpp
   trunk/src/stable/components/basic_component/shared.h
   trunk/src/stable/components/basic_component_qt/
   trunk/src/stable/components/basic_component_qt/CMakeLists.txt
   trunk/src/stable/components/basic_component_qt/basic_component_qt.cfg
   trunk/src/stable/components/basic_component_qt/basic_component_qt.cpp
   trunk/src/stable/components/basic_component_qt/control/
   trunk/src/stable/components/basic_component_qt/control/control.cpp
   trunk/src/stable/components/basic_component_qt/control/control.h
   trunk/src/stable/components/basic_component_qt/control/threadcontrol.cpp
   trunk/src/stable/components/basic_component_qt/control/threadcontrol.h
   trunk/src/stable/components/basic_component_qt/gui/
   trunk/src/stable/components/basic_component_qt/gui/gui.cpp
   trunk/src/stable/components/basic_component_qt/gui/gui.h
   trunk/src/stable/components/basic_component_qt/gui/threadgui.cpp
   trunk/src/stable/components/basic_component_qt/gui/threadgui.h
   trunk/src/stable/components/basic_component_qt/shared.cpp
   trunk/src/stable/components/basic_component_qt/shared.h
Removed:
   trunk/src/stable/components/basic_component/
   trunk/src/stable/components/basic_component_qt/
Log:
tarea #264 basic component refactoring fixed



Added: trunk/src/stable/components/basic_component/CMakeLists.txt
===================================================================
--- trunk/src/stable/components/basic_component/CMakeLists.txt	                        (rev 0)
+++ trunk/src/stable/components/basic_component/CMakeLists.txt	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,28 @@
+
+SET( SOURCE_FILES  control/control.cpp control/threadcontrol.cpp gui/gui.cpp gui/threadgui.cpp basic_component.cpp shared.cpp)
+
+
+include_directories(
+    ${INTERFACES_CPP_DIR}
+    ${LIBS_DIR}
+    ${CMAKE_CURRENT_SOURCE_DIR}
+    ${gtkmm_INCLUDE_DIRS}
+    ${libglademm_INCLUDE_DIRS}
+)
+
+add_executable (basic_component  ${SOURCE_FILES})
+
+TARGET_LINK_LIBRARIES(basic_component 
+    ${CMAKE_THREAD_LIBS_INIT}
+    JderobotInterfaces
+    jderobotutil
+    colorspacesmm
+    ${libglademm_LIBRARIES}
+    ${OpenCV_LIBRARIES}       
+    ${OpenCVGUI_LIBRARIES} 
+	${ZeroCIce_LIBRARIES}    
+	${gtkmm_LIBRARIES}  
+	${gtkmm3_LIBRARIES}  	
+	${gthread_LIBRARIES}
+)
+

Added: trunk/src/stable/components/basic_component/basic_component.cfg
===================================================================
--- trunk/src/stable/components/basic_component/basic_component.cfg	                        (rev 0)
+++ trunk/src/stable/components/basic_component/basic_component.cfg	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,6 @@
+basic_component.Camera1.Proxy=cameraA:tcp -h localhost -p 9999
+basic_component.Camera2.Proxy=cameraB:tcp -h localhost -p 9992
+
+#delete this line or set OFF as value to disable the gui
+basic_component.Gui=ON
+

Added: trunk/src/stable/components/basic_component/basic_component.cpp
===================================================================
--- trunk/src/stable/components/basic_component/basic_component.cpp	                        (rev 0)
+++ trunk/src/stable/components/basic_component/basic_component.cpp	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,74 @@
+//ICE
+#include <Ice/Ice.h>
+#include <IceUtil/IceUtil.h>
+#include <pthread.h>
+
+#include "gui/threadgui.h"
+#include "gui/gui.h"
+#include "control/control.h"
+#include "control/threadcontrol.h"
+
+// Global members
+
+basic_component::ThreadControl* threadControl;
+basic_component::ThreadGui* threadGui;
+
+//Launching the control "thread"
+void controlStart() {
+
+    threadControl->start();
+}
+
+//Launching the gui thred
+void* guiThread(void*) {
+
+    threadGui->start();
+}
+
+int main(int argc, char* argv[]) {
+
+    try{
+
+	//We initialize Ice here to be able to add some other options to the configuration file such as
+        //the posibility to show or not show the GUI.
+        Ice::CommunicatorPtr ic = Ice::initialize(argc, argv);
+        
+        //Shared memory object
+        basic_component::Shared* sm = new basic_component::Shared();
+	
+        //Creates the control&processing thread manager
+        threadControl = new basic_component::ThreadControl(ic, sm);
+
+	Ice::PropertiesPtr prop = ic->getProperties();
+
+	//Let's check if the user want to show the gui or not. This setting must be in the .cfg file
+	std::string gui = prop->getPropertyWithDefault("basic_component.Gui", "miss");
+    	if (!boost::iequals(gui , "miss") && !boost::iequals(gui, "OFF")) {
+		
+		pthread_t t_gui;
+
+		//Creates the gui thread manager
+		threadGui = new basic_component::ThreadGui(sm);
+
+		//Creates the thread for the control&processing
+		pthread_create(&t_gui, NULL, &guiThread, NULL);	
+	
+	}else 
+		std::cout << "No Gui mode" << std::endl;
+
+	//We use the main thread to manage the control&processing thread, so the gui has it's own thread that is
+	//periodically updated.
+	controlStart();
+		
+	
+	
+    } catch (const Ice::Exception& ex) {
+        std::cerr << ex << std::endl;
+        exit(-1);
+    } catch (const char* msg) {
+        std::cerr << msg << std::endl;
+        exit(-1);
+    }
+    return 0;
+
+}

Added: trunk/src/stable/components/basic_component/basic_component.glade
===================================================================
--- trunk/src/stable/components/basic_component/basic_component.glade	                        (rev 0)
+++ trunk/src/stable/components/basic_component/basic_component.glade	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<glade-interface>
+  <!-- interface-requires gtk+ 2.6 -->
+  <!-- interface-naming-policy toplevel-contextual -->
+  <widget class="GtkWindow" id="secondarywindow">
+    <property name="title" translatable="yes">TELEOPERATE CAMERAS</property>
+    <child>
+      <widget class="GtkFixed" id="fixed1">
+        <property name="visible">True</property>
+        <child>
+          <widget class="GtkEventBox" id="eventbox_left">
+            <property name="width_request">320</property>
+            <property name="height_request">240</property>
+            <property name="visible">True</property>
+            <child>
+              <widget class="GtkImage" id="image1">
+                <property name="width_request">320</property>
+                <property name="height_request">240</property>
+                <property name="visible">True</property>
+                <property name="stock">gtk-missing-image</property>
+              </widget>
+            </child>
+          </widget>
+          <packing>
+            <property name="x">1</property>
+            <property name="y">1</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+  </widget>
+</glade-interface>


Property changes on: trunk/src/stable/components/basic_component/basic_component.glade
___________________________________________________________________
Added: svn:executable
   + *

Added: trunk/src/stable/components/basic_component/control/control.cpp
===================================================================
--- trunk/src/stable/components/basic_component/control/control.cpp	                        (rev 0)
+++ trunk/src/stable/components/basic_component/control/control.cpp	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,62 @@
+#include "control.h"
+
+
+namespace basic_component {
+
+bool cameraOn = false;
+bool laserOn = false;
+bool motorsOn = false;
+bool encodersOn = false;
+
+Control::Control(Ice::CommunicatorPtr ic, Shared* sm)
+{
+    /*Obtaining the configuration file (*.cfg) properties such as ports and IP's*/
+    this->ic = ic;
+    this->sm = sm;
+
+    Ice::PropertiesPtr prop = ic->getProperties();
+
+    /*Checking if the property has value and the creation of the proxy is possible. If the property is not set or has no value
+       it will be set as "miss" and then we will know that we cannot create a proxy with the camera (or other sensors/actuators)*/
+    std::string cam = prop->getPropertyWithDefault("basic_component.Camera1.Proxy", "miss");
+    if (!boost::iequals(cam , "miss"))
+    {
+
+	/*Creation of a proxy to connect with cameraServer*/
+	Ice::ObjectPrx base = ic->propertyToProxy("basic_component.Camera1.Proxy");
+	if (0==base)
+		throw "Could not create proxy";
+	/*cast to CameraPrx*/
+	this->cprx = jderobot::CameraPrx::checkedCast(base);
+	if (0==cprx)
+		throw "Invalid proxy";
+
+	cameraOn = true;
+
+	/*Get the image data from the camera proxy*/
+	jderobot::ImageDataPtr data = cprx->getImageData();
+
+	/*Create the first image obtained from the camera and stores in the shared memory*/
+	this->sm->createImage(data);
+	
+    }
+    else
+    {
+	cameraOn = false; 
+	/*Create an empty image if there is no camera connected*/
+	this->sm->createEmptyImage();
+	std::cout << "No camera connected" << std::endl;
+    }
+}
+
+void Control::update()
+{
+    if(cameraOn) 
+    {
+   	//Get de data from the camera and stores de image in the shared memory periodically (see threadcontrol)
+	jderobot::ImageDataPtr data = cprx->getImageData();
+	this->sm->updateImage(data);
+    }
+}
+
+}

Added: trunk/src/stable/components/basic_component/control/control.h
===================================================================
--- trunk/src/stable/components/basic_component/control/control.h	                        (rev 0)
+++ trunk/src/stable/components/basic_component/control/control.h	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,38 @@
+#ifndef SENSORS_H
+#define SENSORS_H
+
+//ICE
+#include <Ice/Ice.h>
+#include <IceUtil/IceUtil.h>
+
+#include "../shared.h"
+
+//INTERFACES
+#include <jderobot/camera.h>
+
+//Opencv
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
+
+#include <boost/algorithm/string.hpp>
+
+namespace basic_component {
+
+class Control
+{
+public:
+
+    Control(Ice::CommunicatorPtr ic, basic_component::Shared* sm);	//constructor
+    void update();					
+
+private:
+
+    Shared* sm;	//Shared memory
+
+    Ice::CommunicatorPtr ic;
+    jderobot::CameraPrx cprx;
+};
+}
+
+#endif // SENSORS_H

Added: trunk/src/stable/components/basic_component/control/threadcontrol.cpp
===================================================================
--- trunk/src/stable/components/basic_component/control/threadcontrol.cpp	                        (rev 0)
+++ trunk/src/stable/components/basic_component/control/threadcontrol.cpp	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,42 @@
+#include "threadcontrol.h"
+
+namespace basic_component {
+
+ThreadControl::ThreadControl(Ice::CommunicatorPtr ic, Shared* sm)
+{
+    //Creates the control object
+    this->control = new Control(ic, sm);
+}
+
+void ThreadControl::start()
+{
+    //Calculates the refreshing time of the control class
+    struct timeval a, b;
+    long totalb, totala;
+    long diff;
+
+    while (true) {
+        gettimeofday(&a, NULL);
+        totala = a.tv_sec * 1000000 + a.tv_usec;
+
+        //update the sensors (in this case the image taken from the camera)
+        this->control->update();
+
+        gettimeofday(&b, NULL);
+        totalb = b.tv_sec * 1000000 + b.tv_usec;
+        diff = (totalb - totala) / 1000;
+
+        if (diff < 0 || diff > cycle_control)
+            diff = cycle_control;
+        else
+            diff = cycle_control - diff;
+
+
+        /*Sleep Algorithm*/
+        usleep(diff * 1000);
+        if (diff < 33)
+            usleep(33 * 1000);
+    }
+}
+
+}

Added: trunk/src/stable/components/basic_component/control/threadcontrol.h
===================================================================
--- trunk/src/stable/components/basic_component/control/threadcontrol.h	                        (rev 0)
+++ trunk/src/stable/components/basic_component/control/threadcontrol.h	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,24 @@
+#ifndef THREADSENSORS_H
+#define THREADSENSORS_H
+
+#include <iostream>
+#include <sys/time.h>
+
+#include "control.h"
+#include "../shared.h"
+
+#define cycle_control 20 //miliseconds
+
+namespace basic_component {
+class ThreadControl
+{
+public:
+    ThreadControl(Ice::CommunicatorPtr ic, Shared* sm);
+    void start();
+
+private:
+    Control* control;
+};
+}
+
+#endif // THREADSENSORS_H

Added: trunk/src/stable/components/basic_component/gui/gui.cpp
===================================================================
--- trunk/src/stable/components/basic_component/gui/gui.cpp	                        (rev 0)
+++ trunk/src/stable/components/basic_component/gui/gui.cpp	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,83 @@
+/*
+ *  Copyright (C) 1997-2011 JDERobot 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 2 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 Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *  Authors : Maikel González <m.gonzalezbai en gmail.com>
+ *            Francisco Pérez <f.perez475 en gmail.com>
+ *
+ */
+
+#include "gui.h"
+
+namespace basic_component {
+
+    Gui::Gui(Shared* sm) : gtkmain(0, 0) {
+
+        this->sm = sm;
+
+        std::cout << "Loading glade\n";
+
+        refXml = Gnome::Glade::Xml::create("./basic_component.glade");
+        //Get widgets       
+        refXml->get_widget("secondarywindow", secondarywindow);
+        // Camera images
+        refXml->get_widget("image1", gtk_image1);
+
+        secondarywindow->show();
+    }
+
+    Gui::~Gui() {
+
+    }
+
+    void Gui::ShowImage() {
+	this->image = this->sm->getImage();
+        setCamara(this->image, 1);
+    }
+
+    void Gui::display() {
+
+        ShowImage();
+        while (gtkmain.events_pending())
+            gtkmain.iteration();
+
+    }
+
+    // First parameter is the widget which will show the image and the id indicates which widget is. This is useful when we have
+    // two cameras and we want to choose which one will offer us the image.
+    void Gui::setCamara(const cv::Mat image, int id) {
+
+        // Set image
+        Glib::RefPtr<Gdk::Pixbuf> imgBuff = Gdk::Pixbuf::create_from_data((const guint8*) image.data,
+                Gdk::COLORSPACE_RGB,
+                false,
+                8,
+                image.cols,
+                image.rows,
+                image.step);
+
+        if (id == 1) {
+            gtk_image1->clear();
+            gtk_image1->set(imgBuff);
+        } else {
+            gtk_image2->clear();
+            gtk_image2->set(imgBuff);
+        }
+
+    }
+
+} // namespace    
+

Added: trunk/src/stable/components/basic_component/gui/gui.h
===================================================================
--- trunk/src/stable/components/basic_component/gui/gui.h	                        (rev 0)
+++ trunk/src/stable/components/basic_component/gui/gui.h	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,76 @@
+/*
+ *  Copyright (C) 1997-2011 JDERobot 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 2 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 Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *  Authors : Maikel González <m.gonzalezbai en gmail.com>
+ *            Francisco Pérez <f.perez475 en gmail.com>
+ *
+ */
+
+#ifndef BASIC_COMPONENT_GUI_H
+#define BASIC_COMPONENT_GUI_H
+
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
+#include <gtk-2.0/gtk/gtk.h>
+#include <gtk-2.0/gdk/gdk.h>
+#include <gtkmm-2.4/gtkmm.h>
+#include <gtkmm/drawingarea.h>
+#include <gdkmm/pixbuf.h>
+#include <libglademm.h>
+#include <math.h>
+#include <string>
+#include <iostream>
+#include <sstream>
+#include "../shared.h"
+
+
+
+namespace basic_component {
+
+    class Gui {
+    public:
+
+        Gui(Shared* sm);
+        virtual ~Gui();
+
+        void display();
+
+        cv::Mat image; // Image camera1 processed to manipulate with openCV
+
+    private:
+        Gtk::Main gtkmain;
+        Glib::RefPtr<Gnome::Glade::Xml> refXml;
+        std::string gladepath;
+
+        // Windows
+        Gtk::Window *secondarywindow;
+
+        // Cameras
+        Gtk::Image *gtk_image1;
+	Gtk::Image *gtk_image2;
+
+        // Private Methods
+        void setCamara(const cv::Mat image, int id);
+	void ShowImage();
+
+	Shared* sm;
+
+
+    }; //class
+}//namespace
+#endif //BASIC_COMPONENT_GUI_H

Added: trunk/src/stable/components/basic_component/gui/threadgui.cpp
===================================================================
--- trunk/src/stable/components/basic_component/gui/threadgui.cpp	                        (rev 0)
+++ trunk/src/stable/components/basic_component/gui/threadgui.cpp	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,43 @@
+#include "threadgui.h"
+
+namespace basic_component {
+ThreadGui::ThreadGui(Shared* sm)
+{
+    //New instace of Gui with the shared memory object.
+    gui = new Gui(sm);
+    gui->display();
+
+}
+
+void ThreadGui::start()
+{
+    //Calculates the refreshing time of the gui.
+    struct timeval a, b;
+    long totalb, totala;
+    long diff;
+
+    while (true) {
+        gettimeofday(&a, NULL);
+        totala = a.tv_sec * 1000000 + a.tv_usec;
+
+        //updates the gui (image shown in this component)
+        gui->display();
+
+        gettimeofday(&b, NULL);
+        totalb = b.tv_sec * 1000000 + b.tv_usec;
+        diff = (totalb - totala) / 1000;
+
+        if (diff < 0 || diff > cycle_gui)
+            diff = cycle_gui;
+        else
+            diff = cycle_gui - diff;
+
+
+        /*Sleep Algorithm*/
+        usleep(diff * 1000);
+        if (diff < 33)
+            usleep(33 * 1000);
+    }
+}
+
+}

Added: trunk/src/stable/components/basic_component/gui/threadgui.h
===================================================================
--- trunk/src/stable/components/basic_component/gui/threadgui.h	                        (rev 0)
+++ trunk/src/stable/components/basic_component/gui/threadgui.h	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,24 @@
+#ifndef THREADGUI_H
+#define THREADGUI_H
+
+#include <iostream>
+#include <sys/time.h>
+
+#include "gui.h"
+
+#include "../shared.h"
+
+#define cycle_gui 50 //miliseconds
+
+namespace basic_component {
+class ThreadGui
+{
+public:
+    ThreadGui(Shared* sm);
+    void start();
+
+private:
+    Gui* gui;
+};
+}
+#endif // THREADGUI_H

Added: trunk/src/stable/components/basic_component/shared.cpp
===================================================================
--- trunk/src/stable/components/basic_component/shared.cpp	                        (rev 0)
+++ trunk/src/stable/components/basic_component/shared.cpp	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,246 @@
+/*
+ *  Copyright (C) 1997-2011 JDERobot 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 2 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 Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *  Authors : Maikel González <m.gonzalezbai en gmail.com>,
+ *            Francisco Pérez <f.perez475 en gmail.com>
+ *
+ */
+
+#include "shared.h"
+
+#define w 400
+
+//Shared memory class storage of shared resources of the component
+
+namespace basic_component{
+
+   Shared::Shared() {
+	pthread_mutex_t controlGui = PTHREAD_MUTEX_INITIALIZER;
+   }
+
+   //GETTERS
+   double Shared::getMotorV(){
+      return this->motorVin;
+   }
+   
+   double Shared::getMotorW(){
+      return this->motorWin;      
+   }
+   
+   double Shared::getMotorL(){
+      return this->motorLin;
+   }
+   
+   jderobot::LaserDataPtr Shared::getLaserData(){
+      return this->laserData;
+   }
+   
+   int Shared::getNumLasers(){
+      return this->laserData->numLaser;
+   }
+   
+   jderobot::IntSeq Shared::getDistancesLaser(){
+      return this->laserData->distanceData;
+   }
+   
+   jderobot::EncodersDataPtr Shared::getEncodersData(){
+      return this->encodersData;
+   }
+   
+   cv::Mat Shared::getImageCamera1(){
+      pthread_mutex_lock(&this->controlGui);
+        cv::Mat result = image1.clone();
+	pthread_mutex_unlock(&this->controlGui);
+        return result;
+   }
+   cv::Mat Shared::getImageCamera2(){
+      pthread_mutex_lock(&this->controlGui);
+        cv::Mat result = image2.clone();
+	pthread_mutex_unlock(&this->controlGui);
+        return result;
+   }
+   
+
+   //SETTERS
+   void Shared::setMotorV(float motorV){
+      this->motorVout=motorV;
+   }
+   void Shared::setMotorW(float motorW){
+      this->motorWout=motorW;
+   }
+   
+   void Shared::setMotorL(float motorL){
+      this->motorLout=motorL;
+      
+   }
+    
+
+/*
+    void Shared::setImageData(jderobot::ImageDataPtr imageData) {
+        pthread_mutex_lock(&this->controlGui);
+        this->imageData1 = imageData;
+        pthread_mutex_unlock(&this->controlGui);
+    }
+
+   void Shared::setPTEncoders(jderobot::PTEncodersDataPtr PTencodersData, int cameraId){
+      if(cameraId==1)
+         this->PTencodersData1=PTencodersData;
+      else
+         this->PTecondersData2=PTencodersData;
+   }
+   */
+
+    //IMAGES MANAGEMENT (only for one camera, for others do the same with image2)
+
+    void Shared::createImage(jderobot::ImageDataPtr data) {
+	pthread_mutex_lock(&this->controlGui);
+        image1.create(data->description->height, data->description->width, CV_8UC3);
+	pthread_mutex_unlock(&this->controlGui);
+    }
+
+    void Shared::createEmptyImage() {
+	pthread_mutex_lock(&this->controlGui);
+	image1.create(w, w, CV_8UC3);
+	pthread_mutex_unlock(&this->controlGui);
+    }
+    
+    void Shared::updateImage(jderobot::ImageDataPtr data){
+	pthread_mutex_lock(&this->controlGui);
+        memcpy((unsigned char *) image1.data ,&(data->pixelData[0]), image1.cols*image1.rows * 3);
+	pthread_mutex_unlock(&this->controlGui);
+    }
+    
+    cv::Mat Shared::getImage() {
+	pthread_mutex_lock(&this->controlGui);
+        cv::Mat result = image1.clone();
+	pthread_mutex_unlock(&this->controlGui);
+        return result;
+    }
+
+
+
+/*********************** OBSOLETO *****************************************    
+    colorspaces::Image* Shared::getImage() {
+        
+        pthread_mutex_lock(&this->controlGui);
+        colorspaces::Image::FormatPtr fmt1 = colorspaces::Image::Format::searchFormat(imageData1->description->format);
+        if (!fmt1)
+            throw "Format not supported";
+        image1 = new colorspaces::Image (imageData1->description->width, imageData1->description->height, fmt1, &(imageData1->pixelData[0])); // Prepare the image to use with openCV
+        pthread_mutex_unlock(&this->controlGui); 
+     
+     
+        return image1;
+    }
+
+    colorspaces::Image*  void Shared::createImage(jderobot::ImageDataPtr data) {
+        
+        pthread_mutex_lock(&this->controlGui);
+        colorspaces::Image::FormatPtr fmt1 = colorspaces::Image::Format::searchFormat(data->description->format);
+        if (!fmt1)
+            throw "Format not supported";
+        image1 = new colorspaces::Image (data->description->width, data->description->height, fmt1, &(data->pixelData[0])); // Prepare the image to use with openCV
+        pthread_mutex_unlock(&this->controlGui);
+        
+        return image1;
+    }
+
+   void Shared::imageCameras2openCV(){
+  
+       	pthread_mutex_lock(&this->controlGui);
+
+	//First camera
+      	colorspaces::Image::FormatPtr fmt1 = colorspaces::Image::Format::searchFormat(imageData1->description->format);
+     	if (!fmt1)
+        	throw "Format not supported";
+       	image1 = new colorspaces::Image (imageData1->description->width, imageData1->description->height, fmt1, &(imageData1->pixelData[0])); // Prepare the image to use with openCV
+
+	//Second camera
+      	colorspaces::Image::FormatPtr fmt2 = colorspaces::Image::Format::searchFormat( imageData2->description->format);
+      	if (!fmt2)
+        	throw "Format not supported";
+       	image2 = new colorspaces::Image ( imageData2->description->width,  imageData2->description->height, fmt2, &( imageData2->pixelData[0])); // Prepare the image to use with openCV
+
+       	pthread_mutex_unlock(&this->controlGui);
+   }
+********************************** FIN OBSOLETO*************************/
+
+
+    void Shared::RunNavigationAlgorithm(){
+      
+/*
+      float v, w, l;
+      jderobot::LaserDataPtr laser;
+      
+      imageCameras2openCV();
+      imageCamera1=getImageCamera1();
+      imageCamera2=getImageCamera2();
+      laser=getLaserData(); // Get the laser info
+      printf("laser[45]: %d\n", laser->distanceData[45]);
+      switch(accion){
+
+      	case 0:		// Robot hacia adelante              
+        	if(( laser->distanceData[45] < 1000.0) or ( laser->distanceData[90] < 1000.0) or ( laser->distanceData[135] < 1000.0)){
+                	setMotorV(0.);
+                        //if ((x_ant == myPoint.x) and (y_ant == myPoint.y) and (z_ant == myPoint.z)){
+                        	accion=1;
+                        	printf("### Activado hacia Atras\n");
+                        //}
+		}
+                else
+	        	setMotorV(100);
+                      	break;
+
+	case 1:		// Robot hacia atras
+	        if ((laser->distanceData[45] < 1100) or (laser->distanceData[90] < 1100) or (laser->distanceData[135] < 1100)){
+	                setMotorV(-50.);
+                        printf("### Llendo hacia atras\n");
+		}
+                else{
+	                setMotorV(0.);
+                        accion=2;
+                }
+                break;
+
+
+	case 2:		// Robot girando.
+	        if((laser->distanceData[45] < 1300) or (laser->distanceData[90] < 1300) or (laser->distanceData[135] < 1300)){
+	                if(sentido%2==0){
+	                        setMotorW(50.);
+                        }
+                        else{
+	                        setMotorW(50.*(-1));
+                        }
+                        printf("### Girando: %d \n", sentido);
+		}
+                else{
+	                setMotorW(0.);
+                        accion=0;
+                        sentido = (1 + rand() % 40);
+                }			
+                break;
+	}
+   
+        
+*/  
+    }
+
+
+Shared::~Shared() {}   
+
+}
+

Added: trunk/src/stable/components/basic_component/shared.h
===================================================================
--- trunk/src/stable/components/basic_component/shared.h	                        (rev 0)
+++ trunk/src/stable/components/basic_component/shared.h	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,116 @@
+/*
+ *  Copyright (C) 1997-2011 JDERobot 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 2 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 Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *  Authors : Maikel González <m.gonzalezbai en gmail.com>,
+ *            Francisco Pérez <f.perez475 en gmail.com>
+ *
+ */
+
+
+#ifndef BASIC_COMPONENT_SHARED_H
+#define BASIC_COMPONENT_SHARED_H
+
+
+#include <iostream>
+#include <pthread.h>
+#include <Ice/Ice.h>
+#include <IceUtil/IceUtil.h>
+#include <jderobot/camera.h>
+#include <jderobot/motors.h>
+#include <jderobot/ptmotors.h>
+#include <jderobot/laser.h>
+#include <jderobot/encoders.h>
+#include <jderobot/ptencoders.h>
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
+
+
+
+namespace basic_component {
+    class Shared {
+	public:
+	virtual ~Shared();
+	
+	    pthread_mutex_t controlGui;	
+	
+	
+	Shared();
+	    //FUNCTIONS 
+	    void RunNavigationAlgorithm();
+
+	    // GETS	    
+	    double getMotorV();
+	    double getMotorW();
+	    double getMotorL();
+	    jderobot::LaserDataPtr getLaserData();
+	    int getNumLasers();
+	    jderobot::IntSeq getDistancesLaser();
+	    jderobot::EncodersDataPtr getEncodersData();
+	    cv::Mat getImageCamera1();
+	    cv::Mat getImageCamera2();
+
+	    //SETS
+	    void setMotorV(float motorV);
+	    void setMotorW(float motorW);
+	    void setMotorL(float motorL);
+//            void setImageData(jderobot::ImageDataPtr imageData);
+	    void setPTEncoders(jderobot::PTEncodersDataPtr* PTencodersData, int cameraId);
+
+            void createImage(jderobot::ImageDataPtr data);
+	    void createEmptyImage();
+	    void updateImage(jderobot::ImageDataPtr data);
+	    cv::Mat getImage();
+        
+	    /*Shared Memory -- ignored by students*/
+	    double motorVout;
+	    double motorWout;
+	    double motorLout;
+	    double motorVin;
+	    double motorWin;
+	    double motorLin;
+	    double v_normalized; // Used to teleoperate cameras (latitude)
+	    double w_normalized; // Used to teleoperate cameras (longitude)
+	    jderobot::EncodersDataPtr encodersData;
+	    jderobot::LaserDataPtr laserData;
+	    jderobot::ImageDataPtr imageData1; // Contains the image info
+	    jderobot::ImageDataPtr imageData2; // Contains the image info
+	    jderobot::PTEncodersDataPtr PTencodersData1;
+	    jderobot::PTEncodersDataPtr PTecondersData2;
+            jderobot::PTMotorsData* PTmotorsData1;
+            jderobot::PTMotorsData* PTmotorsData2;
+	    cv::Mat image1;	// Image camera1 processed to manipulate with openCV
+	    cv::Mat image2; // Image camera2 processed to manipulate with openCV
+	    bool guiVisible;
+	    bool iterationControlActivated;
+	    //Variables used in NavigationAlgorithm
+	    int sentido; 
+	    int accion;
+	    
+	private:
+	    //Variables used in NavigationAlgorithm
+	    cv::Mat imageCamera1;
+	    cv::Mat imageCamera2;
+	    
+	    //Functions used in NavigationAlgorithm
+   	    void imageCameras2openCV();	    
+
+	    
+     
+    };//class
+} // namespace
+#endif /*BASIC_COMPONENT_Control_H*/

Added: trunk/src/stable/components/basic_component_qt/CMakeLists.txt
===================================================================
--- trunk/src/stable/components/basic_component_qt/CMakeLists.txt	                        (rev 0)
+++ trunk/src/stable/components/basic_component_qt/CMakeLists.txt	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,36 @@
+if (${QT_COMPILE})
+
+
+    SET(qt_SOURCES basic_component_qt.cpp gui/gui.cpp)
+
+    SET(qt_HEADERS gui/gui.h)
+
+    include_directories(
+        ${INTERFACES_CPP_DIR}
+        ${LIBS_DIR}/
+        ${CMAKE_CURRENT_SOURCE_DIR}
+    )
+
+    QT4_WRAP_CPP(qt_HEADERS_MOC ${qt_HEADERS})
+
+
+    add_executable( basic_component_qt
+                    basic_component_qt.cpp 
+	            control/threadcontrol.cpp 
+		    control/control.cpp
+		    gui/threadgui.cpp 
+		    gui/gui.cpp 
+		    shared.cpp
+		    ${qt_HEADERS_MOC}
+    )
+			       
+    target_link_libraries(basic_component_qt 
+        ${CMAKE_THREAD_LIBS_INIT}
+        ${OpenCV_LIBRARIES}
+        ${QT_LIBRARIES_JDE}
+        JderobotInterfaces
+        jderobotutil
+        ${ZeroCIce_LIBRARIES}
+    )
+ENDIF()
+

Added: trunk/src/stable/components/basic_component_qt/basic_component_qt.cfg
===================================================================
--- trunk/src/stable/components/basic_component_qt/basic_component_qt.cfg	                        (rev 0)
+++ trunk/src/stable/components/basic_component_qt/basic_component_qt.cfg	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,6 @@
+basic_component_qt.Camera1.Proxy=cameraA:default -h localhost -p 9999
+
+#delete this line or set OFF as value to disable the gui
+basic_component_qt.Gui=ON
+
+

Added: trunk/src/stable/components/basic_component_qt/basic_component_qt.cpp
===================================================================
--- trunk/src/stable/components/basic_component_qt/basic_component_qt.cpp	                        (rev 0)
+++ trunk/src/stable/components/basic_component_qt/basic_component_qt.cpp	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,85 @@
+//Qt
+#include <QtGui>
+
+//ICE
+#include <Ice/Ice.h>
+#include <IceUtil/IceUtil.h>
+
+#include <pthread.h>
+#include "gui/threadgui.h"
+#include "gui/gui.h"
+#include "control/control.h"
+#include "control/threadcontrol.h"
+#include "shared.h"
+
+basic_component_qt::ThreadControl* threadControl;
+basic_component_qt::ThreadGui* threadGui;
+
+//Launching the control thread
+void* controlThread(void*) {
+
+    threadControl->start();
+}
+
+//Launching the gui thred
+void* guiThread(void *) {
+
+    threadGui->start();
+}
+
+int main(int argc, char* argv[])
+{
+    QApplication a(argc, argv);
+    int ret;
+
+    try{
+
+
+        //We initialize Ice here to be able to add some other options to the configuration file such as
+        //the posibility to show or not show the GUI.
+        Ice::CommunicatorPtr ic = Ice::initialize(argc, argv);
+        
+        //Shared memory object
+        basic_component_qt::Shared* sm = new basic_component_qt::Shared();
+
+        //Creates the control&processing thread manager
+        threadControl = new basic_component_qt::ThreadControl(ic, sm);
+
+	Ice::PropertiesPtr prop = ic->getProperties();
+
+	//Checking if the user want to show the gui or not. This setting is included in the .cfg file
+	std::string gui = prop->getPropertyWithDefault("basic_component_qt.Gui", "miss");
+    	if (!boost::iequals(gui , "miss") && !boost::iequals(gui, "OFF")) {
+		
+		pthread_t t_control;
+		pthread_t t_gui;
+		
+		//Creates the gui thread manager
+		threadGui = new basic_component_qt::ThreadGui(sm);
+
+		//Creates the threads for gui and control&processing
+		pthread_create(&t_control, NULL, &controlThread, NULL);
+        	pthread_create(&t_gui, NULL, &guiThread, NULL);	
+
+		//Starting Qt mainloop
+		ret = a.exec();
+	
+	}else {
+		//If there is no gui, it's not necessary to create a thread because the main thread can do the job
+		std::cout << "No Gui mode" << std::endl;
+		controlThread(NULL);	
+		ret = 0;
+	}
+
+	
+    } catch (const Ice::Exception& ex) {
+        std::cerr << ex << std::endl;
+        exit(-1);
+    } catch (const char* msg) {
+        std::cerr << msg << std::endl;
+        exit(-1);
+    }
+
+    return ret;
+
+}

Added: trunk/src/stable/components/basic_component_qt/control/control.cpp
===================================================================
--- trunk/src/stable/components/basic_component_qt/control/control.cpp	                        (rev 0)
+++ trunk/src/stable/components/basic_component_qt/control/control.cpp	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,58 @@
+#include "control.h"
+
+namespace basic_component_qt {
+
+bool cameraOn = false;
+bool laserOn = false;
+bool motorsOn = false;
+bool encodersOn = false;
+
+Control::Control(Ice::CommunicatorPtr ic, Shared* sm)
+{
+    /*Obtaining the configuration file (*.cfg) properties such as ports and IP's*/
+    this->ic = ic;
+    this->sm = sm;
+
+    Ice::PropertiesPtr prop = ic->getProperties();
+
+    std::string cam = prop->getPropertyWithDefault("basic_component_qt.Camera1.Proxy", "miss");
+    if (!boost::iequals(cam , "miss"))
+    {
+    	/*Creation of a proxy to connect with cameraServer*/
+   	Ice::ObjectPrx base = ic->propertyToProxy("basic_component_qt.Camera1.Proxy");
+    	if (0==base)
+      		throw "Could not create proxy";
+
+	/*cast to CameraPrx*/
+    	cprx = jderobot::CameraPrx::checkedCast(base);
+    	if (0==cprx)
+      		throw "Invalid proxy";
+
+	cameraOn = true;
+
+    	/*Get the image data from the camera proxy*/
+    	jderobot::ImageDataPtr data = cprx->getImageData();
+    	/*Create the first image obtained from the camera and stores in the shared memory*/
+    	this->sm->createImage(data);
+    }
+    else
+    {
+	cameraOn = false; 
+	/*Create an empty image if there is no camera connected*/
+	this->sm->createEmptyImage();
+	std::cout << "No camera connected" << std::endl;
+    }
+
+
+}
+
+void Control::update()
+{
+    if(cameraOn) 
+    {
+   	//Get de data from the camera and stores de image in the shared memory periodically (see threadcontrol)
+	jderobot::ImageDataPtr data = cprx->getImageData();
+	this->sm->updateImage(data);
+    }
+}
+}

Added: trunk/src/stable/components/basic_component_qt/control/control.h
===================================================================
--- trunk/src/stable/components/basic_component_qt/control/control.h	                        (rev 0)
+++ trunk/src/stable/components/basic_component_qt/control/control.h	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,40 @@
+#ifndef CONTROL_H
+#define CONTROL_H
+
+//Qt
+
+
+//ICE
+#include <Ice/Ice.h>
+#include <IceUtil/IceUtil.h>
+
+//INTERFACES
+#include <jderobot/camera.h>
+
+//Opencv
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
+
+#include <boost/algorithm/string.hpp>
+#include "../shared.h"
+
+namespace basic_component_qt {
+
+class Control
+{
+public:
+
+    Control(Ice::CommunicatorPtr ic, Shared* sm);	//constructor
+    void update();					
+
+private:
+
+    Shared* sm;
+
+    Ice::CommunicatorPtr ic;
+    jderobot::CameraPrx cprx;
+};
+}
+
+#endif // CONTROL_H

Added: trunk/src/stable/components/basic_component_qt/control/threadcontrol.cpp
===================================================================
--- trunk/src/stable/components/basic_component_qt/control/threadcontrol.cpp	                        (rev 0)
+++ trunk/src/stable/components/basic_component_qt/control/threadcontrol.cpp	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,40 @@
+#include "threadcontrol.h"
+
+namespace basic_component_qt {
+
+ThreadControl::ThreadControl(Ice::CommunicatorPtr ic, Shared* sm)
+{
+    this->control = new Control(ic, sm);
+}
+
+void ThreadControl::start()
+{
+    //Calculates the refreshing time of the sensors class
+    struct timeval a, b;
+    long totalb, totala;
+    long diff;
+
+    while (true) {
+        gettimeofday(&a, NULL);
+        totala = a.tv_sec * 1000000 + a.tv_usec;
+
+        //update the sensors (in this case the image taken from the camera)
+        this->control->update();
+
+        gettimeofday(&b, NULL);
+        totalb = b.tv_sec * 1000000 + b.tv_usec;
+        diff = (totalb - totala) / 1000;
+
+        if (diff < 0 || diff > cycle_control)
+            diff = cycle_control;
+        else
+            diff = cycle_control - diff;
+
+
+        /*Sleep Algorithm*/
+        usleep(diff * 1000);
+        if (diff < 33)
+            usleep(33 * 1000);
+    }
+}
+}

Added: trunk/src/stable/components/basic_component_qt/control/threadcontrol.h
===================================================================
--- trunk/src/stable/components/basic_component_qt/control/threadcontrol.h	                        (rev 0)
+++ trunk/src/stable/components/basic_component_qt/control/threadcontrol.h	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,25 @@
+#ifndef THREADCONTROL_H
+#define THREADCONTROL_H
+
+#include <iostream>
+#include <sys/time.h>
+
+#include "control.h"
+#include "../shared.h"
+
+#define cycle_control 20 //miliseconds
+
+namespace basic_component_qt {
+class ThreadControl
+{
+public:
+    ThreadControl(Ice::CommunicatorPtr ic, Shared* sm);
+    void start();
+
+private:
+    Control* control;
+
+};
+}
+
+#endif // THREADCONTROL_H

Added: trunk/src/stable/components/basic_component_qt/gui/gui.cpp
===================================================================
--- trunk/src/stable/components/basic_component_qt/gui/gui.cpp	                        (rev 0)
+++ trunk/src/stable/components/basic_component_qt/gui/gui.cpp	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,52 @@
+#include "gui.h"
+namespace basic_component_qt {
+Gui::Gui(Shared* sm)
+{
+
+    this->sm = sm;
+
+    //Creation and setup of Gui elements
+    QGridLayout* mainLayout = new QGridLayout();
+    labelImage = new QLabel();
+    mainLayout->addWidget(labelImage, 0, 0);
+    setLayout(mainLayout);
+    setVisible(true);
+
+    //We connect a signat to a slot to be able to do something from an incoming signal.
+    connect(this, SIGNAL(signal_updateGUI()), this, SLOT(on_updateGUI_recieved()));
+
+    show();
+
+}
+
+
+void Gui::updateThreadGUI()
+{
+    //emit the signal to update the gui
+    emit signal_updateGUI();
+}
+
+void Gui::on_updateGUI_recieved()
+{
+    //Create and displays the image taken from the shared memory.
+
+    //cv::Mat
+    cv::Mat frame = this->sm->getImage();
+    QImage imageQt = QImage((const unsigned char*)(frame.data),
+                            frame.cols,
+                            frame.rows,
+                            frame.step,
+                            QImage::Format_RGB888);
+/*  
+    //IplImage
+    IplImage* frame = this->sm->getImage();
+    QImage imageQt = QImage((const unsigned char*)(frame->imageData),
+                            frame->width,
+                            frame->height,
+                            QImage::Format_RGB888);
+*/
+  
+    labelImage->setPixmap(QPixmap::fromImage(imageQt));
+}
+
+}

Added: trunk/src/stable/components/basic_component_qt/gui/gui.h
===================================================================
--- trunk/src/stable/components/basic_component_qt/gui/gui.h	                        (rev 0)
+++ trunk/src/stable/components/basic_component_qt/gui/gui.h	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,29 @@
+#ifndef GUI_H
+#define GUI_H
+
+#include <QtGui>
+
+#include "../shared.h"
+
+namespace basic_component_qt {
+class Gui : public QWidget
+{
+    Q_OBJECT
+
+public:
+    Gui(Shared* sm);
+    void updateThreadGUI();
+
+private:
+    QLabel* labelImage;
+    Shared* sm;
+
+signals:
+    void signal_updateGUI();
+
+public slots:
+    void on_updateGUI_recieved();
+
+};
+}
+#endif // GUI_H

Added: trunk/src/stable/components/basic_component_qt/gui/threadgui.cpp
===================================================================
--- trunk/src/stable/components/basic_component_qt/gui/threadgui.cpp	                        (rev 0)
+++ trunk/src/stable/components/basic_component_qt/gui/threadgui.cpp	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,42 @@
+#include "threadgui.h"
+
+namespace basic_component_qt {
+ThreadGui::ThreadGui(Shared* sm)
+{
+    //New instace of Gui with the shared memory object.
+    gui = new Gui(sm);
+    gui->show();
+
+}
+
+void ThreadGui::start()
+{
+    //Calculates the refreshing time of the gui.
+    struct timeval a, b;
+    long totalb, totala;
+    long diff;
+
+    while (true) {
+        gettimeofday(&a, NULL);
+        totala = a.tv_sec * 1000000 + a.tv_usec;
+
+        //updates the gui (image shown in this component)
+        gui->updateThreadGUI();
+
+        gettimeofday(&b, NULL);
+        totalb = b.tv_sec * 1000000 + b.tv_usec;
+        diff = (totalb - totala) / 1000;
+
+        if (diff < 0 || diff > cycle_gui)
+            diff = cycle_gui;
+        else
+            diff = cycle_gui - diff;
+
+
+        /*Sleep Algorithm*/
+        usleep(diff * 1000);
+        if (diff < 33)
+            usleep(33 * 1000);
+    }
+}
+}

Added: trunk/src/stable/components/basic_component_qt/gui/threadgui.h
===================================================================
--- trunk/src/stable/components/basic_component_qt/gui/threadgui.h	                        (rev 0)
+++ trunk/src/stable/components/basic_component_qt/gui/threadgui.h	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,24 @@
+#ifndef THREADGUI_H
+#define THREADGUI_H
+
+#include <iostream>
+#include <sys/time.h>
+
+#include "gui.h"
+
+#include "../shared.h"
+
+#define cycle_gui 50 //miliseconds
+
+namespace basic_component_qt {
+class ThreadGui
+{
+public:
+    ThreadGui(Shared* sm);
+    void start();
+
+private:
+    Gui* gui;
+};
+}
+#endif // THREADGUI_H

Added: trunk/src/stable/components/basic_component_qt/shared.cpp
===================================================================
--- trunk/src/stable/components/basic_component_qt/shared.cpp	                        (rev 0)
+++ trunk/src/stable/components/basic_component_qt/shared.cpp	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,60 @@
+#include "shared.h"
+#include <cv.h>
+
+#define w 400
+
+namespace basic_component_qt {
+
+    //Using cv::Mat Images
+    
+    void Shared::createImage(jderobot::ImageDataPtr data) {
+	pthread_mutex_lock(&this->controlGui);
+        image.create(data->description->height, data->description->width, CV_8UC3);
+	pthread_mutex_unlock(&this->controlGui);
+    }
+    
+    void Shared::updateImage(jderobot::ImageDataPtr data){
+	pthread_mutex_lock(&this->controlGui);
+        memcpy((unsigned char *) image.data ,&(data->pixelData[0]), image.cols*image.rows * 3);
+	pthread_mutex_unlock(&this->controlGui);
+    }
+    
+    void Shared::createEmptyImage() {
+	pthread_mutex_lock(&this->controlGui);
+	image.create(w, w, CV_8UC3);
+	pthread_mutex_unlock(&this->controlGui);
+    }
+    cv::Mat Shared::getImage() {
+	pthread_mutex_lock(&this->controlGui);
+        cv::Mat result = image.clone();
+	pthread_mutex_unlock(&this->controlGui);
+        return result;
+    }
+
+/*
+    //Using IplImages
+
+    void Shared::createImage(jderobot::ImageDataPtr data) {
+        mutex.lock();
+        image = cvCreateImage(cvSize(data->description->width,data->description->height), 8 ,3);
+	memcpy((unsigned char *) image->imageData,&(data->pixelData[0]),image->width*image->height * 3);
+        mutex.unlock();
+    }
+    
+    void Shared::updateImage(jderobot::ImageDataPtr data){
+        mutex.lock();
+        memcpy((unsigned char *) image->imageData,&(data->pixelData[0]),image->width*image->height * 3);
+        mutex.unlock();
+    }
+   
+    IplImage* Shared::getImage() {
+        mutex.lock();
+        IplImage* result = cvCreateImage(cvSize(image->width,image->height), 8 ,3); 
+	cvCopy(image, result);
+        mutex.unlock();
+        return result;
+    }
+*/
+    
+    Shared::~Shared() {};
+}

Added: trunk/src/stable/components/basic_component_qt/shared.h
===================================================================
--- trunk/src/stable/components/basic_component_qt/shared.h	                        (rev 0)
+++ trunk/src/stable/components/basic_component_qt/shared.h	2014-05-29 10:40:01 UTC (rev 1234)
@@ -0,0 +1,38 @@
+#ifndef BASIC_COMPONENT_QT_SHARED_MEM
+#define BASIC_COMPONENT_QT_SHARED_MEM
+
+
+#include <iostream>
+#include <jderobot/camera.h>
+#include <pthread.h>
+
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
+
+namespace basic_component_qt {
+
+    class Shared {
+        
+    public:
+        virtual ~Shared();
+        
+        void updateImage(jderobot::ImageDataPtr data);
+        void createImage(jderobot::ImageDataPtr data);
+	void createEmptyImage();
+        cv::Mat getImage();	//cv::Mat
+	/*
+	IplImage* getImage();	//IplImage*
+	*/
+        
+    private:
+   	pthread_mutex_t controlGui;
+        cv::Mat image;	//cv::Mat 
+        /*
+	IplImage* image; //IplImage
+	*/
+        
+        
+    };
+}
+#endif /* defined(____shared__) */



More information about the Jderobot-admin mailing list