$search
00001 /* -*- mode: C++ -*- 00002 * 00003 * Navigator timer class 00004 * 00005 * Copyright (C) 2007, 2010, Austin Robot Technology 00006 * 00007 * License: Modified BSD Software License Agreement 00008 * 00009 * $Id: ntimer.h 620 2010-09-25 01:11:51Z jack.oquin $ 00010 */ 00011 00012 #ifndef _NAV_TIMER_HH_ 00013 #define _NAV_TIMER_HH_ 00014 00015 #include <sys/time.h> 00016 #include <time.h> 00017 00022 class NavTimer 00023 { 00024 public: 00025 00027 NavTimer() 00028 { 00029 this->Cancel(); 00030 }; 00031 00032 virtual ~NavTimer() {}; 00033 00035 virtual void Cancel(void) 00036 { 00037 timer_running = false; 00038 } 00039 00047 virtual bool Check(void) 00048 { 00049 if (!timer_running) 00050 return false; // timer not set 00051 00052 // decrement time remaining by the duration of one cycle 00053 time_remaining -= (1.0 / art_msgs::ArtHertz::NAVIGATOR); 00054 return (time_remaining <= 0.0); 00055 } 00056 00061 virtual void Restart(double duration) 00062 { 00063 if (timer_running && time_remaining > 0.0) 00064 return; 00065 00066 Start(duration); 00067 } 00068 00070 virtual void Start(double duration) 00071 { 00072 timer_running = true; 00073 time_remaining = duration; 00074 } 00075 00076 protected: 00077 00078 double time_remaining; //< time remaining until done 00079 bool timer_running; //< true when timer running 00080 }; 00081 00082 #endif // _NAV_TIMER_HH_