humotion / src / server / gaze_motion_generator.cpp @ 4e61b076
History | View | Annotate | Download (6.061 KB)
| 1 | 8c6c1163 | Simon Schulz | /*
|
|---|---|---|---|
| 2 | * This file is part of humotion
|
||
| 3 | *
|
||
| 4 | * Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
|
||
| 5 | * http://opensource.cit-ec.de/projects/humotion
|
||
| 6 | *
|
||
| 7 | * This file may be licensed under the terms of the
|
||
| 8 | * GNU Lesser General Public License Version 3 (the ``LGPL''),
|
||
| 9 | * or (at your option) any later version.
|
||
| 10 | *
|
||
| 11 | * Software distributed under the License is distributed
|
||
| 12 | * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
|
||
| 13 | * express or implied. See the LGPL for the specific language
|
||
| 14 | * governing rights and limitations.
|
||
| 15 | *
|
||
| 16 | * You should have received a copy of the LGPL along with this
|
||
| 17 | * program. If not, go to http://www.gnu.org/licenses/lgpl.html
|
||
| 18 | * or write to the Free Software Foundation, Inc.,
|
||
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
| 20 | *
|
||
| 21 | * The development of this software was supported by the
|
||
| 22 | * Excellence Cluster EXC 277 Cognitive Interaction Technology.
|
||
| 23 | * The Excellence Cluster EXC 277 is a grant of the Deutsche
|
||
| 24 | * Forschungsgemeinschaft (DFG) in the context of the German
|
||
| 25 | * Excellence Initiative.
|
||
| 26 | */
|
||
| 27 | |||
| 28 | #include "server/gaze_motion_generator.h" |
||
| 29 | #include "server/server.h" |
||
| 30 | |||
| 31 | using namespace std; |
||
| 32 | using namespace humotion; |
||
| 33 | using namespace humotion::server; |
||
| 34 | |||
| 35 | //saccade detection threshold in deg/s
|
||
| 36 | ///const float GazeMotionGenerator::SACCADE_SPEED_THRESHOLD = 15.0;
|
||
| 37 | //some constants to decide if the requested move will trigger a neck or eye saccade
|
||
| 38 | const float GazeMotionGenerator::NECK_SACCADE_THRESHOLD = 15.0; //deg |
||
| 39 | const float GazeMotionGenerator::EYE_SACCADE_SPEED_THRESHOLD = 15.0; //deg/s |
||
| 40 | //close to ocolumotor-range?
|
||
| 41 | const float GazeMotionGenerator::OMR_LIMIT_TRIGGERS_NECK_SACCADE = 0.95; //0.95 = reaching 95% of OMR will trigger a correction |
||
| 42 | |||
| 43 | |||
| 44 | //! constructor
|
||
| 45 | GazeMotionGenerator::GazeMotionGenerator(JointInterface *j, int dof, float t) : ReflexxesMotionGenerator(j, dof, t){ |
||
| 46 | } |
||
| 47 | |||
| 48 | //! destructor
|
||
| 49 | GazeMotionGenerator::~GazeMotionGenerator(){
|
||
| 50 | } |
||
| 51 | |||
| 52 | //! update gaze target:
|
||
| 53 | //! \param GazeState with target values for the overall gaze
|
||
| 54 | void GazeMotionGenerator::set_gaze_target(GazeState new_gaze_target){
|
||
| 55 | 1c758459 | Simon Schulz | if (requested_gaze_state.gaze_type == GazeState::GAZETYPE_RELATIVE){
|
| 56 | printf("> ERROR: gaze targets should be converted to absolute before calling this\n");
|
||
| 57 | exit(EXIT_FAILURE); |
||
| 58 | 8c6c1163 | Simon Schulz | } |
| 59 | |||
| 60 | //check magnitude of gaze change to detect eye-neck saccades:
|
||
| 61 | float dist = fabs(requested_gaze_state.distance_pt_abs(new_gaze_target));
|
||
| 62 | |||
| 63 | //check requested speed
|
||
| 64 | float speed = fabs(requested_gaze_state.distance_pt_abs(new_gaze_target)) / (new_gaze_target.timestamp-requested_gaze_state.timestamp);
|
||
| 65 | |||
| 66 | //check magnitude and speed of gaze change to detect eye-neck saccades:
|
||
| 67 | if (dist > NECK_SACCADE_THRESHOLD){
|
||
| 68 | //the next saccade has to use neck motion as well
|
||
| 69 | if (speed > EYE_SACCADE_SPEED_THRESHOLD){
|
||
| 70 | neck_saccade_requested = true;
|
||
| 71 | } |
||
| 72 | }else{
|
||
| 73 | neck_saccade_requested = false;
|
||
| 74 | } |
||
| 75 | |||
| 76 | //check for eye getting close to ocolomotor range
|
||
| 77 | float eye_pos_l = joint_interface->get_ts_position(JointInterface::ID_EYES_LEFT_LR).get_newest_value();
|
||
| 78 | float eye_pos_r = joint_interface->get_ts_position(JointInterface::ID_EYES_RIGHT_LR).get_newest_value();
|
||
| 79 | float eye_pos_ud = joint_interface->get_ts_position(JointInterface::ID_EYES_BOTH_UD).get_newest_value();
|
||
| 80 | |||
| 81 | //min/max bounds:
|
||
| 82 | float left_min = OMR_LIMIT_TRIGGERS_NECK_SACCADE * joint_interface->get_joint_min(JointInterface::ID_EYES_LEFT_LR);
|
||
| 83 | float left_max = OMR_LIMIT_TRIGGERS_NECK_SACCADE * joint_interface->get_joint_max(JointInterface::ID_EYES_LEFT_LR);
|
||
| 84 | float right_min = OMR_LIMIT_TRIGGERS_NECK_SACCADE * joint_interface->get_joint_min(JointInterface::ID_EYES_RIGHT_LR);
|
||
| 85 | float right_max = OMR_LIMIT_TRIGGERS_NECK_SACCADE * joint_interface->get_joint_max(JointInterface::ID_EYES_RIGHT_LR);
|
||
| 86 | float ud_min = OMR_LIMIT_TRIGGERS_NECK_SACCADE * joint_interface->get_joint_min(JointInterface::ID_EYES_BOTH_UD);
|
||
| 87 | float ud_max = OMR_LIMIT_TRIGGERS_NECK_SACCADE * joint_interface->get_joint_max(JointInterface::ID_EYES_BOTH_UD);
|
||
| 88 | |||
| 89 | if (
|
||
| 90 | (eye_pos_l < left_min) || (eye_pos_l > left_max) || |
||
| 91 | (eye_pos_r < right_min) || (eye_pos_r > right_max) || |
||
| 92 | (eye_pos_ud < ud_min) || (eye_pos_ud > ud_max)){
|
||
| 93 | //the eyeball gets close to OMR, activate a neck compensation motion:
|
||
| 94 | neck_saccade_omr = true;
|
||
| 95 | }else{
|
||
| 96 | neck_saccade_omr = false;
|
||
| 97 | } |
||
| 98 | |||
| 99 | //use base class set method:
|
||
| 100 | MotionGenerator::set_gaze_target(new_gaze_target); |
||
| 101 | } |
||
| 102 | |||
| 103 | //! check if an eye saccade is active:
|
||
| 104 | bool GazeMotionGenerator::get_eye_saccade_active(){
|
||
| 105 | bool saccade_active;
|
||
| 106 | |||
| 107 | float speed_left = joint_interface->get_ts_speed(JointInterface::ID_EYES_LEFT_LR).get_newest_value();
|
||
| 108 | float speed_right = joint_interface->get_ts_speed(JointInterface::ID_EYES_RIGHT_LR).get_newest_value();
|
||
| 109 | float speed_tilt = joint_interface->get_ts_speed(JointInterface::ID_EYES_BOTH_UD).get_newest_value();
|
||
| 110 | |||
| 111 | float speed_total_l = sqrt(speed_left*speed_left + speed_tilt*speed_tilt);
|
||
| 112 | float speed_total_r = sqrt(speed_right*speed_right + speed_tilt*speed_tilt);
|
||
| 113 | |||
| 114 | //thresholding
|
||
| 115 | if ((speed_total_l > EYE_SACCADE_SPEED_THRESHOLD) || (speed_total_r > EYE_SACCADE_SPEED_THRESHOLD)){
|
||
| 116 | //this is a saccade
|
||
| 117 | saccade_active = true;
|
||
| 118 | }else{
|
||
| 119 | saccade_active = false;
|
||
| 120 | } |
||
| 121 | |||
| 122 | return saccade_active;
|
||
| 123 | } |
||
| 124 | |||
| 125 | //! get overall gaze
|
||
| 126 | GazeState GazeMotionGenerator::get_current_gaze(){
|
||
| 127 | //shortcut, makes the following easier to read
|
||
| 128 | JointInterface *j = joint_interface; |
||
| 129 | |||
| 130 | GazeState gaze = requested_gaze_state; |
||
| 131 | |||
| 132 | gaze.pan = j->get_ts_position(JointInterface::ID_NECK_PAN).get_newest_value() + |
||
| 133 | (j->get_ts_position(JointInterface::ID_EYES_LEFT_LR).get_newest_value() + j->get_ts_position(JointInterface::ID_EYES_RIGHT_LR).get_newest_value())/2.0; |
||
| 134 | gaze.tilt = j->get_ts_position(JointInterface::ID_NECK_TILT).get_newest_value() + j->get_ts_position(JointInterface::ID_EYES_BOTH_UD).get_newest_value(); |
||
| 135 | gaze.roll = j->get_ts_position(JointInterface::ID_NECK_ROLL).get_newest_value(); |
||
| 136 | |||
| 137 | gaze.vergence = j->get_ts_position(JointInterface::ID_EYES_LEFT_LR).get_newest_value() - j->get_ts_position(JointInterface::ID_EYES_RIGHT_LR).get_newest_value(); |
||
| 138 | |||
| 139 | return gaze;
|
||
| 140 | } |