Revision 6d13138a src/server/eyelid_motion_generator.cpp
src/server/eyelid_motion_generator.cpp | ||
---|---|---|
34 | 34 |
// using namespace humotion::server; |
35 | 35 |
|
36 | 36 |
using humotion::server::EyelidMotionGenerator; |
37 |
|
|
38 |
// saccade detection threshold in deg/s |
|
39 |
const float EyelidMotionGenerator::SACCADE_SPEED_THRESHOLD = 15.0; // deg/s |
|
40 |
// eyeblink duration: |
|
41 |
const float EyelidMotionGenerator::EYEBLINK_DURATION_MS = 150.0; // ms |
|
42 |
// periodic eyeblinks: every 2..10s: |
|
43 |
const float EyelidMotionGenerator::EYEBLINK_EYERY_MS_MIN = 2000.0; // ms |
|
44 |
const float EyelidMotionGenerator::EYEBLINK_EYERY_MS_MAX = 10000.0; // ms |
|
45 |
// how many seconds do we block further blinks after each eyeblink? |
|
46 |
const float EyelidMotionGenerator::EYEBLINK_BLOCKING_TIME = 1000.0; // ms |
|
37 |
using humotion::server::Config; |
|
47 | 38 |
|
48 | 39 |
//! constructor |
49 |
EyelidMotionGenerator::EyelidMotionGenerator(JointInterface *j) : EyeMotionGenerator(j) { |
|
40 |
EyelidMotionGenerator::EyelidMotionGenerator(JointInterface *j, Config *cfg) : |
|
41 |
EyeMotionGenerator(j, cfg) { |
|
50 | 42 |
saccade_blink_active_ = false; |
51 | 43 |
saccade_blink_requested_ = false; |
52 | 44 |
eyelid_closed_[LEFT] = false; |
... | ... | |
153 | 145 |
void EyelidMotionGenerator::process_saccadic_eyeblinks() { |
154 | 146 |
if (saccade_blink_requested_) { |
155 | 147 |
// every n-th's saccade requests an eyeblink |
156 |
// here: use 0.3 even though humans use bigger prob value (but that looks stupid on robot)
|
|
157 |
if ((std::rand()%3) == 0) {
|
|
158 |
// printf("> saccadic eyeblink:\n");
|
|
159 |
start_eyeblink(LEFT); |
|
160 |
start_eyeblink(RIGHT); |
|
148 |
float frnd = static_cast <float> (std::rand()) / static_cast <float> (RAND_MAX);
|
|
149 |
if (frnd <= config->eyeblink_probability_after_saccade) {
|
|
150 |
printf("> saccadic eyeblink:\n"); |
|
151 |
start_eyeblink(LEFT, config->eyeblink_duration * 1000.0);
|
|
152 |
start_eyeblink(RIGHT, config->eyeblink_duration * 1000.0);
|
|
161 | 153 |
} |
162 | 154 |
saccade_blink_requested_ = false; |
163 | 155 |
} |
... | ... | |
167 | 159 |
//! -> we want to have an eyeblink every n...m seconds |
168 | 160 |
void EyelidMotionGenerator::process_periodic_eyeblinks() { |
169 | 161 |
if (eyeblink_active_[LEFT] || eyeblink_active_[RIGHT]) { |
162 |
float range = config->eyeblink_periodic_distribution_upper |
|
163 |
- config->eyeblink_periodic_distribution_lower; |
|
164 |
|
|
165 |
// random number 0...1 |
|
166 |
float frnd = static_cast <float> (std::rand()) / static_cast <float> (RAND_MAX); |
|
167 |
|
|
170 | 168 |
// calculate next timeout for a new periodic eyeblink |
171 |
int milliseconds_to_next_blink = EYEBLINK_EYERY_MS_MIN |
|
172 |
+ (std::rand() % static_cast<int>(EYEBLINK_EYERY_MS_MAX-EYEBLINK_EYERY_MS_MIN)); |
|
169 |
float seconds_to_next_blink = |
|
170 |
config->eyeblink_periodic_distribution_lower + frnd * range; |
|
171 |
|
|
173 | 172 |
periodic_blink_start_time_ = boost::get_system_time() |
174 |
+ boost::posix_time::milliseconds(milliseconds_to_next_blink);
|
|
173 |
+ boost::posix_time::seconds(seconds_to_next_blink);
|
|
175 | 174 |
} |
176 | 175 |
|
177 | 176 |
if (boost::get_system_time() > periodic_blink_start_time_) { |
178 | 177 |
// printf("> periodic eyeblink:\n"); |
179 |
start_eyeblink(LEFT); |
|
180 |
start_eyeblink(RIGHT); |
|
178 |
start_eyeblink(LEFT, config->eyeblink_duration * 1000.0);
|
|
179 |
start_eyeblink(RIGHT, config->eyeblink_duration * 1000.0);
|
|
181 | 180 |
} |
182 | 181 |
} |
183 | 182 |
|
... | ... | |
198 | 197 |
// take care of blocking time |
199 | 198 |
if (eyeblink_active_[LEFT] || eyeblink_active_[RIGHT]) { |
200 | 199 |
eyeblink_blocked_timeout_ = boost::get_system_time() |
201 |
+ boost::posix_time::milliseconds(EYEBLINK_BLOCKING_TIME);
|
|
200 |
+ boost::posix_time::seconds(config->eyeblink_blocked_time);
|
|
202 | 201 |
} |
203 | 202 |
} |
204 | 203 |
|
Also available in: Unified diff