Revision ea068cf1 src/server/eyelid_motion_generator.cpp

View differences:

src/server/eyelid_motion_generator.cpp
47 47

  
48 48
//! constructor
49 49
EyelidMotionGenerator::EyelidMotionGenerator(JointInterface *j) : EyeMotionGenerator(j) {
50
    saccade_blink_active = false;
51
    saccade_blink_requested = false;
52
    eyelid_closed[LEFT] = false;
53
    eyelid_closed[RIGHT] = false;
50
    saccade_blink_active_ = false;
51
    saccade_blink_requested_ = false;
52
    eyelid_closed_[LEFT] = false;
53
    eyelid_closed_[RIGHT] = false;
54 54

  
55
    eyeblink_blocked_timeout = boost::get_system_time();
55
    eyeblink_blocked_timeout_ = boost::get_system_time();
56 56
}
57 57

  
58 58
//! destructor
......
69 69
    float eye_tilt_now  = get_current_position(JointInterface::ID_EYES_BOTH_UD);
70 70

  
71 71
    // calculate left eyelid targets
72
    float eyelid_upper_left_target = eye_tilt_now + requested_gaze_state.eyelid_opening_upper;
73
    float eyelid_lower_left_target = eye_tilt_now - requested_gaze_state.eyelid_opening_lower;
72
    float eyelid_upper_left_target = eye_tilt_now + requested_gaze_state_.eyelid_opening_upper;
73
    float eyelid_lower_left_target = eye_tilt_now - requested_gaze_state_.eyelid_opening_lower;
74 74

  
75 75
    // calculate right eyelid targets
76
    float eyelid_upper_right_target = eye_tilt_now + requested_gaze_state.eyelid_opening_upper;
77
    float eyelid_lower_right_target = eye_tilt_now - requested_gaze_state.eyelid_opening_lower;
76
    float eyelid_upper_right_target = eye_tilt_now + requested_gaze_state_.eyelid_opening_upper;
77
    float eyelid_lower_right_target = eye_tilt_now - requested_gaze_state_.eyelid_opening_lower;
78 78

  
79 79
    // limit target angles
80 80
    eyelid_upper_left_target  = limit_target(JointInterface::ID_EYES_LEFT_LID_UPPER,
......
87 87
                                             eyelid_lower_right_target);
88 88

  
89 89
    // (temporarily) store the target
90
    joint_interface->set_target(JointInterface::ID_EYES_LEFT_LID_UPPER,
90
    joint_interface_->set_target(JointInterface::ID_EYES_LEFT_LID_UPPER,
91 91
                                eyelid_upper_left_target, 0.0);
92
    joint_interface->set_target(JointInterface::ID_EYES_LEFT_LID_LOWER,
92
    joint_interface_->set_target(JointInterface::ID_EYES_LEFT_LID_LOWER,
93 93
                                eyelid_lower_left_target, 0.0);
94
    joint_interface->set_target(JointInterface::ID_EYES_RIGHT_LID_UPPER,
94
    joint_interface_->set_target(JointInterface::ID_EYES_RIGHT_LID_UPPER,
95 95
                                eyelid_upper_right_target, 0.0);
96
    joint_interface->set_target(JointInterface::ID_EYES_RIGHT_LID_LOWER,
96
    joint_interface_->set_target(JointInterface::ID_EYES_RIGHT_LID_LOWER,
97 97
                                eyelid_lower_right_target, 0.0);
98 98

  
99 99
    // check for saccade
100 100
    check_for_saccade();
101 101

  
102 102
    // is there a blink request?
103
    start_external_eyeblinks(requested_gaze_state.eyeblink_request_left,
104
                             requested_gaze_state.eyeblink_request_right);
103
    start_external_eyeblinks(requested_gaze_state_.eyeblink_request_left,
104
                             requested_gaze_state_.eyeblink_request_right);
105 105

  
106 106
    // do we have a saccade & do we want to exec an eyeblink?
107 107
    process_saccadic_eyeblinks();
......
121 121
    // manual eyeblinks will ALWAYs get executed as we use
122 122
    // a negative block timeout (=timeout has already passed)
123 123
    if ((duration_left != 0) || (duration_right != 0)) {
124
        eyeblink_blocked_timeout = boost::get_system_time() - boost::posix_time::seconds(100);
124
        eyeblink_blocked_timeout_ = boost::get_system_time() - boost::posix_time::seconds(100);
125 125
    }
126 126

  
127 127

  
......
129 129
        // nothing to do
130 130
    } else if (duration_left < 0) {
131 131
        // infinite sleep -> close
132
        eyelid_closed[LEFT] = true;
132
        eyelid_closed_[LEFT] = true;
133 133
    } else {
134 134
        // timeout sleep
135 135
        start_eyeblink(LEFT, duration_left);
136
        eyelid_closed[LEFT] = false;
136
        eyelid_closed_[LEFT] = false;
137 137
    }
138 138

  
139 139
    if (duration_right == 0) {
140 140
        // nothing to do
141 141
    } else if (duration_right < 0) {
142 142
        // infinite sleep -> close
143
        eyelid_closed[RIGHT] = true;
143
        eyelid_closed_[RIGHT] = true;
144 144
    } else {
145 145
        // timeout sleep
146 146
        start_eyeblink(RIGHT, duration_right);
147
        eyelid_closed[RIGHT] = false;
147
        eyelid_closed_[RIGHT] = false;
148 148
    }
149 149
}
150 150

  
151 151
//! process saccadic blink requests
152 152
//! -> when we do a saccade, the chances to blink are much higher
153 153
void EyelidMotionGenerator::process_saccadic_eyeblinks() {
154
    if (saccade_blink_requested) {
154
    if (saccade_blink_requested_) {
155 155
        // every n-th's saccade requests an eyeblink
156 156
        // here: use 0.3 even though humans use bigger prob value (but that looks stupid on robot)
157 157
        if ((std::rand()%3) == 0) {
......
159 159
            start_eyeblink(LEFT);
160 160
            start_eyeblink(RIGHT);
161 161
        }
162
        saccade_blink_requested = false;
162
        saccade_blink_requested_ = false;
163 163
    }
164 164
}
165 165

  
166 166
//! process periodic blink requests
167 167
//! -> we want to have an eyeblink every n...m seconds
168 168
void EyelidMotionGenerator::process_periodic_eyeblinks() {
169
    if (eyeblink_active[LEFT] || eyeblink_active[RIGHT]) {
169
    if (eyeblink_active_[LEFT] || eyeblink_active_[RIGHT]) {
170 170
        // calculate next timeout for a new periodic eyeblink
171 171
        int milliseconds_to_next_blink = EYEBLINK_EYERY_MS_MIN
172 172
                + (std::rand() % static_cast<int>(EYEBLINK_EYERY_MS_MAX-EYEBLINK_EYERY_MS_MIN));
173
        periodic_blink_start_time = boost::get_system_time()
173
        periodic_blink_start_time_ = boost::get_system_time()
174 174
                + boost::posix_time::milliseconds(milliseconds_to_next_blink);
175 175
    }
176 176

  
177
    if (boost::get_system_time() > periodic_blink_start_time) {
177
    if (boost::get_system_time() > periodic_blink_start_time_) {
178 178
        // printf("> periodic eyeblink:\n");
179 179
        start_eyeblink(LEFT);
180 180
        start_eyeblink(RIGHT);
......
188 188

  
189 189
    // take care of re-opening eye timeout
190 190
    for (int i=LEFT; i <= RIGHT; i++) {
191
        if (eyeblink_active[i]) {
192
            if (now >= eyeblink_timeout[i]) {
193
                eyeblink_active[i] = false;
191
        if (eyeblink_active_[i]) {
192
            if (now >= eyeblink_timeout_[i]) {
193
                eyeblink_active_[i] = false;
194 194
            }
195 195
        }
196 196
    }
197 197

  
198 198
    // take care of blocking time
199
    if (eyeblink_active[LEFT] || eyeblink_active[RIGHT]) {
200
        eyeblink_blocked_timeout = boost::get_system_time()
199
    if (eyeblink_active_[LEFT] || eyeblink_active_[RIGHT]) {
200
        eyeblink_blocked_timeout_ = boost::get_system_time()
201 201
                + boost::posix_time::milliseconds(EYEBLINK_BLOCKING_TIME);
202 202
    }
203 203
}
......
206 206
//! this will override (=close) the eyelids for all possible eyeblink requests
207 207
void EyelidMotionGenerator::override_lids_for_eyeblink() {
208 208
    // close the requested eyelids
209
    if (eyeblink_active[LEFT] || eyelid_closed[LEFT]) {
209
    if (eyeblink_active_[LEFT] || eyelid_closed_[LEFT]) {
210 210
        close_eyelid(JointInterface::ID_EYES_LEFT_LID_UPPER);
211 211
        close_eyelid(JointInterface::ID_EYES_LEFT_LID_LOWER);
212 212
    }
213
    if (eyeblink_active[RIGHT] || eyelid_closed[RIGHT]) {
213
    if (eyeblink_active_[RIGHT] || eyelid_closed_[RIGHT]) {
214 214
        close_eyelid(JointInterface::ID_EYES_RIGHT_LID_UPPER);
215 215
        close_eyelid(JointInterface::ID_EYES_RIGHT_LID_LOWER);
216 216
    }
......
232 232
    case(JointInterface::ID_EYES_LEFT_LID_UPPER):
233 233
    case(JointInterface::ID_EYES_LEFT_LID_LOWER):
234 234
        // use the upper value + 10 deg as close state:
235
        value = joint_interface->get_joint_min(JointInterface::ID_EYES_LEFT_LID_UPPER) + 10.0;
235
        value = joint_interface_->get_joint_min(JointInterface::ID_EYES_LEFT_LID_UPPER) + 10.0;
236 236
        // overwrite last target_
237
        joint_interface->set_target(joint_id, value, 0.0);
237
        joint_interface_->set_target(joint_id, value, 0.0);
238 238
        break;
239 239

  
240 240
    case(JointInterface::ID_EYES_RIGHT_LID_UPPER):
241 241
    case(JointInterface::ID_EYES_RIGHT_LID_LOWER):
242 242
        // use the upper value + 10 deg as close state:
243
        value = joint_interface->get_joint_min(JointInterface::ID_EYES_RIGHT_LID_UPPER) + 10.0;
243
        value = joint_interface_->get_joint_min(JointInterface::ID_EYES_RIGHT_LID_UPPER) + 10.0;
244 244
        // overwrite last target_
245
        joint_interface->set_target(joint_id, value, 0.0);
245
        joint_interface_->set_target(joint_id, value, 0.0);
246 246
        break;
247 247
    }
248 248
}
......
252 252
//! \param int id of side (LEFT or RIGHT)
253 253
void EyelidMotionGenerator::start_eyeblink(int side, int duration) {
254 254
    // cout << "BLOCKED UNTIL " << eyeblink_blocked_timeout << "\n";
255
    if (boost::get_system_time() < eyeblink_blocked_timeout) {
255
    if (boost::get_system_time() < eyeblink_blocked_timeout_) {
256 256
        // return if we are still in the block time
257 257
        return;
258 258
    }
259 259
    // request for n ms eyeblink:
260
    eyeblink_timeout[side] = boost::get_system_time() + boost::posix_time::milliseconds(duration);
260
    eyeblink_timeout_[side] = boost::get_system_time() + boost::posix_time::milliseconds(duration);
261 261

  
262
    eyeblink_active[side] = true;
262
    eyeblink_active_[side] = true;
263 263
}
264 264

  
265 265
//! check if there is an ongoing saccade:
266 266
void EyelidMotionGenerator::check_for_saccade() {
267 267
    if (get_eye_saccade_active()) {
268 268
        // this is a saccade, check if not already in saccade:
269
        if (!saccade_blink_active) {
269
        if (!saccade_blink_active_) {
270 270
            // this is a new saccade! restart blink timer
271
            saccade_blink_requested = true;
272
            saccade_blink_active = true;
271
            saccade_blink_requested_ = true;
272
            saccade_blink_active_ = true;
273 273
        }
274 274
    } else {
275
        saccade_blink_active = false;
275
        saccade_blink_active_ = false;
276 276
    }
277 277
}
278 278

  
......
281 281
void EyelidMotionGenerator::publish_targets() {
282 282
    // publish values if there is an active gaze input within the last timerange
283 283
    if (gaze_target_input_active()) {
284
        joint_interface->publish_target(JointInterface::ID_EYES_LEFT_LID_UPPER);
285
        joint_interface->publish_target(JointInterface::ID_EYES_LEFT_LID_LOWER);
286
        joint_interface->publish_target(JointInterface::ID_EYES_RIGHT_LID_UPPER);
287
        joint_interface->publish_target(JointInterface::ID_EYES_RIGHT_LID_LOWER);
284
        joint_interface_->publish_target(JointInterface::ID_EYES_LEFT_LID_UPPER);
285
        joint_interface_->publish_target(JointInterface::ID_EYES_LEFT_LID_LOWER);
286
        joint_interface_->publish_target(JointInterface::ID_EYES_RIGHT_LID_UPPER);
287
        joint_interface_->publish_target(JointInterface::ID_EYES_RIGHT_LID_LOWER);
288 288
    }
289 289
}

Also available in: Unified diff