Line |
Branch |
Exec |
Source |
1 |
|
|
/** |
2 |
|
|
* @file demo_spinner.cpp |
3 |
|
|
* @author Maximilien Naveau (maximilien.naveau@gmail.com) |
4 |
|
|
* license License BSD-3-Clause |
5 |
|
|
* @copyright Copyright (c) 2019, New York University and Max Planck |
6 |
|
|
* Gesellschaft. |
7 |
|
|
* @date 2019-05-22 |
8 |
|
|
* |
9 |
|
|
* @brief Demo of the spinner class usage |
10 |
|
|
*/ |
11 |
|
|
|
12 |
|
|
#include "real_time_tools/realtime_check.hpp" |
13 |
|
|
#include "real_time_tools/spinner.hpp" |
14 |
|
|
#include "real_time_tools/thread.hpp" |
15 |
|
|
|
16 |
|
|
/** @brief implement a real time thread checking the timing of the loop */ |
17 |
|
✗ |
THREAD_FUNCTION_RETURN_TYPE thread_function(void*) |
18 |
|
|
{ |
19 |
|
✗ |
double frequency = 300.0; |
20 |
|
✗ |
double switch_frequency = 290; |
21 |
|
|
|
22 |
|
✗ |
real_time_tools::RealTimeCheck realtime_check(frequency, switch_frequency); |
23 |
|
✗ |
real_time_tools::Spinner spinner; |
24 |
|
✗ |
spinner.set_frequency(frequency); |
25 |
|
|
|
26 |
|
✗ |
for (int i = 0; i < 500; i++) |
27 |
|
|
{ |
28 |
|
✗ |
realtime_check.tick(); |
29 |
|
✗ |
spinner.spin(); |
30 |
|
|
} |
31 |
|
|
|
32 |
|
✗ |
std::cout << "\n"; |
33 |
|
✗ |
realtime_check.print(); |
34 |
|
✗ |
std::cout << "\n"; |
35 |
|
|
|
36 |
|
✗ |
return THREAD_FUNCTION_RETURN_VALUE; |
37 |
|
|
} |
38 |
|
|
|
39 |
|
|
/** @brief This a demo on how to use the RealTimeCheck class. */ |
40 |
|
✗ |
int main(int, char* []) |
41 |
|
|
{ |
42 |
|
✗ |
real_time_tools::RealTimeThread thread; |
43 |
|
✗ |
thread.create_realtime_thread(thread_function); |
44 |
|
✗ |
thread.join(); |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
/** |
48 |
|
|
* \example demo_spinner.cpp |
49 |
|
|
* |
50 |
|
|
* This demos has for purpose to present the class real_time_tools::Spinner. |
51 |
|
|
* This class |
52 |
|
|
* allows you to time a loop with a simple API. |
53 |
|
|
* |
54 |
|
|
* One need to create a spinner and set the current spinning frequency. Two |
55 |
|
|
* method are available for this: real_time_tools::Spinner::set_frequency() or |
56 |
|
|
* real_time_tools::Spinner::set_period().. |
57 |
|
|
* |
58 |
|
|
* Once this is set one just needs to call real_time_tools::Spinner::spin() and |
59 |
|
|
* the thread will |
60 |
|
|
* sleep just the amount of time needed in order for the loop to cadenced |
61 |
|
|
* properly. |
62 |
|
|
*/ |
63 |
|
|
|