[Jderobot-admin] jderobot-r1134 - trunk/src/stable/components/openniServer

rocapal en jderobot.org rocapal en jderobot.org
Lun Dic 30 11:03:44 CET 2013


Author: rocapal
Date: 2013-12-30 11:03:44 +0100 (Mon, 30 Dec 2013)
New Revision: 1134

Modified:
   trunk/src/stable/components/openniServer/openniServer.cpp
Log:
#145 fixed bug about usleep function


Modified: trunk/src/stable/components/openniServer/openniServer.cpp
===================================================================
--- trunk/src/stable/components/openniServer/openniServer.cpp	2013-12-28 18:42:04 UTC (rev 1133)
+++ trunk/src/stable/components/openniServer/openniServer.cpp	2013-12-30 10:03:44 UTC (rev 1134)
@@ -416,13 +416,17 @@
 
 
 		pthread_mutex_unlock(&mutex);
-		if ((IceUtil::Time::now().toMicroSeconds() - lastIT.toMicroSeconds()) > cycle ){
+		int delay = IceUtil::Time::now().toMicroSeconds() - lastIT.toMicroSeconds();
+		if (delay > cycle ){
 			if (debug==3)
 				std::cout<<"-------- openniServer: MAIN openni timeout-" << std::endl;
 		}
 		else{
-			usleep(cycle - (IceUtil::Time::now().toMicroSeconds() - lastIT.toMicroSeconds()));
+			if (delay <1 || delay > cycle)
+				delay = 1;
+			usleep(delay);
 		}
+
 		lastIT=IceUtil::Time::now();
 
    }
@@ -656,16 +660,16 @@
 			pthread_mutex_unlock(&mutex);
 
 
-			if ((IceUtil::Time::now().toMicroSeconds() - lastIT.toMicroSeconds()) > cycle ){
-				if (debug)
-					std::cout<<"-------- openniServer: WARNING- RGB timeout-" << std::endl;
+			int delay = IceUtil::Time::now().toMicroSeconds() - lastIT.toMicroSeconds();
+			if (delay > cycle ){
+				if (debug==3)
+					std::cout<<"-------- openniServer: RGB openni timeout-" << std::endl;
 			}
 			else{
-				usleep(cycle - (IceUtil::Time::now().toMicroSeconds() - lastIT.toMicroSeconds()));
-			}
-			/*if (totalpre !=0){
-				std::cout << "rgb: " <<  1000000/(totala-totalpre) << std::endl;
-			}*/
+				if (delay <1 || delay > cycle)
+					delay = 1;
+				usleep(delay);
+			}	
 			lastIT=IceUtil::Time::now();
 		}
 	}
@@ -911,18 +915,19 @@
 			}
 			}//critical region end
 			pthread_mutex_unlock(&mutex);
-			/*gettimeofday(&b,NULL);
-			totalb=b.tv_sec*1000000+b.tv_usec;*/
-			if ((IceUtil::Time::now().toMicroSeconds() - lastIT.toMicroSeconds()) > cycle ){
-				if (debug)
+			
+
+			int delay = IceUtil::Time::now().toMicroSeconds() - lastIT.toMicroSeconds();
+			if (delay > cycle ){
+				if (debug==3)
 					std::cout<<"-------- openniServer: WARNING- DEPTH timeout-" << std::endl;
 			}
 			else{
-				usleep(cycle - (IceUtil::Time::now().toMicroSeconds() - lastIT.toMicroSeconds()));
-			}
-			/*if (totalpre !=0){
-				std::cout << "depth: " <<  1000000/(totala-totalpre) << std::endl;
-			}*/
+				if (delay <1 || delay > cycle)
+					delay = 1;
+				usleep(delay);
+			}			
+			
 			lastIT=IceUtil::Time::now();
 		}
 	}
@@ -1088,16 +1093,19 @@
 							//}
 						}
 					pthread_mutex_unlock(&(this->myCloud->localMutex));
-					if ((IceUtil::Time::now().toMicroSeconds() - lastIT.toMicroSeconds()) > cycle ){
-						if (debug)
-							std::cout<<"-------- openniServer: WARNING- POINTCLOUD timeout-" << std::endl;
+
+					int delay = IceUtil::Time::now().toMicroSeconds() - lastIT.toMicroSeconds();
+					if (delay > cycle ){
+						if (debug==3)
+							std::cout<<"-------- openniServer: POINTCLOUD openni timeout-" << std::endl;
 					}
 					else{
-						usleep(cycle - (IceUtil::Time::now().toMicroSeconds() - lastIT.toMicroSeconds()));
+						if (delay <1 || delay > cycle)
+							delay = 1;
+						usleep(delay);
 					}
-					/*if (totalpre !=0){
-						std::cout << "cloud: " <<  1000000/(totala-totalpre) << std::endl;
-					}*/
+
+					
 					lastIT=IceUtil::Time::now();
 		        }
 		    }



More information about the Jderobot-admin mailing list