Revision 7ed40bef
| src/client/middleware.cpp | ||
|---|---|---|
| 46 | 46 |
//! \param MouthState m to set |
| 47 | 47 |
//! \param send data to server (optional, use manual call to send_*() to trigger update on server) |
| 48 | 48 |
void Middleware::update_mouth_target(MouthState m, bool send){
|
| 49 |
mouth_state = m;
|
|
| 50 |
if (send){
|
|
| 51 |
send_mouth_target();
|
|
| 52 |
}
|
|
| 49 |
mouth_state = m;
|
|
| 50 |
if (send){
|
|
| 51 |
send_mouth_target();
|
|
| 52 |
}
|
|
| 53 | 53 |
} |
| 54 | 54 |
|
| 55 | 55 |
//! set gaze target |
| ... | ... | |
| 65 | 65 |
|
| 66 | 66 |
//! send all targets to server |
| 67 | 67 |
void Middleware::send_all(){
|
| 68 |
send_mouth_target();
|
|
| 68 |
send_mouth_target();
|
|
| 69 | 69 |
send_gaze_target(); |
| 70 | 70 |
} |
| 71 | 71 |
|
| src/client/middleware_ros.cpp | ||
|---|---|---|
| 54 | 54 |
tick_necessary = false; |
| 55 | 55 |
} |
| 56 | 56 |
|
| 57 |
//create node handle
|
|
| 57 |
//create node handle
|
|
| 58 | 58 |
ros::NodeHandle n; |
| 59 | 59 |
|
| 60 |
//set up publishers:
|
|
| 60 |
//set up publishers:
|
|
| 61 | 61 |
mouth_target_publisher = n.advertise<humotion::mouth>(base_scope + "/humotion/mouth/target", 100); |
| 62 | 62 |
gaze_target_publisher = n.advertise<humotion::gaze>(base_scope + "/humotion/gaze/target", 100); |
| 63 | 63 |
|
| src/server/eyebrow_motion_generator.cpp | ||
|---|---|---|
| 28 | 28 |
|
| 29 | 29 |
//! publish targets to motor boards: |
| 30 | 30 |
void EyebrowMotionGenerator::publish_targets(){
|
| 31 |
//publish values if there is an active gaze input within the last timerange |
|
| 32 |
if (gaze_target_input_active()){
|
|
| 33 |
joint_interface->publish_target_position(JointInterface::ID_EYES_LEFT_BROW); |
|
| 34 |
joint_interface->publish_target_position(JointInterface::ID_EYES_RIGHT_BROW); |
|
| 35 |
} |
|
| 31 |
//publish values if there is an active gaze input within the last timerange
|
|
| 32 |
if (gaze_target_input_active()){
|
|
| 33 |
joint_interface->publish_target_position(JointInterface::ID_EYES_LEFT_BROW);
|
|
| 34 |
joint_interface->publish_target_position(JointInterface::ID_EYES_RIGHT_BROW);
|
|
| 35 |
}
|
|
| 36 | 36 |
} |
| src/server/eyelid_motion_generator.cpp | ||
|---|---|---|
| 102 | 102 |
handle_eyeblink_timeout(); |
| 103 | 103 |
|
| 104 | 104 |
//eyeblinks override position target (if necessary) |
| 105 |
override_lids_for_eyeblink();
|
|
| 105 |
override_lids_for_eyeblink(); |
|
| 106 | 106 |
} |
| 107 | 107 |
|
| 108 | 108 |
//! process any external blink requests |
| 109 | 109 |
void EyelidMotionGenerator::start_external_eyeblinks(int duration_left, int duration_right){
|
| 110 | 110 |
//manual eyeblinks will ALWAYs get executed as we use a negative block timeout (=timout has already passed) |
| 111 | 111 |
if ((duration_left != 0) || (duration_right != 0)){
|
| 112 |
eyeblink_blocked_timeout = get_system_time() - posix_time::seconds(100);
|
|
| 112 |
eyeblink_blocked_timeout = get_system_time() - posix_time::seconds(100);
|
|
| 113 | 113 |
} |
| 114 | 114 |
|
| 115 | 115 |
|
| ... | ... | |
| 212 | 212 |
//set upper to minimal allowed value (=as closed as possible) + a small offset |
| 213 | 213 |
//set lower to the same value (instead of max) in order to avoid collisions |
| 214 | 214 |
switch(joint_id){
|
| 215 |
default:
|
|
| 216 |
//no eyelid -> return
|
|
| 217 |
return;
|
|
| 218 |
|
|
| 219 |
case(JointInterface::ID_EYES_LEFT_LID_UPPER):
|
|
| 220 |
case(JointInterface::ID_EYES_LEFT_LID_LOWER):
|
|
| 221 |
//use the upper value + 10 deg as close state:
|
|
| 222 |
value = joint_interface->get_joint_min(JointInterface::ID_EYES_LEFT_LID_UPPER) + 10.0;
|
|
| 223 |
//overwrite last target_
|
|
| 224 |
joint_interface->set_target_position(joint_id, value);
|
|
| 225 |
break;
|
|
| 226 |
|
|
| 227 |
case(JointInterface::ID_EYES_RIGHT_LID_UPPER):
|
|
| 228 |
case(JointInterface::ID_EYES_RIGHT_LID_LOWER):
|
|
| 229 |
//use the upper value + 10 deg as close state:
|
|
| 230 |
value = joint_interface->get_joint_min(JointInterface::ID_EYES_RIGHT_LID_UPPER) + 10.0;
|
|
| 231 |
//overwrite last target_
|
|
| 232 |
joint_interface->set_target_position(joint_id, value);
|
|
| 233 |
break;
|
|
| 215 |
default: |
|
| 216 |
//no eyelid -> return |
|
| 217 |
return; |
|
| 218 |
|
|
| 219 |
case(JointInterface::ID_EYES_LEFT_LID_UPPER): |
|
| 220 |
case(JointInterface::ID_EYES_LEFT_LID_LOWER): |
|
| 221 |
//use the upper value + 10 deg as close state: |
|
| 222 |
value = joint_interface->get_joint_min(JointInterface::ID_EYES_LEFT_LID_UPPER) + 10.0; |
|
| 223 |
//overwrite last target_ |
|
| 224 |
joint_interface->set_target_position(joint_id, value); |
|
| 225 |
break; |
|
| 226 |
|
|
| 227 |
case(JointInterface::ID_EYES_RIGHT_LID_UPPER): |
|
| 228 |
case(JointInterface::ID_EYES_RIGHT_LID_LOWER): |
|
| 229 |
//use the upper value + 10 deg as close state: |
|
| 230 |
value = joint_interface->get_joint_min(JointInterface::ID_EYES_RIGHT_LID_UPPER) + 10.0; |
|
| 231 |
//overwrite last target_ |
|
| 232 |
joint_interface->set_target_position(joint_id, value); |
|
| 233 |
break; |
|
| 234 | 234 |
} |
| 235 | 235 |
} |
| 236 | 236 |
|
| src/server/gaze_motion_generator.cpp | ||
|---|---|---|
| 92 | 92 |
float ud_max = OMR_LIMIT_TRIGGERS_NECK_SACCADE * joint_interface->get_joint_max(JointInterface::ID_EYES_BOTH_UD); |
| 93 | 93 |
|
| 94 | 94 |
if ( |
| 95 |
(eye_target_l < left_min) || (eye_target_l > left_max) || |
|
| 96 |
(eye_target_r < right_min) || (eye_target_r > right_max) || |
|
| 97 |
(eye_target_ud < ud_min) || (eye_target_ud > ud_max)){
|
|
| 95 |
(eye_target_l < left_min) || (eye_target_l > left_max) ||
|
|
| 96 |
(eye_target_r < right_min) || (eye_target_r > right_max) ||
|
|
| 97 |
(eye_target_ud < ud_min) || (eye_target_ud > ud_max)){
|
|
| 98 | 98 |
//the eyeball gets close to OMR, activate a neck compensation motion: |
| 99 | 99 |
neck_saccade_omr = true; |
| 100 | 100 |
}else{
|
| src/server/middleware_rsb.cpp | ||
|---|---|---|
| 142 | 142 |
gaze_state.eyeblink_request_right = msg->eyeblink_request_right(); |
| 143 | 143 |
|
| 144 | 144 |
gaze_state.timestamp = msg->gaze_timestamp(); FIXME: convert RSB timestamp to our representation |
| 145 |
//event->getMetaData().getCreateTime() / 1000.0; //createTime() returns milliseconds -> convert to seconds |
|
| 145 |
//event->getMetaData().getCreateTime() / 1000.0; //createTime() returns milliseconds -> convert to seconds
|
|
| 146 | 146 |
|
| 147 |
controller->set_gaze_target(gaze_state); |
|
| 147 |
controller->set_gaze_target(gaze_state);
|
|
| 148 | 148 |
} |
| 149 | 149 |
|
| 150 | 150 |
#endif |
| src/server/mouth_motion_generator.cpp | ||
|---|---|---|
| 104 | 104 |
//! \param int enum with joint id |
| 105 | 105 |
float MouthMotionGenerator::mouthstate_to_opening(MouthState m, int e){
|
| 106 | 106 |
switch (e){
|
| 107 |
default: printf("> get_opening(0x%02X): invalid joint enum!\n",e); exit(0);
|
|
| 108 |
case(JointInterface::ID_LIP_LEFT_UPPER):
|
|
| 109 |
case(JointInterface::ID_LIP_LEFT_LOWER):
|
|
| 110 |
return m.opening_left;
|
|
| 111 |
case(JointInterface::ID_LIP_CENTER_UPPER):
|
|
| 112 |
case(JointInterface::ID_LIP_CENTER_LOWER):
|
|
| 113 |
return m.opening_center;
|
|
| 114 |
case(JointInterface::ID_LIP_RIGHT_UPPER):
|
|
| 115 |
case(JointInterface::ID_LIP_RIGHT_LOWER):
|
|
| 116 |
return m.opening_right;
|
|
| 107 |
default: printf("> get_opening(0x%02X): invalid joint enum!\n",e); exit(0);
|
|
| 108 |
case(JointInterface::ID_LIP_LEFT_UPPER): |
|
| 109 |
case(JointInterface::ID_LIP_LEFT_LOWER): |
|
| 110 |
return m.opening_left; |
|
| 111 |
case(JointInterface::ID_LIP_CENTER_UPPER): |
|
| 112 |
case(JointInterface::ID_LIP_CENTER_LOWER): |
|
| 113 |
return m.opening_center; |
|
| 114 |
case(JointInterface::ID_LIP_RIGHT_UPPER): |
|
| 115 |
case(JointInterface::ID_LIP_RIGHT_LOWER): |
|
| 116 |
return m.opening_right; |
|
| 117 | 117 |
} |
| 118 | 118 |
} |
| 119 | 119 |
|
| ... | ... | |
| 122 | 122 |
//! \param int enum with joint id |
| 123 | 123 |
float MouthMotionGenerator::mouthstate_to_position(MouthState m, int e){
|
| 124 | 124 |
switch (e){
|
| 125 |
default: printf("> get_position(0x%02X): invalid joint enum!\n",e); exit(0);
|
|
| 126 |
case(JointInterface::ID_LIP_LEFT_UPPER):
|
|
| 127 |
case(JointInterface::ID_LIP_LEFT_LOWER):
|
|
| 128 |
return m.position_left;
|
|
| 129 |
case(JointInterface::ID_LIP_CENTER_UPPER):
|
|
| 130 |
case(JointInterface::ID_LIP_CENTER_LOWER):
|
|
| 131 |
return m.position_center;
|
|
| 132 |
case(JointInterface::ID_LIP_RIGHT_UPPER):
|
|
| 133 |
case(JointInterface::ID_LIP_RIGHT_LOWER):
|
|
| 134 |
return m.position_right;
|
|
| 125 |
default: printf("> get_position(0x%02X): invalid joint enum!\n",e); exit(0);
|
|
| 126 |
case(JointInterface::ID_LIP_LEFT_UPPER): |
|
| 127 |
case(JointInterface::ID_LIP_LEFT_LOWER): |
|
| 128 |
return m.position_left; |
|
| 129 |
case(JointInterface::ID_LIP_CENTER_UPPER): |
|
| 130 |
case(JointInterface::ID_LIP_CENTER_LOWER): |
|
| 131 |
return m.position_center; |
|
| 132 |
case(JointInterface::ID_LIP_RIGHT_UPPER): |
|
| 133 |
case(JointInterface::ID_LIP_RIGHT_LOWER): |
|
| 134 |
return m.position_right; |
|
| 135 | 135 |
} |
| 136 | 136 |
} |
| 137 | 137 |
|
| src/server/server.cpp | ||
|---|---|---|
| 106 | 106 |
|
| 107 | 107 |
unsigned int incoming_data_count = joint_interface->get_and_clear_incoming_position_count(); |
| 108 | 108 |
if (incoming_data_count == 0){
|
| 109 |
incoming_data_count_invalid++;
|
|
| 110 |
if (incoming_data_count_invalid >= MOTION_UPDATERATE){
|
|
| 111 |
printf("> waiting for valid incoming joint data (position+velocity)\n");
|
|
| 112 |
incoming_data_count_invalid = 0;
|
|
| 113 |
}
|
|
| 109 |
incoming_data_count_invalid++; |
|
| 110 |
if (incoming_data_count_invalid >= MOTION_UPDATERATE){
|
|
| 111 |
printf("> waiting for valid incoming joint data (position+velocity)\n");
|
|
| 112 |
incoming_data_count_invalid = 0; |
|
| 113 |
} |
|
| 114 | 114 |
}else{
|
| 115 | 115 |
//fine, joint data is arriving, exit waiting loop |
| 116 | 116 |
break; |
| ... | ... | |
| 143 | 143 |
//check if we received joint information in the last step: |
| 144 | 144 |
unsigned int incoming_data_count = joint_interface->get_and_clear_incoming_position_count(); |
| 145 | 145 |
if (incoming_data_count == 0){
|
| 146 |
//printf("> WARNING: no incoming joint data during the last iteration...\n");
|
|
| 147 |
incoming_data_count_invalid++;
|
|
| 148 |
if (incoming_data_count_invalid >= MOTION_UPDATERATE){
|
|
| 149 |
printf("> ERROR: no incoming joint data for >1 second -> will exit now\n");
|
|
| 150 |
exit(EXIT_FAILURE);
|
|
| 151 |
}
|
|
| 146 |
//printf("> WARNING: no incoming joint data during the last iteration...\n");
|
|
| 147 |
incoming_data_count_invalid++; |
|
| 148 |
if (incoming_data_count_invalid >= MOTION_UPDATERATE){
|
|
| 149 |
printf("> ERROR: no incoming joint data for >1 second -> will exit now\n");
|
|
| 150 |
exit(EXIT_FAILURE); |
|
| 151 |
} |
|
| 152 | 152 |
}else{
|
| 153 |
incoming_data_count_invalid = 0;
|
|
| 153 |
incoming_data_count_invalid = 0; |
|
| 154 | 154 |
} |
| 155 | 155 |
|
| 156 | 156 |
thread::sleep(timeout); |
| src/timestamped_list.cpp | ||
|---|---|---|
| 33 | 33 |
using namespace humotion; |
| 34 | 34 |
|
| 35 | 35 |
TimestampedList::TimestampedList(unsigned int s){
|
| 36 |
//initialize the list to its desired size:
|
|
| 36 |
//initialize the list to its desired size:
|
|
| 37 | 37 |
TimestampedFloat now; |
| 38 | 38 |
tsf_list.resize(s, now); |
| 39 | 39 |
} |
| ... | ... | |
| 73 | 73 |
} |
| 74 | 74 |
|
| 75 | 75 |
void TimestampedList::insert(Timestamp timestamp, float val){
|
| 76 |
//erase first element:
|
|
| 76 |
//erase first element:
|
|
| 77 | 77 |
tsf_list.pop_front(); |
| 78 | 78 |
tsf_list.push_back(TimestampedFloat(timestamp, val)); |
| 79 | 79 |
//printf("insert [%5.3f] = %5.1f\n",timestamp,val);
|
| ... | ... | |
| 91 | 91 |
} |
| 92 | 92 |
|
| 93 | 93 |
timestamped_float_list_t::iterator it = tsf_list.end(); |
| 94 |
it--;
|
|
| 95 |
return it->value;
|
|
| 94 |
it--;
|
|
| 95 |
return it->value;
|
|
| 96 | 96 |
} |
| 97 | 97 |
|
| 98 | 98 |
float TimestampedList::get_interpolated_value(Timestamp target_ts){
|
| ... | ... | |
| 102 | 102 |
mutex::scoped_lock scoped_lock(access_mutex); |
| 103 | 103 |
|
| 104 | 104 |
///target_ts -= 0.001 * 4; |
| 105 |
|
|
| 105 |
|
|
| 106 | 106 |
TimestampedFloat previous; |
| 107 | 107 |
//printf("> latency %3.2fms\n", (Timestamped().to_seconds() - target_ts.to_seconds())*1000.0);
|
| 108 | 108 |
|
| 109 | 109 |
for ( timestamped_float_list_t::iterator it = tsf_list.begin(); it != tsf_list.end(); ++it ){
|
| 110 |
if (it->timestamp >= target_ts){
|
|
| 111 |
//ok found close target
|
|
| 110 |
if (it->timestamp >= target_ts){
|
|
| 111 |
//ok found close target
|
|
| 112 | 112 |
if (it == tsf_list.begin()){
|
| 113 |
//no preceding element
|
|
| 113 |
//no preceding element
|
|
| 114 | 114 |
printf("> warning, timestamp %6.3f smaller than first element %6.3f in timestamped list. this should not happen (increase ts buffer?)\n",target_ts.to_seconds(),tsf_list.begin()->timestamp.to_seconds());
|
| 115 |
return it->value;
|
|
| 116 |
}else{
|
|
| 117 |
//do interpolation
|
|
| 118 |
return interpolate(*it, previous, target_ts);
|
|
| 119 |
}
|
|
| 120 |
}
|
|
| 121 |
previous = *it;
|
|
| 122 |
}
|
|
| 123 |
|
|
| 124 |
//we reached the end, return the last value
|
|
| 115 |
return it->value;
|
|
| 116 |
}else{
|
|
| 117 |
//do interpolation
|
|
| 118 |
return interpolate(*it, previous, target_ts);
|
|
| 119 |
}
|
|
| 120 |
}
|
|
| 121 |
previous = *it;
|
|
| 122 |
}
|
|
| 123 |
|
|
| 124 |
//we reached the end, return the last value
|
|
| 125 | 125 |
printf("> warning: found no timestamp bigger than %f in timestamped list...\n", target_ts.to_seconds());
|
| 126 |
printf(" this should not happen as images will always be behind\n");
|
|
| 126 |
printf(" this should not happen as images will always be behind\n");
|
|
| 127 | 127 |
printf(" the motor data. returning most recent value (ts=%f)\n", previous.timestamp.to_seconds());
|
| 128 |
|
|
| 129 |
return previous.value;
|
|
| 128 |
|
|
| 129 |
return previous.value;
|
|
| 130 | 130 |
} |
| 131 | 131 |
|
| 132 | 132 |
float TimestampedList::interpolate(TimestampedFloat a, TimestampedFloat b, Timestamp timestamp){
|
| 133 |
//a->timestamp < timestamp <= b->timestamp
|
|
| 133 |
//a->timestamp < timestamp <= b->timestamp
|
|
| 134 | 134 |
double dist_a = timestamp.to_seconds() - a.timestamp.to_seconds(); |
| 135 | 135 |
double dist_b = b.timestamp.to_seconds() - timestamp.to_seconds(); |
| 136 |
double dist = dist_a + dist_b;
|
|
| 137 |
|
|
| 136 |
double dist = dist_a + dist_b;
|
|
| 137 |
|
|
| 138 | 138 |
float interpolation = a.value + (dist_a / dist) * (b.value - a.value); |
| 139 |
return interpolation;
|
|
| 139 |
return interpolation;
|
|
| 140 | 140 |
} |
| 141 | 141 |
|
| 142 | 142 |
|
| 143 | 143 |
///tests |
| 144 | 144 |
void TimestampedList::run_tests(){
|
| 145 |
int size = 10;
|
|
| 146 |
TimestampedList list(size);
|
|
| 147 |
|
|
| 148 |
for(int i=0; i<size; i++){
|
|
| 145 |
int size = 10;
|
|
| 146 |
TimestampedList list(size);
|
|
| 147 |
|
|
| 148 |
for(int i=0; i<size; i++){
|
|
| 149 | 149 |
list.insert(Timestamp(i * 100.0,0), i*10.0); |
| 150 |
}
|
|
| 151 |
|
|
| 152 |
//test algorithm:
|
|
| 153 |
|
|
| 154 |
//test exact match:
|
|
| 155 |
for(int i=0; i<size; i++){
|
|
| 150 |
}
|
|
| 151 |
|
|
| 152 |
//test algorithm:
|
|
| 153 |
|
|
| 154 |
//test exact match:
|
|
| 155 |
for(int i=0; i<size; i++){
|
|
| 156 | 156 |
Timestamp ts(i*100.0,0); |
| 157 | 157 |
printf("> testing get_interpolated_value(%f) == %f (value read back = %f)\n",ts.to_seconds(), i*10.0, list.get_interpolated_value(ts));
|
| 158 | 158 |
assert( list.get_interpolated_value(ts) == i*10.0); |
| 159 |
}
|
|
| 160 |
printf("passed test 1\n");
|
|
| 161 |
|
|
| 159 |
}
|
|
| 160 |
printf("passed test 1\n");
|
|
| 161 |
|
|
| 162 | 162 |
assert(list.get_interpolated_value(Timestamp(0.0,0)) == 0.0); |
| 163 | 163 |
assert(list.get_interpolated_value(Timestamp(110.0,0)) == 11.0); |
| 164 | 164 |
assert(list.get_interpolated_value(Timestamp(150.0,0)) == 15.0); |
| 165 | 165 |
assert(list.get_interpolated_value(Timestamp(999990.0,0)) == 90.0); |
| 166 |
|
|
| 167 |
printf("passed test 2\n");
|
|
| 168 |
|
|
| 166 |
|
|
| 167 |
printf("passed test 2\n");
|
|
| 168 |
|
|
| 169 | 169 |
list.insert(Timestamp(1000.0 ,0), 200.0); |
| 170 | 170 |
list.insert(Timestamp(1300.0, 0), -100.0); |
| 171 | 171 |
assert(list.get_interpolated_value(Timestamp(1100, 0)) == 100.0); |
| 172 | 172 |
assert(list.get_interpolated_value(Timestamp(1200, 0)) == 0.0); |
| 173 | 173 |
assert(list.get_interpolated_value(Timestamp(1300, 0)) == -100.0); |
| 174 | 174 |
assert(list.get_interpolated_value(Timestamp(1250, 0)) == -50.0); |
| 175 |
|
|
| 176 |
printf("passed test 3\n");
|
|
| 177 |
exit(0);
|
|
| 175 |
|
|
| 176 |
printf("passed test 3\n");
|
|
| 177 |
exit(0);
|
|
| 178 | 178 |
} |
Also available in: Unified diff