NimbRo ROS Soccer Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
VisionTimer.hpp
1 //VisionTimer.hpp
2 // Created on: Mar 29, 2016
3 // Author: Hafez Farazi <farazi@ais.uni-bonn.de>
4 #pragma once
5 #include <ctime>
6 #include <stdio.h>
7 #include <iostream>
8 #include <sys/stat.h>
15 {
16 public:
17  double timeoutSec;
18  VisionTimer(double timeoutSec=10.0):timeoutSec(timeoutSec)
19  {
20  clock_gettime(CLOCK_REALTIME, &beg_);
21  beg_.tv_sec -= timeoutSec + 1;
22  }
23 
24  double elapsed()
25  {
26  clock_gettime(CLOCK_REALTIME, &end_);
27  return end_.tv_sec - beg_.tv_sec
28  + (end_.tv_nsec - beg_.tv_nsec) / 1000000000.;
29  }
30 
31  void reset()
32  {
33  clock_gettime(CLOCK_REALTIME, &beg_);
34  }
35 
36  bool IsDead(float timeout)
37  {
38  return (elapsed() > timeout);
39  }
40 
41  bool IsDead()
42  {
43  return (elapsed() > timeoutSec);
44  }
45 
46 private:
47  timespec beg_, end_;
48 };
To set a timer and checked if the timeout exceeded.
Definition: VisionTimer.hpp:14