[Jderobot-admin] jderobot-r1091 - trunk/src/stable/libs/parallelIce

frivas en jderobot.org frivas en jderobot.org
Vie Nov 8 09:46:35 CET 2013


Author: frivas
Date: 2013-11-08 09:46:35 +0100 (Fri, 08 Nov 2013)
New Revision: 1091

Modified:
   trunk/src/stable/libs/parallelIce/CMakeLists.txt
   trunk/src/stable/libs/parallelIce/cameraClient.cpp
   trunk/src/stable/libs/parallelIce/cameraClient.h
   trunk/src/stable/libs/parallelIce/pointcloudClient.cpp
   trunk/src/stable/libs/parallelIce/pointcloudClient.h
Log:
#110 included refresh rate calculation


Modified: trunk/src/stable/libs/parallelIce/CMakeLists.txt
===================================================================
--- trunk/src/stable/libs/parallelIce/CMakeLists.txt	2013-11-07 18:28:27 UTC (rev 1090)
+++ trunk/src/stable/libs/parallelIce/CMakeLists.txt	2013-11-08 08:46:35 UTC (rev 1091)
@@ -5,10 +5,10 @@
 
 include_directories( ${LIBS_DIR}/)
 
-add_library (parallelIce STATIC cameraClient.cpp  cameraClient.h  pointcloudClient.cpp  pointcloudClient.h)
+add_library (parallelIce STATIC cameraClient.cpp  cameraClient.h  pointcloudClient.cpp  pointcloudClient.h laserClient.cpp laserClient.h)
 TARGET_LINK_LIBRARIES(parallelIce colorspacesmm)
 
-add_library (parallelIceshare SHARED cameraClient.cpp  cameraClient.h  pointcloudClient.cpp  pointcloudClient.h)
+add_library (parallelIceshare SHARED cameraClient.cpp  cameraClient.h  pointcloudClient.cpp  pointcloudClient.h laserClient.cpp laserClient.h)
 TARGET_LINK_LIBRARIES(parallelIceshare colorspacesmmshare)
 
 

Modified: trunk/src/stable/libs/parallelIce/cameraClient.cpp
===================================================================
--- trunk/src/stable/libs/parallelIce/cameraClient.cpp	2013-11-07 18:28:27 UTC (rev 1090)
+++ trunk/src/stable/libs/parallelIce/cameraClient.cpp	2013-11-08 08:46:35 UTC (rev 1091)
@@ -52,23 +52,22 @@
 		std::cerr << msg << std::endl;
 		std::cout << prefix + " Not camera provided" << std::endl;
 	}
+	_done=false;
 }
 
 cameraClient::~cameraClient() {
 	// TODO Auto-generated destructor stub
+	_done=true;
 }
 
 void
 cameraClient::run(){
 	jderobot::ImageDataPtr dataPtr;
 	colorspaces::Image::FormatPtr fmt;
-	struct timeval post;
-	long long int totalpre=0;
-	long long int totalpost=0;
-	while (this->isAlive()){
-		gettimeofday(&post,NULL);
-		totalpost=post.tv_sec*1000000+post.tv_usec;
+	IceUtil::Time last;
 
+	last=IceUtil::Time::now();
+	while (!(_done)){
 		dataPtr = this->prx->getImageData();
 		fmt = colorspaces::Image::Format::searchFormat(dataPtr->description->format);
 		if (!fmt)
@@ -83,16 +82,16 @@
 		localData.copyTo(this->data);
 		this->controlMutex.unlock();
 
-		if (totalpre !=0){
-			if ((totalpost - totalpre) > this->cycle ){
-				if (this->debug)
-					std::cout<<"--------" << prefix << " adquisition timeout-" << std::endl;
-			}
-			else{
-				usleep(this->cycle - (totalpost - totalpre));
-			}
+		if ((IceUtil::Time::now().toMicroSeconds() - last.toMicroSeconds()) > this->cycle ){
+			//if (this->debug)
+				std::cout<<"--------" << prefix << " adquisition timeout-" << std::endl;
 		}
-		totalpre=totalpost;
+		else{
+			usleep(this->cycle - (IceUtil::Time::now().toMicroSeconds() - last.toMicroSeconds()));
+		}
+
+		this->refreshRate=(int)(1000000/(IceUtil::Time::now().toMicroSeconds() - last.toMicroSeconds()));
+		last=IceUtil::Time::now();
 	}
 }
 

Modified: trunk/src/stable/libs/parallelIce/cameraClient.h
===================================================================
--- trunk/src/stable/libs/parallelIce/cameraClient.h	2013-11-07 18:28:27 UTC (rev 1090)
+++ trunk/src/stable/libs/parallelIce/cameraClient.h	2013-11-08 08:46:35 UTC (rev 1091)
@@ -42,6 +42,7 @@
 
 	//callbacks
 	cv::Mat getImage();
+	int getRfreshRate(){return refreshRate;};
 private:
 	cv::Mat data;
 	jderobot::CameraPrx prx;
@@ -50,6 +51,8 @@
 	IceUtil::Mutex controlMutex;
 	std::string prefix;
 	bool debug;
+	bool _done;
+	int refreshRate;
 
 };
 

Modified: trunk/src/stable/libs/parallelIce/pointcloudClient.cpp
===================================================================
--- trunk/src/stable/libs/parallelIce/pointcloudClient.cpp	2013-11-07 18:28:27 UTC (rev 1090)
+++ trunk/src/stable/libs/parallelIce/pointcloudClient.cpp	2013-11-08 08:46:35 UTC (rev 1091)
@@ -49,22 +49,24 @@
 		std::cerr << msg << std::endl;
 		std::cout <<  prefix + " Not camera provided" << std::endl;
 	}
+	_done=false;
 
 }
 
 pointcloudClient::~pointcloudClient() {
 	// TODO Auto-generated destructor stub
+	this->_done=true;
 }
 
 void pointcloudClient::run(){
 
-	struct timeval post;
-	long long int totalpre=0;
-	long long int totalpost=0;
-	while (1){
-		gettimeofday(&post,NULL);
-		totalpost=post.tv_sec*1000000+post.tv_usec;
+	IceUtil::Time last;
 
+	last=IceUtil::Time::now();
+
+	while (!(_done)){
+
+
 		jderobot::pointCloudDataPtr localCloud=this->prx->getCloudData();
 
 		this->controlMutex.lock();
@@ -72,16 +74,15 @@
 		std::copy( localCloud->p.begin(), localCloud->p.end(), this->data.begin() );
 
 		this->controlMutex.unlock();
-		if (totalpre !=0){
-			if ((totalpost - totalpre) > this->cycle ){
-				if (this->debug)
-					std::cout<< prefix << ": pointCloud adquisition timeout-" << std::endl;
-			}
-			else{
-				usleep(this->cycle - (totalpost - totalpre));
-			}
+		if ((IceUtil::Time::now().toMicroSeconds() - last.toMicroSeconds()) > this->cycle ){
+			if (this->debug)
+				std::cout<< prefix << ": pointCloud adquisition timeout-" << std::endl;
 		}
-		totalpre=totalpost;
+		else{
+			usleep(this->cycle - (IceUtil::Time::now().toMicroSeconds() - last.toMicroSeconds()));
+		}
+		this->refreshRate=(int)(1000000/(IceUtil::Time::now().toMicroSeconds() - last.toMicroSeconds()));
+		last=IceUtil::Time::now();
 	}
 }
 

Modified: trunk/src/stable/libs/parallelIce/pointcloudClient.h
===================================================================
--- trunk/src/stable/libs/parallelIce/pointcloudClient.h	2013-11-07 18:28:27 UTC (rev 1090)
+++ trunk/src/stable/libs/parallelIce/pointcloudClient.h	2013-11-08 08:46:35 UTC (rev 1091)
@@ -40,6 +40,7 @@
 	virtual void run();
 
 	std::vector<jderobot::RGBPoint>  getData();
+	int getRfreshRate(){return refreshRate;};
 
 
 private:
@@ -49,6 +50,8 @@
 	long long int cycle;
 	IceUtil::Mutex controlMutex;
 	bool debug;
+	bool _done;
+	int refreshRate;
 
 };
 



More information about the Jderobot-admin mailing list