00001 /************************************************************************************************** 00002 Software License Agreement (BSD License) 00003 00004 Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt 00005 All rights reserved. 00006 00007 Redistribution and use in source and binary forms, with or without modification, are permitted 00008 provided that the following conditions are met: 00009 00010 *Redistributions of source code must retain the above copyright notice, this list of 00011 conditions and the following disclaimer. 00012 *Redistributions in binary form must reproduce the above copyright notice, this list of 00013 conditions and the following disclaimer in the documentation and/or other materials provided 00014 with the distribution. 00015 *Neither the name of the University of Aveiro nor the names of its contributors may be used to 00016 endorse or promote products derived from this software without specific prior written permission. 00017 00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 00019 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 00020 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 00021 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00024 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00025 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 ***************************************************************************************************/ 00033 #ifndef _TIMER_H_ 00034 #define _TIMER_H_ 00035 00040 #define MINIMUM_IPC_SLEEP 0.005 00041 00042 //#################################################################### 00043 // Includes: 00044 //#################################################################### 00045 00046 //System Includes 00047 #include <sys/time.h> 00048 #include <unistd.h> 00049 #include <stdio.h> 00050 #include <stdlib.h> 00051 #include <pthread.h> 00052 #include <ros/ros.h> 00053 //Include lar wrappers 00054 00055 //Include lar individual modules 00056 00057 00058 //Include local modules 00059 00060 00061 00062 // double lar_get_time(); 00063 00064 class c_timer{ 00065 public: 00066 c_timer(); 00067 ~c_timer(); 00068 00069 void tic(int); 00070 void toc(int); 00071 void run_sleep(int, double); 00072 void set_ipc_sleep(int); 00073 char run_ipc_sleep(double, int, char); 00074 double get_toc(int);//added by dgameiro on 25-02-2010 00075 void verb(int start=0, int end=10){printf("class timer tocs...\n");for (int i=start;i<end;i++) {printf("toc[%d]=%3.4f ms\n",i,lar_toc[i]*1000.0);}}; 00076 00077 private: 00078 //pthread_mutex_t ipc_connected_mutex; 00079 char ipc_connected; 00080 pthread_mutex_t clock_tic_mutex; 00081 double clock_tic[10]; 00082 pthread_mutex_t clock_set_mutex; 00083 char clock_set[10]; 00084 pthread_mutex_t lar_tic_mutex; 00085 double lar_tic[10]; 00086 pthread_mutex_t lar_toc_mutex; 00087 double lar_toc[10]; 00088 }; 00089 #endif 00090