This is some awesome robot code
Dependencies: mbed-rtos mbed QEI
Fork of ICRSEurobot13 by
tvmet/util/Timer.h@15:9c5aaeda36dc, 2013-04-06 (annotated)
- Committer:
- madcowswe
- Date:
- Sat Apr 06 20:57:54 2013 +0000
- Revision:
- 15:9c5aaeda36dc
Encoders fairly tuned, still has random noise in it
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
madcowswe | 15:9c5aaeda36dc | 1 | /* |
madcowswe | 15:9c5aaeda36dc | 2 | * Tiny Vector Matrix Library |
madcowswe | 15:9c5aaeda36dc | 3 | * Dense Vector Matrix Libary of Tiny size using Expression Templates |
madcowswe | 15:9c5aaeda36dc | 4 | * |
madcowswe | 15:9c5aaeda36dc | 5 | * Copyright (C) 2001 - 2007 Olaf Petzold <opetzold@users.sourceforge.net> |
madcowswe | 15:9c5aaeda36dc | 6 | * |
madcowswe | 15:9c5aaeda36dc | 7 | * This library is free software; you can redistribute it and/or |
madcowswe | 15:9c5aaeda36dc | 8 | * modify it under the terms of the GNU Lesser General Public |
madcowswe | 15:9c5aaeda36dc | 9 | * License as published by the Free Software Foundation; either |
madcowswe | 15:9c5aaeda36dc | 10 | * version 2.1 of the License, or (at your option) any later version. |
madcowswe | 15:9c5aaeda36dc | 11 | * |
madcowswe | 15:9c5aaeda36dc | 12 | * This library is distributed in the hope that it will be useful, |
madcowswe | 15:9c5aaeda36dc | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
madcowswe | 15:9c5aaeda36dc | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
madcowswe | 15:9c5aaeda36dc | 15 | * Lesser General Public License for more details. |
madcowswe | 15:9c5aaeda36dc | 16 | * |
madcowswe | 15:9c5aaeda36dc | 17 | * You should have received a copy of the GNU Lesser General Public |
madcowswe | 15:9c5aaeda36dc | 18 | * License along with this library; if not, write to the Free Software |
madcowswe | 15:9c5aaeda36dc | 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
madcowswe | 15:9c5aaeda36dc | 20 | * |
madcowswe | 15:9c5aaeda36dc | 21 | * $Id: Timer.h,v 1.9 2007-06-23 15:58:59 opetzold Exp $ |
madcowswe | 15:9c5aaeda36dc | 22 | */ |
madcowswe | 15:9c5aaeda36dc | 23 | |
madcowswe | 15:9c5aaeda36dc | 24 | #ifndef TVMET_UTIL_TIMER_H |
madcowswe | 15:9c5aaeda36dc | 25 | #define TVMET_UTIL_TIMER_H |
madcowswe | 15:9c5aaeda36dc | 26 | |
madcowswe | 15:9c5aaeda36dc | 27 | #if defined(TVMET_HAVE_SYS_TIME_H) && defined(TVMET_HAVE_UNISTD_H) |
madcowswe | 15:9c5aaeda36dc | 28 | # include <sys/time.h> |
madcowswe | 15:9c5aaeda36dc | 29 | # include <sys/resource.h> |
madcowswe | 15:9c5aaeda36dc | 30 | # include <unistd.h> |
madcowswe | 15:9c5aaeda36dc | 31 | #else |
madcowswe | 15:9c5aaeda36dc | 32 | # include <ctime> |
madcowswe | 15:9c5aaeda36dc | 33 | #endif |
madcowswe | 15:9c5aaeda36dc | 34 | |
madcowswe | 15:9c5aaeda36dc | 35 | namespace tvmet { |
madcowswe | 15:9c5aaeda36dc | 36 | |
madcowswe | 15:9c5aaeda36dc | 37 | namespace util { |
madcowswe | 15:9c5aaeda36dc | 38 | |
madcowswe | 15:9c5aaeda36dc | 39 | /** |
madcowswe | 15:9c5aaeda36dc | 40 | \class Timer Timer.h "tvmet/util/Timer.h" |
madcowswe | 15:9c5aaeda36dc | 41 | \brief A quick& dirty portable timer, measures elapsed time. |
madcowswe | 15:9c5aaeda36dc | 42 | |
madcowswe | 15:9c5aaeda36dc | 43 | It is recommended that implementations measure wall clock rather than CPU |
madcowswe | 15:9c5aaeda36dc | 44 | time since the intended use is performance measurement on systems where |
madcowswe | 15:9c5aaeda36dc | 45 | total elapsed time is more important than just process or CPU time. |
madcowswe | 15:9c5aaeda36dc | 46 | |
madcowswe | 15:9c5aaeda36dc | 47 | The accuracy of timings depends on the accuracy of timing information |
madcowswe | 15:9c5aaeda36dc | 48 | provided by the underlying platform, and this varies from platform to |
madcowswe | 15:9c5aaeda36dc | 49 | platform. |
madcowswe | 15:9c5aaeda36dc | 50 | */ |
madcowswe | 15:9c5aaeda36dc | 51 | |
madcowswe | 15:9c5aaeda36dc | 52 | class Timer |
madcowswe | 15:9c5aaeda36dc | 53 | { |
madcowswe | 15:9c5aaeda36dc | 54 | Timer(const Timer&); |
madcowswe | 15:9c5aaeda36dc | 55 | Timer& operator=(const Timer&); |
madcowswe | 15:9c5aaeda36dc | 56 | |
madcowswe | 15:9c5aaeda36dc | 57 | public: // types |
madcowswe | 15:9c5aaeda36dc | 58 | typedef double time_t; |
madcowswe | 15:9c5aaeda36dc | 59 | |
madcowswe | 15:9c5aaeda36dc | 60 | public: |
madcowswe | 15:9c5aaeda36dc | 61 | /** starts the timer immediatly. */ |
madcowswe | 15:9c5aaeda36dc | 62 | Timer() { m_start_time = getTime(); } |
madcowswe | 15:9c5aaeda36dc | 63 | |
madcowswe | 15:9c5aaeda36dc | 64 | /** restarts the timer */ |
madcowswe | 15:9c5aaeda36dc | 65 | void restart() { m_start_time = getTime(); } |
madcowswe | 15:9c5aaeda36dc | 66 | |
madcowswe | 15:9c5aaeda36dc | 67 | /** return elapsed time in seconds */ |
madcowswe | 15:9c5aaeda36dc | 68 | time_t elapsed() const { return (getTime() - m_start_time); } |
madcowswe | 15:9c5aaeda36dc | 69 | |
madcowswe | 15:9c5aaeda36dc | 70 | private: |
madcowswe | 15:9c5aaeda36dc | 71 | time_t getTime() const { |
madcowswe | 15:9c5aaeda36dc | 72 | #if defined(TVMET_HAVE_SYS_TIME_H) && defined(TVMET_HAVE_UNISTD_H) |
madcowswe | 15:9c5aaeda36dc | 73 | getrusage(RUSAGE_SELF, &m_rusage); |
madcowswe | 15:9c5aaeda36dc | 74 | time_t sec = m_rusage.ru_utime.tv_sec; // user, no system time |
madcowswe | 15:9c5aaeda36dc | 75 | time_t usec = m_rusage.ru_utime.tv_usec; // user, no system time |
madcowswe | 15:9c5aaeda36dc | 76 | return sec + usec/1e6; |
madcowswe | 15:9c5aaeda36dc | 77 | #else |
madcowswe | 15:9c5aaeda36dc | 78 | return static_cast<time_t>(std::clock()) / static_cast<time_t>(CLOCKS_PER_SEC); |
madcowswe | 15:9c5aaeda36dc | 79 | #endif |
madcowswe | 15:9c5aaeda36dc | 80 | } |
madcowswe | 15:9c5aaeda36dc | 81 | |
madcowswe | 15:9c5aaeda36dc | 82 | private: |
madcowswe | 15:9c5aaeda36dc | 83 | #if defined(TVMET_HAVE_SYS_TIME_H) && defined(TVMET_HAVE_UNISTD_H) |
madcowswe | 15:9c5aaeda36dc | 84 | mutable struct rusage m_rusage; |
madcowswe | 15:9c5aaeda36dc | 85 | #endif |
madcowswe | 15:9c5aaeda36dc | 86 | time_t m_start_time; |
madcowswe | 15:9c5aaeda36dc | 87 | }; |
madcowswe | 15:9c5aaeda36dc | 88 | |
madcowswe | 15:9c5aaeda36dc | 89 | } // namespace util |
madcowswe | 15:9c5aaeda36dc | 90 | |
madcowswe | 15:9c5aaeda36dc | 91 | } // namespace tvmet |
madcowswe | 15:9c5aaeda36dc | 92 | |
madcowswe | 15:9c5aaeda36dc | 93 | #endif // TVMET_UTIL_TIMER_H |
madcowswe | 15:9c5aaeda36dc | 94 | |
madcowswe | 15:9c5aaeda36dc | 95 | // Local Variables: |
madcowswe | 15:9c5aaeda36dc | 96 | // mode:C++ |
madcowswe | 15:9c5aaeda36dc | 97 | // tab-width:8 |
madcowswe | 15:9c5aaeda36dc | 98 | // End: |