Revision 0c8d22a5 src/server/gaze_motion_generator.cpp

View differences:

src/server/gaze_motion_generator.cpp
25 25
* Excellence Initiative.
26 26
*/
27 27

  
28
#include "server/gaze_motion_generator.h"
29
#include "server/server.h"
28
#include "humotion/server/gaze_motion_generator.h"
29
#include "humotion/server/server.h"
30 30

  
31
using namespace std;
32
using namespace humotion;
33
using namespace humotion::server;
31
using humotion::server::GazeMotionGenerator;
34 32

  
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
33
// saccade detection threshold in deg/s
34
// const float GazeMotionGenerator::SACCADE_SPEED_THRESHOLD = 15.0;
35
// some constants to decide if the requested move will trigger a neck or eye saccade
36
const float GazeMotionGenerator::NECK_SACCADE_THRESHOLD      = 15.0;  // deg
37
const float GazeMotionGenerator::EYE_SACCADE_SPEED_THRESHOLD = 15.0;  // deg/s
38

  
39
// close to ocolumotor-range?
40
// 0.95 = reaching 95% of OMR will trigger a correction
41
const float GazeMotionGenerator::OMR_LIMIT_TRIGGERS_NECK_SACCADE = 0.95;
42 42

  
43 43

  
44 44
//! constructor
45 45
GazeMotionGenerator::GazeMotionGenerator(JointInterface *j, int dof, float t)
46
    : ReflexxesMotionGenerator(j, dof, t){
46
    : ReflexxesMotionGenerator(j, dof, t) {
47 47
}
48 48

  
49 49
//! destructor
50
GazeMotionGenerator::~GazeMotionGenerator(){
50
GazeMotionGenerator::~GazeMotionGenerator() {
51 51
}
52 52

  
53 53
//! update gaze target:
54 54
//! \param GazeState with target values for the overall gaze
55
void GazeMotionGenerator::set_gaze_target(GazeState new_gaze_target){
56
    if (requested_gaze_state.gaze_type == GazeState::GAZETYPE_RELATIVE){
55
void GazeMotionGenerator::set_gaze_target(GazeState new_gaze_target) {
56
    if (requested_gaze_state.gaze_type == GazeState::GAZETYPE_RELATIVE) {
57 57
        printf("> ERROR: gaze targets should be converted to absolute before calling this\n");
58 58
        exit(EXIT_FAILURE);
59 59
    }
60 60

  
61
    //check magnitude of gaze change to detect eye-neck saccades:
61
    // check magnitude of gaze change to detect eye-neck saccades
62 62
    float dist = fabs(requested_gaze_state.distance_pt_abs(new_gaze_target));
63 63

  
64
    //check requested speed
65
    float speed = fabs(requested_gaze_state.distance_pt_abs(new_gaze_target)) / (new_gaze_target.timestamp.to_seconds()-requested_gaze_state.timestamp.to_seconds());
64
    // check requested speed
65
    float speed = fabs(requested_gaze_state.distance_pt_abs(new_gaze_target))
66
            / (new_gaze_target.timestamp.to_seconds()-requested_gaze_state.timestamp.to_seconds());
66 67

  
67
    //check magnitude and speed of gaze change to detect eye-neck saccades:
68
    if (dist > NECK_SACCADE_THRESHOLD){
69
        //the next saccade has to use neck motion as well
70
        if (speed > EYE_SACCADE_SPEED_THRESHOLD){
68
    // check magnitude and speed of gaze change to detect eye-neck saccades
69
    if (dist > NECK_SACCADE_THRESHOLD) {
70
        // the next saccade has to use neck motion as well
71
        if (speed > EYE_SACCADE_SPEED_THRESHOLD) {
71 72
            neck_saccade_requested = true;
72 73
        }
73
    }else{
74
    } else {
74 75
        neck_saccade_requested = false;
75 76
    }
76 77

  
77
    //check for eye getting close to ocolomotor range
78
    //float eye_pos_l = joint_interface->get_ts_position(JointInterface::ID_EYES_LEFT_LR).get_newest_value();
79
    //float eye_pos_r = joint_interface->get_ts_position(JointInterface::ID_EYES_RIGHT_LR).get_newest_value();
80
    //float eye_pos_ud = joint_interface->get_ts_position(JointInterface::ID_EYES_BOTH_UD).get_newest_value();
81
    //actually it makes more sense to trigger the neck saccade based on the target getting out of the OMR
78
    // check for eye getting close to ocolomotor range
79
    // actually it makes more sense to trigger the neck saccade based on
80
    // the target getting out of the OMR
82 81
    float eye_target_l  = joint_interface->get_target_position(JointInterface::ID_EYES_LEFT_LR);
83 82
    float eye_target_r  = joint_interface->get_target_position(JointInterface::ID_EYES_RIGHT_LR);
84 83
    float eye_target_ud = joint_interface->get_target_position(JointInterface::ID_EYES_BOTH_UD);
85 84

  
86
    //min/max bounds:
87
    float left_min  = OMR_LIMIT_TRIGGERS_NECK_SACCADE * joint_interface->get_joint_min(JointInterface::ID_EYES_LEFT_LR);
88
    float left_max  = OMR_LIMIT_TRIGGERS_NECK_SACCADE * joint_interface->get_joint_max(JointInterface::ID_EYES_LEFT_LR);
89
    float right_min = OMR_LIMIT_TRIGGERS_NECK_SACCADE * joint_interface->get_joint_min(JointInterface::ID_EYES_RIGHT_LR);
90
    float right_max = OMR_LIMIT_TRIGGERS_NECK_SACCADE * joint_interface->get_joint_max(JointInterface::ID_EYES_RIGHT_LR);
91
    float ud_min    = OMR_LIMIT_TRIGGERS_NECK_SACCADE * joint_interface->get_joint_min(JointInterface::ID_EYES_BOTH_UD);
92
    float ud_max    = OMR_LIMIT_TRIGGERS_NECK_SACCADE * joint_interface->get_joint_max(JointInterface::ID_EYES_BOTH_UD);
85
    // min/max bounds
86
    float left_min  = OMR_LIMIT_TRIGGERS_NECK_SACCADE *
87
            joint_interface->get_joint_min(JointInterface::ID_EYES_LEFT_LR);
88
    float left_max  = OMR_LIMIT_TRIGGERS_NECK_SACCADE *
89
            joint_interface->get_joint_max(JointInterface::ID_EYES_LEFT_LR);
90
    float right_min = OMR_LIMIT_TRIGGERS_NECK_SACCADE *
91
            joint_interface->get_joint_min(JointInterface::ID_EYES_RIGHT_LR);
92
    float right_max = OMR_LIMIT_TRIGGERS_NECK_SACCADE *
93
            joint_interface->get_joint_max(JointInterface::ID_EYES_RIGHT_LR);
94
    float ud_min    = OMR_LIMIT_TRIGGERS_NECK_SACCADE *
95
            joint_interface->get_joint_min(JointInterface::ID_EYES_BOTH_UD);
96
    float ud_max    = OMR_LIMIT_TRIGGERS_NECK_SACCADE *
97
            joint_interface->get_joint_max(JointInterface::ID_EYES_BOTH_UD);
93 98

  
94 99
    if (
95 100
            (eye_target_l < left_min) || (eye_target_l > left_max) ||
96 101
            (eye_target_r < right_min) || (eye_target_r > right_max) ||
97
            (eye_target_ud < ud_min) || (eye_target_ud > ud_max)){
98
        //the eyeball gets close to OMR, activate a neck compensation motion:
102
            (eye_target_ud < ud_min) || (eye_target_ud > ud_max)) {
103
        // the eyeball gets close to OMR, activate a neck compensation motion
99 104
        neck_saccade_omr = true;
100
    }else{
105
    } else {
101 106
        neck_saccade_omr = false;
102 107
    }
103 108

  
104
    //use base class set method:
109
    // use base class set method
105 110
    MotionGenerator::set_gaze_target(new_gaze_target);
106 111
}
107 112

  
108 113
//! check if an eye saccade is active:
109
bool GazeMotionGenerator::get_eye_saccade_active(){
114
bool GazeMotionGenerator::get_eye_saccade_active() {
110 115
    bool saccade_active;
111 116

  
112
    float speed_left  = joint_interface->get_ts_speed(JointInterface::ID_EYES_LEFT_LR).get_newest_value();
113
    float speed_right = joint_interface->get_ts_speed(JointInterface::ID_EYES_RIGHT_LR).get_newest_value();
114
    float speed_tilt  = joint_interface->get_ts_speed(JointInterface::ID_EYES_BOTH_UD).get_newest_value();
117
    float speed_left  = joint_interface->get_ts_speed(
118
                JointInterface::ID_EYES_LEFT_LR).get_newest_value();
119
    float speed_right = joint_interface->get_ts_speed(
120
                JointInterface::ID_EYES_RIGHT_LR).get_newest_value();
121
    float speed_tilt  = joint_interface->get_ts_speed(
122
                JointInterface::ID_EYES_BOTH_UD).get_newest_value();
115 123

  
116 124
    float speed_total_l = sqrt(speed_left*speed_left + speed_tilt*speed_tilt);
117 125
    float speed_total_r = sqrt(speed_right*speed_right + speed_tilt*speed_tilt);
118 126

  
119
    //thresholding
120
    if ((speed_total_l > EYE_SACCADE_SPEED_THRESHOLD) || (speed_total_r > EYE_SACCADE_SPEED_THRESHOLD)){
121
        //this is a saccade
127
    // thresholding
128
    if ((speed_total_l > EYE_SACCADE_SPEED_THRESHOLD) ||
129
            (speed_total_r > EYE_SACCADE_SPEED_THRESHOLD)) {
130
        // this is a saccade
122 131
        saccade_active = true;
123
    }else{
132
    } else {
124 133
        saccade_active = false;
125 134
    }
126 135

  
......
128 137
}
129 138

  
130 139
//! get overall gaze
131
GazeState GazeMotionGenerator::get_current_gaze(){
132
    //shortcut, makes the following easier to read
140
humotion::GazeState GazeMotionGenerator::get_current_gaze() {
141
    // shortcut, makes the following easier to read
133 142
    JointInterface *j = joint_interface;
134 143

  
135 144
    GazeState gaze = requested_gaze_state;
136 145

  
137 146
    gaze.pan = j->get_ts_position(JointInterface::ID_NECK_PAN).get_newest_value() +
138
            (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;
139
    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();
147
            (j->get_ts_position(JointInterface::ID_EYES_LEFT_LR).get_newest_value()
148
             + j->get_ts_position(JointInterface::ID_EYES_RIGHT_LR).get_newest_value())/2.0;
149
    gaze.tilt = j->get_ts_position(JointInterface::ID_NECK_TILT).get_newest_value()
150
            + j->get_ts_position(JointInterface::ID_EYES_BOTH_UD).get_newest_value();
140 151
    gaze.roll = j->get_ts_position(JointInterface::ID_NECK_ROLL).get_newest_value();
141 152

  
142
    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();
153
    gaze.vergence = j->get_ts_position(JointInterface::ID_EYES_LEFT_LR).get_newest_value()
154
            - j->get_ts_position(JointInterface::ID_EYES_RIGHT_LR).get_newest_value();
143 155

  
144 156
    return gaze;
145 157
}

Also available in: Unified diff