A sparse MPC solver for walking motion generation.
oruw_timer.h
Go to the documentation of this file.
1 /**
2  * @file
3  * @author Alexander Sherikov
4  * @date 05.03.2012 17:35:04 MSK
5  */
6 
7 
8 #ifndef ORUW_TIMER_H
9 #define ORUW_TIMER_H
10 
11 #include <qi/os.hpp>
12 
13 #include "oruw_log.h"
14 
15 
16 /**
17  * @brief Log time of existance on destruction. Throw an error, if the given
18  * upper limit is not satisfied.
19  */
21 {
22  public:
23  /**
24  * @brief Create a timer
25  *
26  * @param[in] timer_id identifier of the timer
27  * @param[in] timer_limit_ms the upper limit
28  */
29  oruw_timer(const char* timer_id, const unsigned int timer_limit_ms) : id(timer_id)
30  {
31  qi::os::gettimeofday (&start_time);
32  limit = (double) timer_limit_ms / 1000; // in seconds
33  }
34 
35 
36  /**
37  * @brief Reset timer to the current time
38  */
39  void reset()
40  {
41  qi::os::gettimeofday (&start_time);
42  }
43 
44 
45  /**
46  * @brief Checks if the limit is satisfied, logs a message.
47  *
48  * @return true if the limit is satisfied, false otherwise.
49  */
50  bool check()
51  {
52  qi::os::gettimeofday (&end_time);
53  double timediff = ((double) end_time.tv_sec - start_time.tv_sec
54  + 0.000001* (end_time.tv_usec - start_time.tv_usec));
55  ORUW_LOG_MESSAGE("Checking timer '%s': value = %f / limit = %f\n", id, timediff, limit);
56  return (timediff <= limit);
57  }
58 
59 
60  private:
61  qi::os::timeval end_time;
62  qi::os::timeval start_time;
63 
64  const char *id;
65  double limit;
66 };
67 #endif // ORUW_TIMER_H
qi::os::timeval end_time
Definition: oruw_timer.h:61
Log time of existance on destruction. Throw an error, if the given upper limit is not satisfied.
Definition: oruw_timer.h:20
bool check()
Checks if the limit is satisfied, logs a message.
Definition: oruw_timer.h:50
double limit
Definition: oruw_timer.h:65
oruw_timer(const char *timer_id, const unsigned int timer_limit_ms)
Create a timer.
Definition: oruw_timer.h:29
void reset()
Reset timer to the current time.
Definition: oruw_timer.h:39
const char * id
Definition: oruw_timer.h:64
#define ORUW_LOG_MESSAGE(...)
Definition: oruw_log.h:65
qi::os::timeval start_time
Definition: oruw_timer.h:62