Revision 90fa4b4e server/src/main.cpp
server/src/main.cpp | ||
---|---|---|
34 | 34 |
#include <iostream> |
35 | 35 |
#include <stdlib.h> |
36 | 36 |
#include <math.h> |
37 |
#include <boost/date_time/posix_time/posix_time.hpp> |
|
38 |
#include <boost/thread/thread_time.hpp> |
|
39 |
#include <boost/thread/thread.hpp> |
|
37 |
#include <chrono> |
|
38 |
#include <thread> |
|
40 | 39 |
#include <boost/algorithm/string.hpp> |
41 | 40 |
|
42 | 41 |
Arbiter* arbiter; |
43 | 42 |
|
44 | 43 |
using namespace std; |
45 |
using namespace boost; |
|
46 | 44 |
|
47 | 45 |
int main(int argc, char* argv[]) { |
48 | 46 |
if ((argc != 5) && (argc != 6)) { |
... | ... | |
61 | 59 |
|
62 | 60 |
// fetch middleware from cmd line |
63 | 61 |
std::string mw = argv[1]; |
64 |
to_upper(mw); // convert to uppercase |
|
62 |
boost::algorithm::to_upper(mw); // convert to uppercase
|
|
65 | 63 |
|
66 | 64 |
// fetch mw for humotion |
67 | 65 |
std::string mw_humotion = argv[2]; |
... | ... | |
87 | 85 |
|
88 | 86 |
printf("> all done. hlrc server ready\n"); |
89 | 87 |
|
90 |
// send values to human motion server |
|
91 |
float loop_delay = 1000.0 / 50.0; // run with 50Hz
|
|
92 |
boost::system_time timeout = get_system_time() + posix_time::milliseconds(loop_delay);
|
|
88 |
// send values to human motion server with 50Hz
|
|
89 |
const auto loop_period = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::duration<float>(1.0 / 50));
|
|
90 |
auto timeout = std::chrono::steady_clock::now() + loop_period;
|
|
93 | 91 |
|
94 | 92 |
while (client->ok()) { |
95 | 93 |
middleware->tick(); |
... | ... | |
105 | 103 |
// debug: |
106 | 104 |
// arbiter->get_mouth_state().dump(); |
107 | 105 |
|
108 |
thread::sleep(timeout);
|
|
109 |
timeout = get_system_time() + posix_time::milliseconds(loop_delay);
|
|
106 |
std::this_thread::sleep_until(timeout);
|
|
107 |
timeout += loop_period;
|
|
110 | 108 |
} |
111 | 109 |
|
112 | 110 |
return EXIT_SUCCESS; |
Also available in: Unified diff