Index: trunk/lib/FlairCore/CMakeLists.txt
===================================================================
--- trunk/lib/FlairCore/CMakeLists.txt	(revision 319)
+++ trunk/lib/FlairCore/CMakeLists.txt	(revision 330)
@@ -9,5 +9,4 @@
 INCLUDE_DIRECTORIES(
 	${LIBXML2_INCLUDE_DIR}
-	${CMAKE_SYSROOT}/usr/include/opencv1
 	${CMAKE_SYSROOT}/usr/include/udt
 	${CMAKE_CURRENT_SOURCE_DIR}/src
Index: trunk/lib/FlairCore/src/ConditionVariable.cpp
===================================================================
--- trunk/lib/FlairCore/src/ConditionVariable.cpp	(revision 319)
+++ trunk/lib/FlairCore/src/ConditionVariable.cpp	(revision 330)
@@ -31,5 +31,5 @@
 ConditionVariable::~ConditionVariable() { delete pimpl_; }
 
-void ConditionVariable::CondWait(void) { pimpl_->CondWait(); }
+bool ConditionVariable::CondWait(Time timeout) { return pimpl_->CondWait(timeout); }
 
 bool ConditionVariable::CondWaitUntil(Time date) {
Index: trunk/lib/FlairCore/src/ConditionVariable.h
===================================================================
--- trunk/lib/FlairCore/src/ConditionVariable.h	(revision 319)
+++ trunk/lib/FlairCore/src/ConditionVariable.h	(revision 330)
@@ -55,6 +55,10 @@
   * Upon successful return, the mutex has been locked and is owned by the
   *calling thread which should unlock it (see Mutex::ReleaseMutex).
+  * 
+  * \param timeout timeout
+  * \return true if the condition variable is signaled before the tipeout specified
+  *  in parameter elapses or if timeout elapses, false otherwise
   */
-  void CondWait(void);
+  bool CondWait(Time timeout=TIME_INFINITE);
 
   /*!
Index: trunk/lib/FlairCore/src/ConditionVariable_impl.cpp
===================================================================
--- trunk/lib/FlairCore/src/ConditionVariable_impl.cpp	(revision 319)
+++ trunk/lib/FlairCore/src/ConditionVariable_impl.cpp	(revision 330)
@@ -53,16 +53,21 @@
 }
 
-void ConditionVariable_impl::CondWait(void) {
+bool ConditionVariable_impl::CondWait(Time timeout) {
   int status;
+  if(timeout==TIME_INFINITE) {
 #ifdef __XENO__
-  status =
-      rt_cond_wait(&m_ResumeCond, &self->Mutex::pimpl_->mutex, TM_INFINITE);
+    status=rt_cond_wait(&m_ResumeCond, &self->Mutex::pimpl_->mutex, TM_INFINITE);
 #else
-  status = pthread_cond_wait(&m_ResumeCond, &self->Mutex::pimpl_->mutex);
+    status=pthread_cond_wait(&m_ResumeCond, &self->Mutex::pimpl_->mutex);
 #endif
-  if (status != 0) {
-		char errorMsg[256];
-    self->Err("error (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
-	}
+    if(status != 0) {
+      char errorMsg[256];
+      self->Err("error (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
+      return false;
+    }
+    return true;
+  } else {
+    return CondWaitUntil(GetTime()+timeout);
+  }
 }
 
@@ -72,12 +77,11 @@
   status = rt_cond_wait_until(&m_ResumeCond, &self->Mutex::pimpl_->mutex, date);
 #else
-  struct timespec restrict;
-  restrict.tv_sec = date / 1000000000;
-  restrict.tv_nsec = date % 1000000000;
+  struct timespec abstime;
+  abstime.tv_sec = date / 1000000000;
+  abstime.tv_nsec = date % 1000000000;
   status = pthread_cond_timedwait(&m_ResumeCond, &self->Mutex::pimpl_->mutex,
-                                  &restrict);
+                                  &abstime);
 #endif
-  if (status == 0)
-    return true;
+  if (status == 0) return true;
   if (status != ETIMEDOUT) {
 		char errorMsg[256];
Index: trunk/lib/FlairCore/src/IODevice_impl.cpp
===================================================================
--- trunk/lib/FlairCore/src/IODevice_impl.cpp	(revision 319)
+++ trunk/lib/FlairCore/src/IODevice_impl.cpp	(revision 330)
@@ -225,8 +225,12 @@
 
   wake_mutex->GetMutex();
-  if (thread_to_wake == NULL) {
-    thread_to_wake = (Thread *)thread;
-  } else {
-    status = -1;
+  if(thread==NULL) {
+    thread_to_wake=NULL;
+  } else {
+    if (thread_to_wake == NULL) {
+      thread_to_wake = (Thread *)thread;
+    } else {
+      status = -1;
+    }
   }
   wake_mutex->ReleaseMutex();
Index: trunk/lib/FlairCore/src/Picture.cpp
===================================================================
--- trunk/lib/FlairCore/src/Picture.cpp	(revision 319)
+++ trunk/lib/FlairCore/src/Picture.cpp	(revision 330)
@@ -20,4 +20,5 @@
 #include "Layout.h"
 #include "LayoutPosition.h"
+#include <string.h>
 
 using std::string;
@@ -45,5 +46,5 @@
   if (image != NULL) {
     image->GetMutex();
-    memcpy(buf, image->img->imageData, image->GetDataType().GetSize());
+    memcpy(buf, image->buffer, image->GetDataType().GetSize());
     image->ReleaseMutex();
   }
Index: trunk/lib/FlairCore/src/Picture.h
===================================================================
--- trunk/lib/FlairCore/src/Picture.h	(revision 319)
+++ trunk/lib/FlairCore/src/Picture.h	(revision 330)
@@ -15,5 +15,4 @@
 
 #include <SendData.h>
-#include <cxtypes.h>
 
 namespace flair {
Index: trunk/lib/FlairCore/src/RangeFinderPlot.cpp
===================================================================
--- trunk/lib/FlairCore/src/RangeFinderPlot.cpp	(revision 319)
+++ trunk/lib/FlairCore/src/RangeFinderPlot.cpp	(revision 330)
@@ -20,5 +20,4 @@
 #include "Matrix.h"
 #include "LayoutPosition.h"
-#include <cxcore.h>
 
 using std::string;
Index: trunk/lib/FlairCore/src/Thread.cpp
===================================================================
--- trunk/lib/FlairCore/src/Thread.cpp	(revision 319)
+++ trunk/lib/FlairCore/src/Thread.cpp	(revision 330)
@@ -82,6 +82,6 @@
 void Thread::Resume(void) { pimpl_->Resume(); }
 
-int Thread::WaitUpdate(const IODevice *device) {
-  return pimpl_->WaitUpdate(device);
+bool Thread::WaitUpdate(const IODevice *device,Time timeout) {
+  return pimpl_->WaitUpdate(device,timeout);
 }
 
Index: trunk/lib/FlairCore/src/Thread.h
===================================================================
--- trunk/lib/FlairCore/src/Thread.h	(revision 319)
+++ trunk/lib/FlairCore/src/Thread.h	(revision 330)
@@ -140,6 +140,7 @@
   *
   * \param device IODevice to wait update from
-  */
-  int WaitUpdate(const IODevice *device);
+  * \return true if device was updated, false otherwise (timeout, etc)
+  */
+  bool WaitUpdate(const IODevice *device,Time timeout=TIME_INFINITE);
 
   /*!
Index: trunk/lib/FlairCore/src/Thread_impl.cpp
===================================================================
--- trunk/lib/FlairCore/src/Thread_impl.cpp	(revision 319)
+++ trunk/lib/FlairCore/src/Thread_impl.cpp	(revision 330)
@@ -276,10 +276,10 @@
 }
 
-int Thread_impl::WaitUpdate(const IODevice *device) {
-  int status = 0;
+bool Thread_impl::WaitUpdate(const IODevice *device,Time timeout) {
+  bool status = true;
 
   if (IsSuspended() == true) {
     self->Err("thread is already supended\n");
-    status = -1;
+    status = false;
   } else {
     cond->GetMutex();
@@ -287,10 +287,10 @@
     if (device->pimpl_->SetToWake(self) == 0) {
       is_suspended = true;
-      cond->CondWait();
+      status=cond->CondWait(timeout);
+      if(status==false) device->pimpl_->SetToWake(NULL);//condwait timedout
       is_suspended = false;
     } else {
-      self->Err("%s is already waiting an update\n",
-                device->ObjectName().c_str());
-      status = -1;
+      self->Err("%s is already waiting an update\n", device->ObjectName().c_str());
+      status = false;
     }
 
Index: trunk/lib/FlairCore/src/cvimage.cpp
===================================================================
--- trunk/lib/FlairCore/src/cvimage.cpp	(revision 319)
+++ trunk/lib/FlairCore/src/cvimage.cpp	(revision 330)
@@ -22,23 +22,26 @@
 namespace core {
 
+char* (*cvimage::allocFunction)(ssize_t)=cvimage::DefaultAllocFunction;
+void (*cvimage::freeFunction)(char*)=cvimage::DefaultFreeFunction;
+   
 cvimage::cvimage(const Object *parent, uint16_t width, uint16_t height,
                  Type::Format format, string name, bool allocate_data, int n)
     : io_data(parent, name, n), dataType(width, height, format) {
   this->allocate_data = allocate_data;
-
+//Printf("cvimage %s\n",ObjectName().c_str());
   if (allocate_data) {
     switch (format) {
     case Type::Format::YUYV:
     case Type::Format::UYVY:
-      img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 2);
+      buffer=allocFunction(width*height*2);
       break;
     case Type::Format::BGR:
-      img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
+      buffer=allocFunction(width*height*3);
       break;
     case Type::Format::Gray:
-      img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
+      buffer=allocFunction(width*height*1);
       break;
     default:
-      Err("format no supported");
+      Err("format not supported");
       break;
     }
@@ -47,22 +50,7 @@
       Err("number of samples!=1 not possible when not allocating data\n");
     n = 1;
-    switch (format) {
-    case Type::Format::YUYV:
-    case Type::Format::UYVY:
-      img = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, 2);
-      break;
-    case Type::Format::BGR:
-      img = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, 3);
-      break;
-    case Type::Format::Gray:
-      img = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, 1);
-      break;
-    default:
-      Err("format no supported");
-      break;
-    }
   }
 
-  SetPtrToCircle((void **)&img);
+  SetPtrToCircle((void **)&buffer);
 
   if (n > 1)
@@ -72,10 +60,27 @@
 cvimage::~cvimage() {
   // printf("destructeur cvimage\n");
-
-  cvReleaseImage(&img);
+  if(allocate_data) freeFunction(buffer);
 }
 
 void cvimage::RawRead(char *dst) const { Warn("non implementé\n"); }
 
+void cvimage::RegisterAllocFunction(char*(*func)(ssize_t size)) {
+  if(allocFunction==DefaultAllocFunction) allocFunction=func;
+}
+
+void cvimage::RegisterFreeFunction(void(*func)(char* buffer)) {
+  if(freeFunction==DefaultFreeFunction) freeFunction=func;
+}
+
+char* cvimage::DefaultAllocFunction(ssize_t size){
+  Printf("default alloc %i\n",size);
+  return (char*)malloc(size);
+}
+
+void cvimage::DefaultFreeFunction(char* buffer){
+  Printf("default free\n");
+  free(buffer);
+}
+
 } // end namespace core
 } // end namespace flair
Index: trunk/lib/FlairCore/src/cvimage.h
===================================================================
--- trunk/lib/FlairCore/src/cvimage.h	(revision 319)
+++ trunk/lib/FlairCore/src/cvimage.h	(revision 330)
@@ -14,7 +14,14 @@
 #define CVIMAGE_H
 
-#include <cxcore.h>
 #include <io_data.h>
 #include <stdint.h>
+
+
+namespace flair {
+namespace sensor {
+class V4LCamera;
+}
+}
+
 
 namespace flair {
@@ -28,5 +35,6 @@
 */
 class cvimage : public io_data {
-public:
+    public:
+  friend class flair::sensor::V4LCamera;
   class Type : public DataType {
   public:
@@ -97,12 +105,11 @@
   ~cvimage();
 
-  /*!
-  * \brief IplImage
-  *
-  * \return IplImage
-  */
-  IplImage *img;
+  
+  char *buffer;
 
   Type const &GetDataType() const { return dataType; };
+  
+  static void RegisterAllocFunction(char*(*func)(ssize_t size));
+  static void RegisterFreeFunction(void(*func)(char* buffer));
 
 private:
@@ -119,4 +126,9 @@
   bool allocate_data;
   Type dataType;
+  static char* (*allocFunction)(ssize_t);
+  static void (*freeFunction)(char*);
+  static char* DefaultAllocFunction(ssize_t size);
+  static void DefaultFreeFunction(char* buffer);
+  
 };
 
Index: trunk/lib/FlairCore/src/unexported/ConditionVariable_impl.h
===================================================================
--- trunk/lib/FlairCore/src/unexported/ConditionVariable_impl.h	(revision 319)
+++ trunk/lib/FlairCore/src/unexported/ConditionVariable_impl.h	(revision 330)
@@ -37,5 +37,5 @@
   ConditionVariable_impl(flair::core::ConditionVariable *self);
   ~ConditionVariable_impl();
-  void CondWait(void);
+  bool CondWait(flair::core::Time timeout);
   bool CondWaitUntil(flair::core::Time date);
   void CondSignal(void);
Index: trunk/lib/FlairCore/src/unexported/Thread_impl.h
===================================================================
--- trunk/lib/FlairCore/src/unexported/Thread_impl.h	(revision 319)
+++ trunk/lib/FlairCore/src/unexported/Thread_impl.h	(revision 330)
@@ -47,5 +47,5 @@
   void Resume(void);
   bool IsSuspended(void);
-  int WaitUpdate(const flair::core::IODevice *device);
+  bool WaitUpdate(const flair::core::IODevice *device,flair::core::Time timeout);
   bool period_set;
    bool isRunning;
Index: trunk/lib/FlairFilter/CMakeLists.txt
===================================================================
--- trunk/lib/FlairFilter/CMakeLists.txt	(revision 319)
+++ trunk/lib/FlairFilter/CMakeLists.txt	(revision 330)
@@ -8,5 +8,4 @@
 	${CMAKE_CURRENT_SOURCE_DIR}/src/unexported
 	${CMAKE_CURRENT_SOURCE_DIR}/src/
-	${CMAKE_SYSROOT}/usr/include/opencv1
 	${CMAKE_SYSROOT}/usr/include/iir
 )
Index: trunk/lib/FlairMeta/CMakeLists.txt
===================================================================
--- trunk/lib/FlairMeta/CMakeLists.txt	(revision 319)
+++ trunk/lib/FlairMeta/CMakeLists.txt	(revision 330)
@@ -9,5 +9,4 @@
 	${CMAKE_CURRENT_SOURCE_DIR}/src/unexported
 	${CMAKE_CURRENT_SOURCE_DIR}/src/
-	${CMAKE_SYSROOT}/usr/include/opencv1
 )
 
Index: trunk/lib/FlairSensorActuator/src/Camera.cpp
===================================================================
--- trunk/lib/FlairSensorActuator/src/Camera.cpp	(revision 319)
+++ trunk/lib/FlairSensorActuator/src/Camera.cpp	(revision 330)
@@ -117,4 +117,6 @@
 void Camera::ProcessUpdate(core::io_data* data) {
 	if(getFrameworkManager()->IsLogging() && getFrameworkManager()->IsDeviceLogged(this)) {
+    Printf("todo logging and jpeg without opencv\n");
+    /*
 		if(logFormat==LogFormat::JPG) {
 			data->GetMutex();
@@ -143,5 +145,5 @@
 			}
 			data->ReleaseMutex();
-		}
+		}*/
 	}
 	IODevice::ProcessUpdate(data);
@@ -151,5 +153,5 @@
 	if(filename=="") filename="./"+ObjectName()+"_"+std::to_string(GetTime())+".jpg";
   string::size_type idx = filename.rfind('.');
-
+Printf("todo SavePictureToFile without opencv\n");/*
 	if(idx != string::npos) {
 		Printf("saving %s\n", filename.c_str());
@@ -169,13 +171,13 @@
 	} else {
 		Warn("saving %s no file extension!\n", filename.c_str());
-	}
+	}*/
 }
 
 void Camera::SaveRawPictureToFile(string filename) const {
-  Printf("saving %s, size %i\n", filename.c_str(), output->img->imageSize);
+  Printf("saving %s, size %i\n", filename.c_str(), output->GetDataType().GetSize());
   std::ofstream pFile;
   pFile.open(filename);
   output->GetMutex();
-  pFile.write(output->img->imageData, output->img->imageSize);
+  pFile.write(output->buffer, output->GetDataType().GetSize());
   output->ReleaseMutex();
 
Index: trunk/lib/FlairSensorActuator/src/SimulatedCamera.cpp
===================================================================
--- trunk/lib/FlairSensorActuator/src/SimulatedCamera.cpp	(revision 319)
+++ trunk/lib/FlairSensorActuator/src/SimulatedCamera.cpp	(revision 330)
@@ -22,4 +22,5 @@
 #include <SharedMem.h>
 #include <sstream>
+#include <string.h>
 
 using std::string;
@@ -40,5 +41,5 @@
 
   shmemReadBuf=(char*)malloc(buf_size);
-  output->img->imageData = shmemReadBuf;
+  output->buffer = shmemReadBuf;
 
   shmem = new SharedMem((Thread *)this,ShMemName(modelId, deviceId), buf_size, SharedMem::Type::producerConsumer);
Index: trunk/lib/FlairSensorActuator/src/SimulatedCamera.h
===================================================================
--- trunk/lib/FlairSensorActuator/src/SimulatedCamera.h	(revision 319)
+++ trunk/lib/FlairSensorActuator/src/SimulatedCamera.h	(revision 330)
@@ -16,5 +16,4 @@
 #include <Camera.h>
 #include <Thread.h>
-#include <cxcore.h>
 
 namespace flair {
Index: trunk/lib/FlairSensorActuator/src/V4LCamera.cpp
===================================================================
--- trunk/lib/FlairSensorActuator/src/V4LCamera.cpp	(revision 319)
+++ trunk/lib/FlairSensorActuator/src/V4LCamera.cpp	(revision 330)
@@ -23,5 +23,14 @@
 #include <cvimage.h>
 #include <FrameworkManager.h>
+#include <fcntl.h>
 #include <linux/videodev2.h>
+
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <cstring>
+#include <sys/mman.h>
+
+
+#define DEFAULT_V4L_BUFFERS 4
 
 using std::string;
@@ -37,24 +46,67 @@
     : Thread(getFrameworkManager(), name, priority),
       Camera(name, width, height, format) {
-  capture = cvCaptureFromCAM(camera_index);
-  if (capture < 0)
-    Thread::Err("cvCaptureFromCAM error\n");
-
-  if (cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, width)<0)
-    Thread::Err("cvSetCaptureProperty error\n");
-  if (cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, height)<0)
-    Thread::Err("cvSetCaptureProperty error\n");
-
+  
+  string deviceName="/dev/video"+std::to_string(camera_index);
+  device = open(deviceName.c_str(), O_RDWR | O_NONBLOCK);
+  if (device == -1) {
+     Thread::Err("Cannot open %s\n");
+  }
+    
+  //get v4l2_format
+  struct v4l2_format form;
+  form.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+  xioctl (device, VIDIOC_G_FMT,&form);
+  
+  //set width, height and format
   if (format == cvimage::Type::Format::UYVY) {
-    if (cvSetCaptureProperty(capture, CV_CAP_PROP_FORMAT, V4L2_PIX_FMT_UYVY)<0)
-      Thread::Err("cvSetCaptureProperty error\n");
+    form.fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY; 
   } else if (format == cvimage::Type::Format::YUYV) {
-    if (cvSetCaptureProperty(capture, CV_CAP_PROP_FORMAT, V4L2_PIX_FMT_YUYV) <
-        0)
-      Thread::Err("cvSetCaptureProperty error\n");
+    form.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; 
   } else {
     Thread::Err("format not supported\n");
   }
-
+  
+  form.fmt.pix.width = width; 
+  form.fmt.pix.height = height;
+  form.fmt.win.chromakey = 0;
+  form.fmt.win.field = V4L2_FIELD_ANY;
+  form.fmt.win.clips = 0;
+  form.fmt.win.clipcount = 0;
+  form.fmt.pix.field = V4L2_FIELD_ANY;
+  xioctl (device, VIDIOC_S_FMT, &form);
+  
+  /* This is just a technicality, but all buffers must be filled up before any
+   staggered SYNC is applied.  SO, filler up. (see V4L HowTo) */
+
+  AllocBuffers();
+
+  for (int bufferIndex = 0; bufferIndex < ((int)requestbuffers.count);++bufferIndex) {
+    struct v4l2_buffer buf;
+
+    memset(&buf, 0, sizeof (v4l2_buffer));
+
+    buf.type        = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+    buf.memory      = V4L2_MEMORY_MMAP;
+    buf.index       = (unsigned long)bufferIndex;
+
+    if (-1 == xioctl (device, VIDIOC_QBUF, &buf)) {
+        Thread::Err("VIDIOC_QBUF xioctl\n");
+        break;
+    }
+  }
+
+  // enable the streaming
+  v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+  if (-1 == xioctl (device, VIDIOC_STREAMON,&type)) {
+      Thread::Err("VIDIOC_STREAMON xioctl\n");
+  }
+
+
+  // skip first frame. it is often bad -- this is unnotied in traditional apps,
+  //  but could be fatal if bad jpeg is enabled
+  GrabFrame();
+    
+    
+    
   // station sol
   gain = new DoubleSpinBox(GetGroupBox()->NewRow(), "gain:", 0, 1, 0.1);
@@ -85,11 +137,9 @@
 void V4LCamera::Run(void) {
   Time cam_time, new_time, fpsNow, fpsPrev;
-  IplImage *img; // raw image
+  char* buffer; // raw image
   int fpsCounter = 0;
 
   // init image old
-  if (!cvGrabFrame(capture)) {
-    Printf("Could not grab a frame\n");
-  }
+  GrabFrame();
   cam_time = GetTime();
   fpsPrev = cam_time;
@@ -97,7 +147,12 @@
   while (!ToBeStopped()) {
     //check for ps3eye deconnection in hds uav
-    if(cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH)<0) {
-      Thread::Warn("camera disconnected\n");
-      hasProblems=true;
+    if(hasProblems==false) {
+      struct v4l2_format form;
+      form.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+      xioctl(device, VIDIOC_G_FMT,&form);
+      if(xioctl (device, VIDIOC_G_FMT,&form)<0) {
+        Thread::Warn("camera disconnected\n");
+        hasProblems=true;
+      }
     }
     
@@ -127,5 +182,5 @@
       SetHue(hue->Value());
     if (sharpness->ValueChanged() == true)
-      cvSetCaptureProperty(capture, CV_CAP_PROP_SHARPNESS, sharpness->Value());
+      SetProperty(V4L2_CID_SHARPNESS, sharpness->Value());
     if (autogain->ValueChanged() == true) {
       if (autogain->Value() == true) {
@@ -147,11 +202,9 @@
     }
     if (awb->ValueChanged() == true)
-      cvSetCaptureProperty(capture, CV_CAP_PROP_AWB, awb->Value());
+      SetProperty(V4L2_CID_AUTO_WHITE_BALANCE, awb->Value());
 
     // cam pictures
-    img = cvRetrieveRawFrame(capture);
-    if (!cvGrabFrame(capture)) {
-      Printf("Could not grab a frame\n");
-    }
+    buffer = RetrieveRawFrame();
+    GrabFrame();
     new_time = GetTime();
     
@@ -163,5 +216,5 @@
 
     output->GetMutex();
-    output->img->imageData = img->imageData;
+    output->buffer = buffer;
     output->ReleaseMutex();
 
@@ -172,5 +225,176 @@
   }
 
-  cvReleaseCapture(&capture);
+  close(device);
+}
+
+void V4LCamera::GrabFrame(void) {
+    unsigned int count;
+
+    count = 1;
+
+    while (count-- > 0) {
+        for (;;) {
+            fd_set fds;
+            struct timeval tv;
+            int r;
+
+            FD_ZERO (&fds);
+            FD_SET (device, &fds);
+
+            /* Timeout. */
+            tv.tv_sec = 2;
+            tv.tv_usec = 0;
+
+            r = select (device+1, &fds, NULL, NULL, &tv);
+
+            if (-1 == r) {
+                if (EINTR == errno) continue;
+                Thread::Err("select\n");
+            }
+
+            if (0 == r) {
+                Thread::Err("select timeout\n");
+                /* end the infinite loop */
+                break;
+            }
+
+            if (read_frame_v4l2 ()) break;
+        }
+    }
+}
+
+int V4LCamera::read_frame_v4l2(void) {
+  struct v4l2_buffer buf;
+  memset(&buf, 0, sizeof (v4l2_buffer));
+  
+
+    buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+    buf.memory = V4L2_MEMORY_MMAP;
+
+    if (-1 == xioctl (device, VIDIOC_DQBUF, &buf)) {
+        switch (errno) {
+        case EAGAIN:
+            return 0;
+
+        case EIO:
+            /* Could ignore EIO, see spec. */
+
+            /* fall through */
+
+        default:
+            /* display the error and stop processing */
+            Thread::Err("VIDIOC_DQBUF xioctl\n");
+            return 1;
+        }
+   }
+
+   if(buf.index >= requestbuffers.count) {
+     Thread::Err("buf.index >= requestbuffers.count\n");
+   }
+   
+#ifdef USE_TEMP_BUFFER
+   memcpy(capture->buffers[MAX_V4L_BUFFERS].start, 
+	  capture->buffers[buf.index].start, 
+	  capture->buffers[MAX_V4L_BUFFERS].length );
+   capture->bufferIndex = MAX_V4L_BUFFERS;
+   //printf("got data in buff %d, len=%d, flags=0x%X, seq=%d, used=%d)\n", 
+   //	  buf.index, buf.length, buf.flags, buf.sequence, buf.bytesused);
+#else
+   bufferIndex = buf.index;
+#endif
+
+   if (-1 == xioctl (device, VIDIOC_QBUF, &buf)) {
+       Thread::Err ("VIDIOC_QBUF xioctl\n");
+   }
+
+   return 1;
+}
+
+int V4LCamera::AllocBuffers(void) {
+   memset(&requestbuffers, 0, sizeof (v4l2_requestbuffers));
+   
+   unsigned int buffer_number = DEFAULT_V4L_BUFFERS;
+
+   try_again:
+   
+   requestbuffers.count = buffer_number;
+   requestbuffers.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+   requestbuffers.memory = V4L2_MEMORY_MMAP;
+
+   if (-1 == xioctl (device, VIDIOC_REQBUFS, &requestbuffers)) {
+       if (EINVAL == errno) {
+         Thread::Err("not support memory mapping not supportted\n");
+       } else {
+         Thread::Err ("VIDIOC_REQBUFS xioctl\n");
+       }
+       return -1;
+   }
+
+   if (requestbuffers.count < buffer_number) {
+       if (buffer_number == 1) {
+        Thread::Err("Insufficient buffer memory\n");
+        return -1;
+       } else {
+        buffer_number--;
+        Thread::Warn ("Insufficient buffer memory, decreasing buffers\n");
+        goto try_again;
+       }
+   }
+
+   for (int n_buffers = 0; n_buffers < requestbuffers.count; ++n_buffers) {
+       struct v4l2_buffer buf;
+
+       memset(&buf, 0, sizeof (v4l2_buffer));
+
+       buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+       buf.memory = V4L2_MEMORY_MMAP;
+       buf.index = n_buffers;
+
+       if (-1 == xioctl (device, VIDIOC_QUERYBUF, &buf)) {
+           Thread::Err("VIDIOC_QUERYBUF xioctl\n");
+           return -1;
+       }
+
+       buffers[n_buffers].length = buf.length;
+       buffers[n_buffers].start =
+         mmap (NULL /* start anywhere */,
+               buf.length,
+               PROT_READ | PROT_WRITE /* required */,
+               MAP_SHARED /* recommended */,
+               device, buf.m.offset);
+
+       if (MAP_FAILED == buffers[n_buffers].start) {
+           Thread::Err("mmap\n");
+           return -1;
+       }
+   }
+
+  //todo: verifier cette alloc, pas de double buffeinrg?
+  //peut on initialiser l'image dans le constrcteur de la camera?
+   
+   output->buffer=output->allocFunction(output->dataType.GetSize());
+   return 1;
+};
+
+char *V4LCamera::RetrieveRawFrame(void) {
+  
+  /* [FD] this really belongs here */
+  if (ioctl(device, VIDIOCSYNC, &mmaps[bufferIndex].frame) == -1) {
+    Thread::Err("Could not SYNC to video stream. %s\n", strerror(errno));
+  }
+
+  /* Now get what has already been captured as a IplImage return */
+  if (output->dataType.GetFormat() == cvimage::Type::Format::YUYV || output->dataType.GetFormat() == cvimage::Type::Format::UYVY) {
+    #ifdef USE_TEMP_BUFFER
+    capture->frame.imageData=(char*)capture->buffers[capture->bufferIndex].start;
+    #else
+Printf("frame is not allocated\n");
+    memcpy((char *)frame,(char *)buffers[bufferIndex].start,output->GetDataType().GetSize());
+    #endif
+  } else {
+    Thread::Err("palette %d not supported for raw output\n",output->dataType.GetFormat());
+  }
+
+  return(frame);
 }
 
@@ -180,5 +404,5 @@
 
 void V4LCamera::SetAutoGain(bool value) {
-  cvSetCaptureProperty(capture, CV_CAP_PROP_AUTOGAIN, value);
+  SetProperty(V4L2_CID_AUTOGAIN, value);
 }
 
@@ -188,25 +412,67 @@
 
 void V4LCamera::SetGain(float value) {
-  cvSetCaptureProperty(capture, CV_CAP_PROP_GAIN, value);
+  SetProperty(V4L2_CID_GAIN, value);
 }
 
 void V4LCamera::SetExposure(float value) {
-  cvSetCaptureProperty(capture, CV_CAP_PROP_EXPOSURE, value);
+  SetProperty(V4L2_CID_EXPOSURE, value);
 }
 
 void V4LCamera::SetBrightness(float value) {
-  cvSetCaptureProperty(capture, CV_CAP_PROP_BRIGHTNESS, value);
+  SetProperty(V4L2_CID_BRIGHTNESS, value);
 }
 
 void V4LCamera::SetSaturation(float value) {
-  cvSetCaptureProperty(capture, CV_CAP_PROP_SATURATION, value);
+  SetProperty(V4L2_CID_SATURATION, value);
 }
 
 void V4LCamera::SetHue(float value) {
-  cvSetCaptureProperty(capture, CV_CAP_PROP_HUE, value);
+  SetProperty(V4L2_CID_HUE, value);
 }
 
 void V4LCamera::SetContrast(float value) {
-  cvSetCaptureProperty(capture, CV_CAP_PROP_CONTRAST, value);
+  SetProperty(V4L2_CID_CONTRAST, value);
+}
+
+float V4LCamera::GetProperty(int property) {
+  //get min and max value
+  struct v4l2_queryctrl queryctrl;
+  queryctrl.id = property;
+  if(xioctl (device, VIDIOC_QUERYCTRL,&queryctrl)==-1) return -1;
+  int min = queryctrl.minimum;
+  int max = queryctrl.maximum;
+ 
+  //set value
+  struct v4l2_control control;
+  memset (&control, 0, sizeof (v4l2_control));
+  control.id = property;
+  if(xioctl (device,VIDIOC_G_CTRL, &control)==-1) return -1;
+  
+  return ((float)control.value - min + 1) / (max - min);
+}
+
+void V4LCamera::SetProperty(int property,float value) {
+  //get min and max value
+  struct v4l2_queryctrl queryctrl;
+  queryctrl.id = property;
+  xioctl (device, VIDIOC_QUERYCTRL,&queryctrl);
+  int min = queryctrl.minimum;
+  int max = queryctrl.maximum;
+ 
+  //set value
+  struct v4l2_control control;
+  memset (&control, 0, sizeof (v4l2_control));
+  control.id = property;
+  control.value = (int)(value * (max - min) + min);
+  xioctl (device,VIDIOC_S_CTRL, &control);
+}
+
+int V4LCamera::xioctl( int fd, int request, void *arg) {
+  int r;
+
+  do r = ioctl (fd, request, arg);
+  while (-1 == r && EINTR == errno);
+
+  return r;
 }
 
Index: trunk/lib/FlairSensorActuator/src/V4LCamera.h
===================================================================
--- trunk/lib/FlairSensorActuator/src/V4LCamera.h	(revision 319)
+++ trunk/lib/FlairSensorActuator/src/V4LCamera.h	(revision 330)
@@ -16,5 +16,8 @@
 #include <Thread.h>
 #include "Camera.h"
-#include <highgui.h>
+//todo use pimpl and remove this
+#include <linux/videodev2.h>
+#include <libv4l1-videodev.h>
+#define MAX_V4L_BUFFERS 10
 
 namespace flair {
@@ -138,7 +141,6 @@
   */
   void Run(void);
-
-  CvCapture *capture;
-
+  
+  int device;
   gui::Tab *sensor_tab;
   gui::DoubleSpinBox *bright, *exposure, *gain, *contrast, *hue, *sharpness,*sat;
@@ -146,4 +148,20 @@
   gui::Label *fps;
   bool hasProblems;
+  static int xioctl( int fd, int request, void *arg);
+  void SetProperty(int property,float value);
+  float GetProperty(int property);
+  void GrabFrame(void);
+  int read_frame_v4l2(void);
+  char *RetrieveRawFrame(void);
+  int AllocBuffers(void);
+  struct video_mmap *mmaps;
+  int bufferIndex;
+  struct v4l2_requestbuffers requestbuffers;
+  struct buffer {
+    void *  start;
+    size_t  length;
+  };
+  buffer buffers[MAX_V4L_BUFFERS + 1];
+  char* frame;
 };
 } // end namespace sensor
Index: trunk/lib/FlairSensorActuator/src/VrpnClient.cpp
===================================================================
--- trunk/lib/FlairSensorActuator/src/VrpnClient.cpp	(revision 319)
+++ trunk/lib/FlairSensorActuator/src/VrpnClient.cpp	(revision 330)
@@ -36,5 +36,5 @@
 	
 VrpnClient::VrpnClient(string name,
-                       string address, uint8_t priority)
+                       string address, uint8_t priority,ConnectionType_t connectionType)
     : Thread(getFrameworkManager(), name, priority) {
 	if (singleton != NULL) {
@@ -45,21 +45,7 @@
   }
   
-  pimpl_ = new VrpnClient_impl(this, name, address);
+  pimpl_ = new VrpnClient_impl(this, name, address,connectionType);
 }
 
-
-VrpnClient::VrpnClient(std::string name,
-             uint16_t port,  uint8_t priority)
-  : Thread(getFrameworkManager(), name, priority) {
-	if (singleton != NULL) {
-    SimpleWarn("VrpnClient should be instanced only one time!\n");
-    SimpleWarn("Next calls to GetVrpnClient() will return the first created VrpnClient (%s)\n",singleton->ObjectName().c_str());
-  } else {
-    singleton = this;
-  }
-
-  pimpl_ = new VrpnClient_impl(this, name, port);
-}             
-             
 VrpnClient::VrpnClient(string name,
                        SerialPort *serialport, uint16_t us_period,
Index: trunk/lib/FlairSensorActuator/src/VrpnClient.h
===================================================================
--- trunk/lib/FlairSensorActuator/src/VrpnClient.h	(revision 319)
+++ trunk/lib/FlairSensorActuator/src/VrpnClient.h	(revision 330)
@@ -42,27 +42,18 @@
 
 public:
+  typedef enum { Vrpn, VrpnLite, Xbee } ConnectionType_t;
+
   /*!
   * \brief Constructor
   *
-  * Construct a VrpnClient. Connection is done by IP to a vrpn server.
+  * Construct a VrpnClient. Connection is done by IP to a vrpn server or vrpnlite server (see tools/VrpnLite in flair-src)
   *
   * \param name name
   * \param address server address
   * \param priority priority of the Thread
+  * \param connection connection type: Vrpn or VrpnLite
   */
   VrpnClient(std::string name,
-             std::string address,  uint8_t priority);
-
-  /*!
-  * \brief Constructor
-  *
-  * Construct a VrpnClient. Connection is done by IP to a vrpn-lite server (see tools/VrpnLite in flair-src)
-  *
-  * \param name name
-  * \param port server port
-  * \param priority priority of the Thread
-  */
-  VrpnClient(std::string name,
-             uint16_t port,  uint8_t priority);
+             std::string address,  uint8_t priority,ConnectionType_t connectionType=Vrpn);
              
   /*!
@@ -100,6 +91,4 @@
   gui::TabWidget *GetTabWidget(void) const;
   
-  typedef enum { Vrpn, VrpnLite, Xbee } ConnectionType_t;
-  
   ConnectionType_t ConnectionType(void) const;
 
Index: trunk/lib/FlairSensorActuator/src/VrpnClient_impl.cpp
===================================================================
--- trunk/lib/FlairSensorActuator/src/VrpnClient_impl.cpp	(revision 319)
+++ trunk/lib/FlairSensorActuator/src/VrpnClient_impl.cpp	(revision 330)
@@ -40,29 +40,24 @@
 
 VrpnClient_impl::VrpnClient_impl(VrpnClient *self, string name,
-                                 std::string address) {
+                                 std::string address,flair::sensor::VrpnClient::ConnectionType_t connectionType) {
   this->self = self;
   this->address = address;
+  this->connectionType = connectionType;
   isConnected=false;
-  connectionType=VrpnClient::Vrpn;
-
-  connection = vrpn_get_connection_by_name(address.c_str());
+  
+  if(connectionType==VrpnClient::Vrpn) {
+    connection = vrpn_get_connection_by_name(address.c_str());
+    Printf("Connecting to VRPN server on %s\n",address.c_str());
+  } else if(connectionType==VrpnClient::VrpnLite) {
+    dataSocket =new UdpSocket(getFrameworkManager(), "data_socket", address);
+    Printf("Connecting to VRPN-lite server on %s\n",address.c_str());
+  } else {
+    self->Err("Bad connection type, try using naother constructor\n");
+  }
 
   CommonConstructor(name);
-  
-  Printf("Connecting to VRPN server on %s\n",address.c_str());
-}
-
-VrpnClient_impl::VrpnClient_impl(VrpnClient *self, string name,
-                                 uint16_t port) {
-  this->self = self;
-	isConnected=false;
-  connectionType=VrpnClient::VrpnLite;
-
-  dataSocket =new UdpSocket(getFrameworkManager(), "data_socket", port);
-
-  CommonConstructor(name);
-  
-  Printf("Connecting to VRPN-lite server on port %i\n",port);
-}
+}
+
+
 
 VrpnClient_impl::VrpnClient_impl(VrpnClient *self, string name,
@@ -132,6 +127,25 @@
     trackables.push_back(obj);
     mutex->ReleaseMutex();
+  } else if (connectionType==VrpnClient::VrpnLite) {
+    if(liteObjects.size()<0xffff) {
+      liteObject_t tmp;
+      tmp.vrpnobject = obj;
+      tmp.id = liteObjects.size();
+      mutex->GetMutex();
+      liteObjects.push_back(tmp);
+      mutex->ReleaseMutex();
+      //Printf("%i %s\n",tmp.id,obj->self->ObjectName().c_str());
+      
+      char char_array[obj->self->ObjectName().length() + 2];//id coded on 16bits 
+      strcpy(char_array, obj->self->ObjectName().c_str()); 
+      uint16_t* idPtr=(uint16_t*)&char_array[obj->self->ObjectName().length()];
+      *idPtr=tmp.id;
+      dataSocket->HostToNetwork((char*)idPtr,sizeof(uint16_t));
+      dataSocket->SendMessage(char_array,obj->self->ObjectName().length() + 2);
+    }else {
+      self->Warn("too much trackables for vrpnlite connection, not adding %s\n",obj->self->ObjectName().c_str());
+    }
   } else {
-    self->Warn("AddTrackable called but not in vrpn mode\n");
+    self->Warn("AddTrackable called but not in vrpn mode nor in vrpnlite mode\n");
   }
 }
@@ -146,5 +160,5 @@
     mutex->ReleaseMutex();
   } else {
-    self->Warn("AddTrackable called but not in vrpnlite nor in xbee mode\n");
+    self->Warn("AddTrackable called but not in xbee mode\n");
   }
 }
@@ -153,6 +167,5 @@
   mutex->GetMutex();
   if (connectionType==VrpnClient::Vrpn) {
-    for (vector<VrpnObject_impl *>::iterator it = trackables.begin();
-         it < trackables.end(); it++) {
+    for (vector<VrpnObject_impl *>::iterator it = trackables.begin();it < trackables.end(); it++) {
       if (*it == obj) {
         trackables.erase(it);
@@ -162,6 +175,5 @@
   }
   if (connectionType==VrpnClient::VrpnLite || connectionType==VrpnClient::Xbee) {
-    for (vector<liteObject_t>::iterator it = liteObjects.begin();
-         it < liteObjects.end(); it++) {
+    for (vector<liteObject_t>::iterator it = liteObjects.begin();it < liteObjects.end(); it++) {
       if ((*it).vrpnobject == obj) {
         liteObjects.erase(it);
@@ -243,6 +255,9 @@
             //printf("%lld\n",GetTime()/(1000*1000));
             mutex->GetMutex();
-            for (unsigned int i = 0; i < trackables.size(); i++)
-                trackables.at(i)->tracker->mainloop();
+            for (unsigned int i = 0; i < trackables.size(); i++) {
+             // Printf("tracker %i\n",i);
+              trackables.at(i)->tracker->mainloop();
+              //Printf("tracker %i ok\n",i);
+            }
             mutex->ReleaseMutex();
         } else {
@@ -251,37 +266,55 @@
         }
     }else if(connectionType==VrpnClient::VrpnLite) {
-      vrpn_TRACKERCB t;
-      float pos[3];
-      float quat[4];
+      mutex->GetMutex();
+    
+      int16_t pos[3];
+      int16_t quat[4];
       Time time;
-      uint8_t id;
-      char datas[sizeof(id) + sizeof(pos)+sizeof(quat)+ sizeof(time)];
+      char datas[liteObjects.size()*(sizeof(pos)+sizeof(quat))+ sizeof(time)];
+      char *datasPtr=datas;
+      
       int rcv=dataSocket->RecvMessage(datas,sizeof(datas),50*1000*1000);
-      if(rcv!=sizeof(datas)) continue;  
-      id = datas[0];
-      memcpy(pos, datas+sizeof(id), sizeof(pos));
-      memcpy(quat, datas +sizeof(id)+ sizeof(pos), sizeof(quat));
-      memcpy(&time, datas+sizeof(id) + sizeof(pos)+sizeof(quat), sizeof(time));
-      
-      for(int i=0;i<3;i++) dataSocket->NetworkToHost((char*)(&pos[i]),sizeof(pos[i]));
-      for(int i=0;i<4;i++) dataSocket->NetworkToHost((char*)(&quat[i]),sizeof(quat[i]));
+      if(rcv!=sizeof(datas)) {
+        if(rcv>0) Printf("discarding message (size %i/%i)\n",rcv,sizeof(datas));
+        mutex->ReleaseMutex();
+        continue;  
+      }
+      
+      memcpy(&time, datasPtr+sizeof(datas)-sizeof(time), sizeof(time));
       dataSocket->NetworkToHost((char*)(&time),sizeof(time));
-
-      mutex->GetMutex();
-      if (id < liteObjects.size()) {
-        for (int i = 0; i < 3; i++) t.pos[i] = pos[i];
+      
+      for (vector<liteObject_t>::iterator it = liteObjects.begin();it < liteObjects.end(); it++) {
+        memcpy(pos, datasPtr, sizeof(pos));
+        datasPtr+=sizeof(pos);
+        memcpy(quat,datasPtr, sizeof(quat));
+        datasPtr+=sizeof(quat);
+        
+        for(int i=0;i<3;i++) dataSocket->NetworkToHost((char*)(&pos[i]),sizeof(pos[i]));
+        for(int i=0;i<4;i++) dataSocket->NetworkToHost((char*)(&quat[i]),sizeof(quat[i]));
+        
+        vrpn_TRACKERCB t;
+        for (int i = 0; i < 3; i++) t.pos[i] = ConvertPosition(pos[i]);
         // warning: t.quat is defined as (qx,qy,qz,qw), which is different from
         // flair::core::Quaternion
-        t.quat[0] = quat[1];
-        t.quat[1] = quat[2];
-        t.quat[2] = quat[3];
-        t.quat[3] = quat[0];
+        t.quat[0] = ConvertQuaternion(quat[1]);
+        t.quat[1] = ConvertQuaternion(quat[2]);
+        t.quat[2] = ConvertQuaternion(quat[3]);
+        t.quat[3] = ConvertQuaternion(quat[0]);
         t.msg_time.tv_sec=time/((Time)1000000000);
         t.msg_time.tv_usec=(time%((Time)1000000000))/((Time)1000);
         //Printf("%i %lld %lld %lld\n",id,time,t.msg_time.tv_sec,t.msg_time.tv_usec);
-        VrpnObject_impl::handle_pos(liteObjects.at(id).vrpnobject, t);
-      }
+        VrpnObject_impl::handle_pos((void*)(it->vrpnobject), t);
+      }
+      
       mutex->ReleaseMutex();
     }
   }
 }
+
+float VrpnClient_impl::ConvertPosition(int16_t value) const {
+  return (float)value/1000.;
+}
+
+float VrpnClient_impl::ConvertQuaternion(int16_t value) const {
+  return (float)value/32767.;
+}
Index: trunk/lib/FlairSensorActuator/src/VrpnObject.h
===================================================================
--- trunk/lib/FlairSensorActuator/src/VrpnObject.h	(revision 319)
+++ trunk/lib/FlairSensorActuator/src/VrpnObject.h	(revision 330)
@@ -50,5 +50,5 @@
   * \brief Constructor
   *
-  * Construct a VrpnObject. Connection is done by IP. (vrpn)
+  * Construct a VrpnObject. Connection is done by IP with vrpn or vrpnlite (see tools/VrpnLite in flair-src)
   *
   * \param name VRPN object name, should be the same as defined in the server
@@ -62,8 +62,8 @@
   * \brief Constructor
   *
-  * Construct a VrpnObject. Connection is done by xbee or vrpnlite (see tools/VrpnLite in flair-src)
+  * Construct a VrpnObject. Connection is done by xbee 
   *
   * \param name name
-  * \param id VRPN object id, should be the same as defined in the xbee bridge or vrpnlite tool
+  * \param id VRPN object id, should be the same as defined in the xbee bridge
   * \param tab Tab for the user interface
   * \param client VrpnClient of the connection, if unspecified, use the default one
Index: trunk/lib/FlairSensorActuator/src/VrpnObject_impl.cpp
===================================================================
--- trunk/lib/FlairSensorActuator/src/VrpnObject_impl.cpp	(revision 319)
+++ trunk/lib/FlairSensorActuator/src/VrpnObject_impl.cpp	(revision 330)
@@ -51,6 +51,6 @@
     self->Err("erreur aucun identifiant specifie pour la connexion Xbee\n");
   }
-  if (id == -1 && GetVrpnClient()->ConnectionType()==VrpnClient::VrpnLite) {
-    self->Err("erreur aucun identifiant specifie pour la connexion VrpnLite\n");
+  if (id != -1 && GetVrpnClient()->ConnectionType()==VrpnClient::VrpnLite) {
+    self->Err("identifiant pour la connexion ignore car inutile en mode VrpnLite\n");
   }
   if (id != -1 && GetVrpnClient()->ConnectionType()==VrpnClient::Vrpn) {
@@ -94,5 +94,5 @@
     parent->pimpl_->AddTrackable(this);
   } else if(GetVrpnClient()->ConnectionType()==VrpnClient::VrpnLite){
-    parent->pimpl_->AddTrackable(this, id);
+    parent->pimpl_->AddTrackable(this);
   }
   
@@ -191,4 +191,5 @@
 
   caller->output->SetDataTime(time,deltaTime);
+  //Printf("%s data filled\n",caller->self->ObjectName().c_str());
   caller->output->ReleaseMutex();
 
@@ -199,5 +200,6 @@
   caller->state->SetValueNoMutex(2, 0, Euler::ToDegree(euler.yaw));
   caller->state->ReleaseMutex();
-
+//Printf("%s process\n",caller->self->ObjectName().c_str());
   caller->self->ProcessUpdate(caller->output);
-}
+  //Printf("%s process ok\n",caller->self->ObjectName().c_str());
+}
Index: trunk/lib/FlairSensorActuator/src/unexported/VrpnClient_impl.h
===================================================================
--- trunk/lib/FlairSensorActuator/src/unexported/VrpnClient_impl.h	(revision 319)
+++ trunk/lib/FlairSensorActuator/src/unexported/VrpnClient_impl.h	(revision 330)
@@ -48,9 +48,8 @@
 public:
   VrpnClient_impl(flair::sensor::VrpnClient *self, std::string name,
-                  std::string address);
+                  std::string address,flair::sensor::VrpnClient::ConnectionType_t connectionType);
   VrpnClient_impl(flair::sensor::VrpnClient *self, std::string name,
                   flair::core::SerialPort *serialport, uint16_t us_period);
-  VrpnClient_impl(flair::sensor::VrpnClient *self, std::string name,
-                  uint16_t port);
+  
   ~VrpnClient_impl();
   void AddTrackable(VrpnObject_impl *obj);    // normal
@@ -67,4 +66,6 @@
 private:
   void CommonConstructor(std::string name);
+  float ConvertPosition(int16_t value) const;
+  float ConvertQuaternion(int16_t value) const;
   flair::sensor::VrpnClient *self;
   flair::core::Mutex *mutex;
Index: trunk/lib/FlairSimulator/CMakeLists.txt
===================================================================
--- trunk/lib/FlairSimulator/CMakeLists.txt	(revision 319)
+++ trunk/lib/FlairSimulator/CMakeLists.txt	(revision 330)
@@ -12,5 +12,4 @@
 	${CMAKE_CURRENT_SOURCE_DIR}/../FlairSensorActuator/src
 	${CMAKE_SYSROOT}/usr/include/vrpn
-	${CMAKE_SYSROOT}/usr/include/opencv1
 	${CMAKE_SYSROOT}/usr/include/irrlicht
 )
Index: trunk/lib/FlairVisionFilter/src/CvtColor.cpp
===================================================================
--- trunk/lib/FlairVisionFilter/src/CvtColor.cpp	(revision 319)
+++ trunk/lib/FlairVisionFilter/src/CvtColor.cpp	(revision 330)
@@ -57,5 +57,5 @@
 
 void CvtColor::UpdateFrom(const io_data *data) {
-    IplImage *img=((cvimage*)data)->img;
+    cvimage *img=(cvimage*)data;
 
     data->GetMutex();
@@ -64,5 +64,5 @@
     switch(conversion) {
     case Conversion_t::ToGray:
-        switch(((cvimage*)data)->GetDataType().GetFormat()) {
+        switch(img->GetDataType().GetFormat()) {
         case cvimage::Type::Format::YUYV:
             //dspCvtColor(img,output->img,DSP_YUYV2GRAY);
Index: trunk/lib/FlairVisionFilter/src/ImgThreshold.cpp
===================================================================
--- trunk/lib/FlairVisionFilter/src/ImgThreshold.cpp	(revision 319)
+++ trunk/lib/FlairVisionFilter/src/ImgThreshold.cpp	(revision 330)
@@ -53,7 +53,7 @@
 
 void ImgThreshold::UpdateFrom(const io_data *data) {
-    cvimage *cvImage=(cvimage*)data;
+ /*   cvimage *cvImage=(cvimage*)data;
     IplImage *gimg=cvImage->img;
-/*
+
     data->GetMutex();
     output->GetMutex();
Index: trunk/lib/FlairVisionFilter/src/OpticalFlow.cpp
===================================================================
--- trunk/lib/FlairVisionFilter/src/OpticalFlow.cpp	(revision 319)
+++ trunk/lib/FlairVisionFilter/src/OpticalFlow.cpp	(revision 330)
@@ -79,5 +79,5 @@
 
 void OpticalFlow::UpdateFrom(const io_data *data)
-{
+{/*
     IplImage *gimg=((cvimage*)data)->img;
     IplImage *gimg_old=((cvimage*)data->Prev(1))->img;
@@ -100,5 +100,5 @@
         output->Resize(max_features->Value());
     }
-/*
+
     if(is_init==false)
     {
@@ -125,5 +125,5 @@
     data->Prev(1)->ReleaseMutex();
     data->ReleaseMutex();
-*/
+
     //apply rotation
     for(i=0;i<count;i++) {
@@ -160,5 +160,5 @@
     //rotation
     swap(pyr,pyr_old);
-
+*/
     output->SetDataTime(data->DataTime());
     ProcessUpdate(output);
Index: trunk/lib/FlairVisionFilter/src/Sobel.cpp
===================================================================
--- trunk/lib/FlairVisionFilter/src/Sobel.cpp	(revision 319)
+++ trunk/lib/FlairVisionFilter/src/Sobel.cpp	(revision 330)
@@ -55,8 +55,8 @@
 }
 
-void Sobel::UpdateFrom(const io_data *data) {
+void Sobel::UpdateFrom(const io_data *data) {/*
     cvimage *cvImage=(cvimage*)data;
     IplImage *gimg=cvImage->img;
-/*
+
     data->GetMutex();
     output->GetMutex();
Index: trunk/tools/VrpnLite/src/VrpnLite.cpp
===================================================================
--- trunk/tools/VrpnLite/src/VrpnLite.cpp	(revision 319)
+++ trunk/tools/VrpnLite/src/VrpnLite.cpp	(revision 330)
@@ -25,14 +25,7 @@
 using namespace flair::sensor;
 
-VrpnLite::VrpnLite(string clientAddress,string serveurAddress): Thread(getFrameworkManager(),"VrpnLite",90) {
-  vrpnclient=new VrpnClient("vrpn", serveurAddress,80); 
-  VrpnObject* vrpnobject = new VrpnObject("x4_0",vrpnclient->GetTabWidget(),vrpnclient);
-  //VrpnObject* vrpnobject2 = new VrpnObject("target",vrpnclient->GetTabWidget(),vrpnclient);
-  
-  vrpnobjects.push_back(vrpnobject);
-  //vrpnobjects.push_back(vrpnobject2);
-  
-  dataSocket = new UdpSocket(this,"client socket",clientAddress);
-  
+VrpnLite::VrpnLite(int vrpnLitePort,string vrpnServerAddress): Thread(getFrameworkManager(),"VrpnLite",90) {
+  vrpnclient=new VrpnClient("vrpn", vrpnServerAddress,80); 
+  dataSocket = new UdpSocket(this,"client socket",vrpnLitePort);
   vrpnclient->Start();
 }
@@ -42,46 +35,99 @@
 
 void VrpnLite::Run(void) {
+  Time dataSocketTimeout;
+  char msg[256];
+  
   while (!ToBeStopped()) {
     
-    WaitUpdate(vrpnobjects.at(0));//tood improve this wait, to be sure all vrpnobject are up to date; or one thread by object?
-    //could be also lighter to send only one frame with all objects
-    int i=0;
-    for (vector<VrpnObject*>::iterator it = vrpnobjects.begin();it < vrpnobjects.end(); it++) {
-      SendObject(*it,i);
-      i++;
+    if(vrpnobjects.size()>0) {
+      //wait for last one to be sure all are up to date
+      if(WaitUpdate(vrpnobjects.at(vrpnobjects.size()-1),100000000)) {
+          SendObjects();
+      }
+      dataSocketTimeout=TIME_NONBLOCK;
+    } else {
+      dataSocketTimeout=100000000;
     }
     
+    ssize_t rcv=dataSocket->RecvMessage(msg,sizeof(msg),dataSocketTimeout);
+    if(rcv>0) {
+      string object=msg;
+      uint16_t* idPtr=(uint16_t*)&msg[rcv-2];
+      dataSocket->HostToNetwork((char*)idPtr,sizeof(uint16_t));
+      //assume we receive it in the good order
+      if(*idPtr==vrpnobjects.size()) {
+        Printf("adding object %s with id %i\n",object.c_str(),*idPtr);
+        VrpnObject* vrpnobject = new VrpnObject(object,vrpnclient->GetTabWidget());
+        vrpnobjects.push_back(vrpnobject);
+      }else {
+        Err("adding object %s failed, expected id %i, got %i\n",object.c_str(),vrpnobjects.size(),*idPtr);
+      }
+    }
   }
 }
 
-void VrpnLite::SendObject(const VrpnObject* vrpnobject,uint8_t id) const{
+void VrpnLite::SendObjects(void) const{
+  int16_t position[3];
+  int16_t quaternion[4];
+  Time time;
+  char datas[vrpnobjects.size()*(sizeof(position)+sizeof(quaternion))+ sizeof(time)];
+  char *datasPtr=datas;
+  
+  for (vector<VrpnObject*>::const_iterator it = vrpnobjects.begin();it < vrpnobjects.end(); it++) {
     Vector3Df objectPosition;
     Quaternion objectQuaternion;
-    
+    const VrpnObject* vrpnobject=*it;
+
     vrpnobject->GetPosition(objectPosition);
     vrpnobject->GetQuaternion(objectQuaternion);
-    Time time=vrpnobject->GetLastPacketTime();
-    
-    float position[3];
-    position[0]=objectPosition.x;
-    position[1]=objectPosition.y;
-    position[2]=objectPosition.z;
-    float quaternion[4];
-    quaternion[0]=objectQuaternion.q0;
-    quaternion[1]=objectQuaternion.q1;
-    quaternion[2]=objectQuaternion.q2;
-    quaternion[3]=objectQuaternion.q3;
-    
+    time=vrpnobject->GetLastPacketTime();
+
+    position[0]=ConvertPosition(objectPosition.x);
+    position[1]=ConvertPosition(objectPosition.y);
+    position[2]=ConvertPosition(objectPosition.z);
+    quaternion[0]=ConvertQuaternion(objectQuaternion.q0);
+    quaternion[1]=ConvertQuaternion(objectQuaternion.q1);
+    quaternion[2]=ConvertQuaternion(objectQuaternion.q2);
+    quaternion[3]=ConvertQuaternion(objectQuaternion.q3);
+
     for(int i=0;i<3;i++) dataSocket->HostToNetwork((char*)(&position[i]),sizeof(position[i]));
     for(int i=0;i<4;i++) dataSocket->HostToNetwork((char*)(&quaternion[i]),sizeof(quaternion[i]));
-    dataSocket->HostToNetwork((char*)(&time),sizeof(Time));
-    
-    char datas[sizeof(id) + sizeof(position)+sizeof(quaternion)+ sizeof(time)];
-    
-    datas[0]=id;
-    memcpy(datas+sizeof(id),position, sizeof(position));
-    memcpy(datas +sizeof(id)+ sizeof(position),quaternion, sizeof(quaternion));
-    memcpy(datas+sizeof(id) + sizeof(position)+sizeof(quaternion),&time, sizeof(time));
-    
-    dataSocket->SendMessage(datas,sizeof(datas));
+
+    memcpy(datasPtr,position, sizeof(position));
+    datasPtr+=sizeof(position);
+    memcpy(datasPtr,quaternion, sizeof(quaternion));
+    datasPtr+=sizeof(quaternion);
+  }
+  
+  dataSocket->HostToNetwork((char*)(&time),sizeof(Time));
+  memcpy(datasPtr,&time, sizeof(time));//only one time for all VrpnObject; suppose it is the same!
+  dataSocket->SendMessage(datas,sizeof(datas));
 }
+
+int16_t VrpnLite::ConvertQuaternion(float value) const{
+  int16_t tmp;
+  tmp=value*32767.;
+  if(value<-1) {
+    tmp=-32767;
+    Warn("position value is %f, saturating it to %i\n",value,tmp);
+  }
+  if(value>1) {
+    tmp=32767;
+    Warn("position value is %f, saturating it to %i\n",value,tmp);
+  }
+  return tmp;
+}
+
+int16_t VrpnLite::ConvertPosition(float value) const{
+  int16_t tmp;
+  tmp=value*1000;
+  if(value<-32.768) {
+    tmp=-32768;
+    Warn("position value is %f, saturating it to %i\n",value,tmp);
+  }
+  if(value>32.767) {
+    tmp=32767;
+    Warn("position value is %f, saturating it to %i\n",value,tmp);
+  }
+  return tmp;
+}
Index: trunk/tools/VrpnLite/src/VrpnLite.h
===================================================================
--- trunk/tools/VrpnLite/src/VrpnLite.h	(revision 319)
+++ trunk/tools/VrpnLite/src/VrpnLite.h	(revision 330)
@@ -30,5 +30,5 @@
 class VrpnLite: public flair::core::Thread {
   public:
-      VrpnLite(std::string clientAddress,std::string serveurAddress);
+      VrpnLite(int vrpnLitePort,std::string vrpnServerAddress);
       ~VrpnLite();
 
@@ -38,6 +38,7 @@
       std::vector<flair::sensor::VrpnObject*> vrpnobjects;
       flair::core::UdpSocket* dataSocket;
-      void SendObject(const flair::sensor::VrpnObject* vrpnobject,uint8_t id) const;
-      
+      void SendObjects(void) const;
+      int16_t ConvertPosition(float value) const;
+      int16_t ConvertQuaternion(float value) const;
 };
 
Index: trunk/tools/VrpnLite/src/main.cpp
===================================================================
--- trunk/tools/VrpnLite/src/main.cpp	(revision 319)
+++ trunk/tools/VrpnLite/src/main.cpp	(revision 330)
@@ -22,6 +22,6 @@
 
 string xml_file;
-string clientAddress,serverAddress;
-int port;
+string vrpnServerAddress;
+int gcsPort,vrpnLitePort;
 
 void parseOptions(int argc, char **argv);
@@ -32,8 +32,8 @@
   FrameworkManager *manager;
   manager = new FrameworkManager("vrpnforwarder");
-  manager->SetupConnection("127.0.0.1", port);
+  manager->SetupConnection("127.0.0.1", gcsPort);
   manager->SetupUserInterface(xml_file);
   
-  VrpnLite* vrpnlite=new VrpnLite(clientAddress,serverAddress);
+  VrpnLite* vrpnlite=new VrpnLite(vrpnLitePort,vrpnServerAddress);
   
   vrpnlite->Start();
@@ -47,7 +47,7 @@
     CmdLine cmd("Command description message", ' ', "0.1");
 
-    ValueArg<string> clientaddressArg("c", "caddress","client address", true,
-                                "127.0.0.1:3884", "string");
-    cmd.add(clientaddressArg);
+    ValueArg<int> vrpnLitePortArg("v", "vport","vrpn lite port", true,
+                                3884, "int");
+    cmd.add(vrpnLitePortArg);
     
     ValueArg<string> serveraddressArg("s", "saddress","server address", true,
@@ -55,7 +55,7 @@
     cmd.add(serveraddressArg);
 
-    ValueArg<int> portArg("p", "port","local port used to connect to the ground station",
+    ValueArg<int> gcsPortArg("p", "port","local port used to connect to the ground station",
                           false, 9000, "int");
-    cmd.add(portArg);
+    cmd.add(gcsPortArg);
 
 
@@ -66,7 +66,7 @@
     cmd.parse(argc, argv);
 
-    clientAddress = clientaddressArg.getValue();
-    serverAddress = serveraddressArg.getValue();
-    port = portArg.getValue();
+    vrpnLitePort = vrpnLitePortArg.getValue();
+    vrpnServerAddress = serveraddressArg.getValue();
+    gcsPort = gcsPortArg.getValue();
     xml_file = xmlArg.getValue();
 
