Revision 9cb381ec 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)){ |
... | ... | |
59 | 57 |
|
60 | 58 |
//fetch middleware from cmd line |
61 | 59 |
std::string mw = argv[1]; |
62 |
to_upper(mw); //convert to uppercase |
|
60 |
boost::algorithm::to_upper(mw); //convert to uppercase
|
|
63 | 61 |
|
64 | 62 |
//fetch mw for humotion |
65 | 63 |
std::string mw_humotion = argv[2]; |
... | ... | |
84 | 82 |
|
85 | 83 |
printf("> all done. hlrc server ready\n"); |
86 | 84 |
|
87 |
//send values to human motion server |
|
88 |
float loop_delay = 1000.0 / 50.0; //run with 50Hz
|
|
89 |
boost::system_time timeout = get_system_time() + posix_time::milliseconds(loop_delay);
|
|
85 |
//send values to human motion server with 50Hz
|
|
86 |
const auto loop_period = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::duration<float>(1.0 / 50));
|
|
87 |
auto timeout = std::chrono::steady_clock::now() + loop_period;
|
|
90 | 88 |
|
91 | 89 |
while(client->ok()){ |
92 | 90 |
middleware->tick(); |
... | ... | |
102 | 100 |
//debug: |
103 | 101 |
//arbiter->get_mouth_state().dump(); |
104 | 102 |
|
105 |
thread::sleep(timeout);
|
|
106 |
timeout = get_system_time() + posix_time::milliseconds(loop_delay);
|
|
103 |
std::this_thread::sleep_until(timeout);
|
|
104 |
timeout += loop_period;
|
|
107 | 105 |
} |
108 | 106 |
|
109 | 107 |
return EXIT_SUCCESS; |
110 |
|
|
111 | 108 |
} |
112 |
|
Also available in: Unified diff