Revision 9cb381ec

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:
......
90 88

  
91 89
    bool active;
92 90
    unsigned int repetition_now;
93
    boost::system_time end_time;
94
    boost::system_time start_time;
91
    std::chrono::time_point<std::chrono::steady_clock> end_time;
92
    std::chrono::time_point<std::chrono::steady_clock> start_time;
95 93
};
96

  
97

  
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:
......
76 77
    humotion::GazeState gaze_state;
77 78

  
78 79

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

  
......
108 109

  
109 110
    AudioPlayer *audio_player;
110 111
};
111

  
112

  
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:
......
53 54
    int driver;
54 55

  
55 56
};
56

  
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>
34

  
31
#include <chrono>
35 32

  
36 33
class EmotionConfig{
37 34
public:
......
76 73
    //overblend time
77 74
    unsigned int overblend_time_ms;
78 75
private:
79
    boost::system_time end_time;
76
    std::chrono::time_point<std::chrono::steady_clock> end_time;
80 77
};
81

  
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

  
66 65
};
67

  
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(){
......
141 142
    }
142 143

  
143 144
    //now check if this animation ended:
144
    system_time now = get_system_time(); //posix_time::microsec_clock::local_time();
145
    std::chrono::time_point<std::chrono::steady_clock> now = std::chrono::steady_clock::now();
145 146
    if (now > end_time){
146 147
        active = false;
147 148
        return;
148 149
    }
149 150

  
150 151
    //milliseconds from the beginning of this ani:
151
    posix_time::time_duration diff = now - start_time;
152
    float elapsed_ms = diff.total_milliseconds();
153
    //printf("mili %f\n",elapsed_ms);
152
    float elapsed_ms = std::chrono::duration<float, milli>(now - start_time).count();
153
    //printf("milli %f\n",elapsed_ms);
154 154

  
155 155
    float max_elongation = 0.0;
156 156
    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;
......
66 68

  
67 69
void Arbiter::set_default_emotion(EmotionState e){
68 70
    //lock access
69
    mutex::scoped_lock scoped_lock(emotion_config_default_mutex);
71
    boost::mutex::scoped_lock scoped_lock(emotion_config_default_mutex);
70 72

  
71 73
    //update our config, ignore duration as this is the default emotion
72 74
    emotion_config_default.select_config(e.value);
......
79 81

  
80 82
void Arbiter::set_current_emotion(EmotionState e){
81 83
    //lock access
82
    mutex::scoped_lock scoped_lock(emotion_config_current_mutex);
84
    boost::mutex::scoped_lock scoped_lock(emotion_config_current_mutex);
83 85

  
84 86
    //this will set a emotion override for a given time, after the timeout
85 87
    //we will return to the default emotion state:
......
94 96

  
95 97
void Arbiter::set_mouth_config(MouthConfig m){
96 98
    //lock access
97
    mutex::scoped_lock scoped_lock(mouth_config_override_mutex);
99
    boost::mutex::scoped_lock scoped_lock(mouth_config_override_mutex);
98 100

  
99 101
    mouth_config = m;
100 102
}
101 103

  
102 104
void Arbiter::set_gaze_target(humotion::GazeState target){
103 105
    //lock access
104
    mutex::scoped_lock scoped_lock(requested_gaze_state_mutex);
106
    boost::mutex::scoped_lock scoped_lock(requested_gaze_state_mutex);
105 107

  
106 108
    requested_gaze_state = target;
107 109
}
108 110

  
109 111
void Arbiter::set_mouth_target(humotion::MouthState target){
110 112
    //lock access
111
    mutex::scoped_lock scoped_lock(requested_mouth_state_mutex);
113
    boost::mutex::scoped_lock scoped_lock(requested_mouth_state_mutex);
112 114

  
113 115
    requested_mouth_state = target;
114 116
}
......
117 119
void Arbiter::play_animation(boost::shared_ptr<Animation> incoming_animation){
118 120
    //incoming animation, check if this would conflict with any pending animations:
119 121
    //lock access & iterate over vector:
120
    mutex::scoped_lock lock_av(active_animation_vector_mutex);
122
    boost::mutex::scoped_lock lock_av(active_animation_vector_mutex);
121 123
    active_animation_vector_t::iterator it;
122 124
    for(it = active_animation_vector.begin(); it<active_animation_vector.end(); it++){
123 125
        boost::shared_ptr<Animation> current_ani = *it;
......
160 162

  
161 163
void Arbiter::speak(boost::shared_ptr<Utterance> u){ //, ao_sample_format audio_format, char *audio_data, unsigned int audio_len){
162 164
    //lock audio playback as such:
163
    mutex::scoped_lock scoped_lock_audio(audio_player_mutex);
165
    boost::mutex::scoped_lock scoped_lock_audio(audio_player_mutex);
164 166

  
165 167
    //lock utterance & store data:
166
    mutex::scoped_lock scoped_lock(utterance_mutex);
168
    boost::mutex::scoped_lock scoped_lock(utterance_mutex);
167 169
    utterance = u;
168 170
    scoped_lock.unlock();
169 171

  
......
270 272
    }
271 273

  
272 274
    //lock access
273
    mutex::scoped_lock scoped_lock1(emotion_config_default_mutex);
275
    boost::mutex::scoped_lock scoped_lock1(emotion_config_default_mutex);
274 276

  
275 277

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

  
328 329
        result.pan_offset = gaze_state_old.pan_offset + tp * (gaze_target.pan_offset - gaze_state_old.pan_offset);
......
343 344

  
344 345
void Arbiter::override_by_animation(){
345 346
    //lock access & iterate over vector:
346
    mutex::scoped_lock lock_av(active_animation_vector_mutex);
347
    boost::mutex::scoped_lock lock_av(active_animation_vector_mutex);
347 348
    active_animation_vector_t::iterator it;
348 349
    for(it = active_animation_vector.begin(); it<active_animation_vector.end(); it++){
349 350
        boost::shared_ptr<Animation> current_ani = *it;
server/src/AudioPlayerRSB.cpp
127 127
                int sampling_rate  = audio_data_ptr->rate();
128 128
                double playback_time = (double)sample_count / (double)sampling_rate;
129 129
                printf("> AudioPlayerRSB estimated playbacktime to %5.3lf seconds. will wait now...",playback_time);
130
                boost::this_thread::sleep(boost::posix_time::milliseconds(1000.0 * playback_time));
130
                boost::this_thread::sleep(std::chrono::seconds(playback_time));
131 131
                printf("> AudioPlayerRSB finished waiting...\n");
132 132
                break;
133 133
            }
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);
......
42 41

  
43 42

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

  
......
51 50

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

  
57 56
void EmotionConfig::select_config(EmotionType e){
......
104 103
    mouth_override.position_right  = 11.5250000000000000000;
105 104
    mouth_override.opening_right   = 0;//2.412000;
106 105
    */
107
    
106

  
108 107
    mouth_override.position_left   = 20;
109 108
    mouth_override.opening_left    = 0.0;
110 109
    mouth_override.position_center = 22;
......
141 140
    mouth_override.opening_center  = 7.0;
142 141
    mouth_override.position_right  = -1+10.5;
143 142
    mouth_override.opening_right   = 0.0;*/
144
  
143

  
145 144
    mouth_override.position_left   = 18; //13.56850000000000000000;
146 145
    mouth_override.opening_left    = 0; //.791000;
147 146
    mouth_override.position_center = 26; //14.18400000000000000000;
......
149 148
    mouth_override.position_right  = 18; //15.31800000000000000000;
150 149
    mouth_override.opening_right   = 0; //2.791000;
151 150

  
152
 
151

  
153 152

  
154 153
}
155 154

  
......
240 239
    mouth_override.position_right  = 22.0;
241 240
    mouth_override.opening_right   = 0.0;
242 241

  
243
    
242

  
244 243
}
245 244

  
246 245
void EmotionConfig::init_fear(){
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

  
......
87 87
    //empty phoneme list
88 88
    if (phonemes_vector.size() == 0) return "";
89 89

  
90
    system_time now = get_system_time();
90
    std::chrono::time_point<std::chrono::steady_clock> now = std::chrono::steady_clock::now();
91 91

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

  
98 98
        //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)){
......
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