Revision 90fa4b4e

View differences:

server/include/Animation.h
28 28

  
29 29
#pragma once
30 30
#include <humotion/gaze_state.h>
31
#include "boost/date_time/posix_time/posix_time.hpp"
32
#include <boost/thread/thread_time.hpp>
33
#include <boost/thread/thread.hpp>
31
#include <chrono>
34 32

  
35 33
class Animation {
36 34
public:
......
102 100

  
103 101
	bool active;
104 102
	unsigned int repetition_now;
105
	boost::system_time end_time;
106
	boost::system_time start_time;
103
	std::chrono::time_point<std::chrono::steady_clock> end_time;
104
	std::chrono::time_point<std::chrono::steady_clock> start_time;
107 105
};
server/include/Arbiter.h
28 28

  
29 29
#pragma once
30 30
#include <string>
31
#include <vector>
32
#include <boost/shared_ptr.hpp>
33
#include <boost/thread/mutex.hpp>
31 34
#include <humotion/client/client.h>
32 35
#include "EmotionState.h"
33 36
#include "EmotionConfig.h"
......
35 38
#include "Utterance.h"
36 39
#include "AudioPlayer.h"
37 40
#include "Animation.h"
38
#include <boost/shared_ptr.hpp>
39
#include <vector>
40 41

  
41 42
class Arbiter {
42 43
public:
......
74 75
	humotion::MouthState mouth_state;
75 76
	humotion::GazeState gaze_state;
76 77

  
77
	boost::posix_time::ptime gaze_state_end_time;
78
	std::chrono::time_point<std::chrono::steady_clock> gaze_state_end_time;
78 79
	humotion::GazeState gaze_state_old;
79 80
	bool gaze_state_animation_restart;
80 81

  
server/include/AudioPlayer.h
28 28

  
29 29
#pragma once
30 30
#include <string>
31
#include <boost/thread/thread_time.hpp>
32
#include <boost/thread/thread.hpp>
33 31
#include <boost/shared_ptr.hpp>
34 32
#include "AudioData.h"
35 33

  
server/include/AudioPlayerLibAO.h
29 29
#pragma once
30 30
#include "AudioPlayer.h"
31 31
#include <ao/ao.h>
32
#include <boost/thread/thread.hpp>
32 33

  
33 34
class AudioPlayerLibAO : public AudioPlayer {
34 35
public:
server/include/EmotionConfig.h
28 28

  
29 29
#pragma once
30 30
#include <humotion/client/client.h>
31
#include "boost/date_time/posix_time/posix_time.hpp"
32
#include <boost/thread/thread_time.hpp>
33
#include <boost/thread/thread.hpp>
31
#include <chrono>
34 32

  
35 33
class EmotionConfig {
36 34
public:
......
74 72
	unsigned int overblend_time_ms;
75 73

  
76 74
private:
77
	boost::system_time end_time;
75
	std::chrono::time_point<std::chrono::steady_clock> end_time;
78 76
};
server/include/Utterance.h
29 29
#pragma once
30 30
#include <string>
31 31
#include <vector>
32
#include "boost/date_time/posix_time/posix_time.hpp"
33
#include <boost/thread/thread_time.hpp>
34
#include <boost/thread/thread.hpp>
32
#include <chrono>
33
#include <boost/shared_ptr.hpp>
35 34
#include "AudioData.h"
36 35

  
37 36
class Utterance {
......
59 58

  
60 59
private:
61 60
	phonemes_vector_t::iterator phonemes_vector_iterator;
62
	boost::system_time symbol_end_time;
61
	std::chrono::time_point<std::chrono::steady_clock> symbol_end_time;
63 62

  
64 63
	bool playing;
65 64
};
server/src/Animation.cpp
27 27
 */
28 28

  
29 29
#include "Animation.h"
30
#include <stdexcept>
31

  
30 32
using namespace std;
31
using namespace boost;
32 33

  
33 34
Animation::Animation() {
34 35
	active = false;
......
51 52

  
52 53
	// Set up end time
53 54
	int duration = duration_each * repetitions;
54
	start_time = get_system_time(); // posix_time::microsec_clock::local_time();
55
	end_time = start_time + boost::posix_time::milliseconds(duration);
55
	start_time = std::chrono::steady_clock::now();
56
	end_time = start_time + std::chrono::milliseconds(duration);
56 57
}
57 58

  
58 59
bool Animation::is_active() {
......
147 148
	}
148 149

  
149 150
	// now check if this animation ended:
150
	system_time now = get_system_time(); // posix_time::microsec_clock::local_time();
151
	std::chrono::time_point<std::chrono::steady_clock> now = std::chrono::steady_clock::now();
151 152
	if (now > end_time) {
152 153
		active = false;
153 154
		return;
154 155
	}
155 156

  
156 157
	// milliseconds from the beginning of this ani:
157
	posix_time::time_duration diff = now - start_time;
158
	float elapsed_ms = diff.total_milliseconds();
159
	// printf("mili %f\n",elapsed_ms);
158
	float elapsed_ms = std::chrono::duration<float, milli>(now - start_time).count();
159
	// printf("milli %f\n",elapsed_ms);
160 160

  
161 161
	float max_elongation = 0.0;
162 162
	float profile = 0.0;
server/src/Arbiter.cpp
30 30
#include "AudioPlayerLibAO.h"
31 31
#include "AudioPlayerRSB.h"
32 32
#include <boost/algorithm/string/predicate.hpp>
33
#include <boost/thread/mutex.hpp>
34
#include <iostream>
33 35

  
34 36
using namespace boost;
35 37
using namespace std;
......
69 71

  
70 72
void Arbiter::set_default_emotion(EmotionState e) {
71 73
	// lock access
72
	mutex::scoped_lock scoped_lock(emotion_config_default_mutex);
74
	boost::mutex::scoped_lock scoped_lock(emotion_config_default_mutex);
73 75

  
74 76
	// update our config, ignore duration as this is the default emotion
75 77
	emotion_config_default.select_config(e.value);
......
82 84

  
83 85
void Arbiter::set_current_emotion(EmotionState e) {
84 86
	// lock access
85
	mutex::scoped_lock scoped_lock(emotion_config_current_mutex);
87
	boost::mutex::scoped_lock scoped_lock(emotion_config_current_mutex);
86 88

  
87 89
	// this will set a emotion override for a given time, after the timeout
88 90
	// we will return to the default emotion state:
......
97 99

  
98 100
void Arbiter::set_mouth_config(MouthConfig m) {
99 101
	// lock access
100
	mutex::scoped_lock scoped_lock(mouth_config_override_mutex);
102
	boost::mutex::scoped_lock scoped_lock(mouth_config_override_mutex);
101 103

  
102 104
	mouth_config = m;
103 105
}
104 106

  
105 107
void Arbiter::set_gaze_target(humotion::GazeState target) {
106 108
	// lock access
107
	mutex::scoped_lock scoped_lock(requested_gaze_state_mutex);
109
	boost::mutex::scoped_lock scoped_lock(requested_gaze_state_mutex);
108 110

  
109 111
	requested_gaze_state = target;
110 112
}
111 113

  
112 114
void Arbiter::set_mouth_target(humotion::MouthState target) {
113 115
	// lock access
114
	mutex::scoped_lock scoped_lock(requested_mouth_state_mutex);
116
	boost::mutex::scoped_lock scoped_lock(requested_mouth_state_mutex);
115 117

  
116 118
	requested_mouth_state = target;
117 119
}
......
120 122
void Arbiter::play_animation(boost::shared_ptr<Animation> incoming_animation) {
121 123
	// incoming animation, check if this would conflict with any pending animations:
122 124
	// lock access & iterate over vector:
123
	mutex::scoped_lock lock_av(active_animation_vector_mutex);
125
	boost::mutex::scoped_lock lock_av(active_animation_vector_mutex);
124 126
	active_animation_vector_t::iterator it;
125 127
	for (it = active_animation_vector.begin(); it < active_animation_vector.end(); it++) {
126 128
		boost::shared_ptr<Animation> current_ani = *it;
......
165 167
void Arbiter::speak(
166 168
   boost::shared_ptr<Utterance> u) { //, ao_sample_format audio_format, char *audio_data, unsigned int audio_len){
167 169
	// lock audio playback as such:
168
	mutex::scoped_lock scoped_lock_audio(audio_player_mutex);
170
	boost::mutex::scoped_lock scoped_lock_audio(audio_player_mutex);
169 171

  
170 172
	// lock utterance & store data:
171
	mutex::scoped_lock scoped_lock(utterance_mutex);
173
	boost::mutex::scoped_lock scoped_lock(utterance_mutex);
172 174
	utterance = u;
173 175
	scoped_lock.unlock();
174 176

  
......
277 279
	}
278 280

  
279 281
	// lock access
280
	mutex::scoped_lock scoped_lock1(emotion_config_default_mutex);
282
	boost::mutex::scoped_lock scoped_lock1(emotion_config_default_mutex);
281 283

  
282 284
	// did the current emotion time out?
283 285
	if (!emotion_target->is_active()) {
......
317 319
		// new incoming target, set up soft fade:
318 320
		cout << "NEW EMOTION\n";
319 321
		gaze_state_old = gaze_state;
320
		gaze_state_end_time = get_system_time() + boost::posix_time::milliseconds(overblend_time);
322
		gaze_state_end_time = std::chrono::steady_clock::now() + std::chrono::milliseconds(overblend_time);
321 323
		gaze_state_animation_restart = false;
322 324
	}
323 325
	// do smooth overblend, all targets should be reached at gaze_state_end_time
324
	boost::posix_time::time_duration tdiff = gaze_state_end_time - get_system_time();
325
	if (tdiff.is_negative()) {
326
	double diff_ms =
327
	   std::chrono::duration<double, std::milli>(gaze_state_end_time - std::chrono::steady_clock::now()).count();
328
	if (diff_ms < 0) {
326 329
		// animation is done, exit now
327 330
		return gaze_target;
328 331
	}
329 332
	else {
330 333
		// do smooth animation
331
		double diff_ms = tdiff.total_milliseconds();
332 334
		double tp = 1.0 - diff_ms / static_cast<double>(overblend_time);
333 335

  
334 336
		result.pan_offset = gaze_state_old.pan_offset + tp * (gaze_target.pan_offset - gaze_state_old.pan_offset);
......
349 351

  
350 352
void Arbiter::override_by_animation() {
351 353
	// lock access & iterate over vector:
352
	mutex::scoped_lock lock_av(active_animation_vector_mutex);
354
	boost::mutex::scoped_lock lock_av(active_animation_vector_mutex);
353 355
	active_animation_vector_t::iterator it;
354 356
	for (it = active_animation_vector.begin(); it < active_animation_vector.end(); it++) {
355 357
		boost::shared_ptr<Animation> current_ani = *it;
server/src/AudioPlayerRSB.cpp
128 128
				int sampling_rate = audio_data_ptr->rate();
129 129
				double playback_time = (double)sample_count / (double)sampling_rate;
130 130
				printf("> AudioPlayerRSB estimated playbacktime to %5.3lf seconds. will wait now...", playback_time);
131
				boost::this_thread::sleep(boost::posix_time::milliseconds(1000.0 * playback_time));
131
				boost::this_thread::sleep(std::chrono::seconds(playback_time));
132 132
				printf("> AudioPlayerRSB finished waiting...\n");
133 133
				break;
134 134
			}
server/src/EmotionConfig.cpp
27 27
 */
28 28

  
29 29
#include "EmotionConfig.h"
30
using namespace boost;
31 30

  
32 31
EmotionConfig::EmotionConfig() {
33 32
	select_config(NEUTRAL);
......
41 40
}
42 41

  
43 42
bool EmotionConfig::is_active() {
44
	if (get_system_time() >= end_time) {
43
	if (std::chrono::steady_clock::now() >= end_time) {
45 44
		return false;
46 45
	}
47 46

  
......
50 49

  
51 50
void EmotionConfig::set_duration(unsigned long ms) {
52 51
	// set a timeout:
53
	end_time = get_system_time() + posix_time::milliseconds(ms);
52
	end_time = std::chrono::steady_clock::now() + std::chrono::milliseconds(ms);
54 53
}
55 54

  
56 55
void EmotionConfig::select_config(EmotionType e) {
server/src/Utterance.cpp
72 72

  
73 73
	// fetch first end time
74 74
	symbol_duration_pair_t symbol_duration_pair = *phonemes_vector_iterator;
75
	symbol_end_time = get_system_time() + boost::posix_time::milliseconds(symbol_duration_pair.second);
75
	symbol_end_time = std::chrono::steady_clock::now() + std::chrono::milliseconds(symbol_duration_pair.second);
76 76

  
77 77
	printf("> we have %d pairs\n", (int)phonemes_vector.size());
78 78

  
......
89 89
	if (phonemes_vector.size() == 0)
90 90
		return "";
91 91

  
92
	system_time now = get_system_time();
92
	std::chrono::time_point<std::chrono::steady_clock> now = std::chrono::steady_clock::now();
93 93

  
94 94
	while (now > symbol_end_time) {
95 95
		// fetch next phoneme:
96 96
		symbol_duration_pair_t symbol_duration_pair = *phonemes_vector_iterator;
97
		symbol_end_time = symbol_end_time + boost::posix_time::milliseconds(symbol_duration_pair.second);
97
		symbol_end_time = symbol_end_time + std::chrono::milliseconds(symbol_duration_pair.second);
98 98
		// printf("time: %d", symbol_duration_pair.second);
99 99

  
100 100
		// do we have to increment the iterator or are we done? (NOTE: -1 is necessary here!)
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