Revision ea068cf1 src/server/controller.cpp

View differences:

src/server/controller.cpp
40 40
using humotion::server::Controller;
41 41

  
42 42
//! constructor
43
Controller::Controller(JointInterface *j) : activated(false) {
44
    joint_interface = j;
43
Controller::Controller(JointInterface *j) {
44
    activated_ = false;
45
    joint_interface_ = j;
45 46
}
46 47

  
47 48
//! destructor
......
54 55
    //       (i.e. the neck generator must be added after the eye generator!)
55 56

  
56 57
    // eye motion generation:
57
    add_motion_generator(new EyeMotionGenerator(joint_interface));
58
    add_motion_generator(new EyeMotionGenerator(joint_interface_));
58 59

  
59 60
    // eyelid motion generator
60
    add_motion_generator(new EyelidMotionGenerator(joint_interface));
61
    add_motion_generator(new EyelidMotionGenerator(joint_interface_));
61 62

  
62 63
    // neck motion generator
63
    add_motion_generator(new NeckMotionGenerator(joint_interface));
64
    add_motion_generator(new NeckMotionGenerator(joint_interface_));
64 65

  
65 66
    // mouth motion generator
66
    add_motion_generator(new MouthMotionGenerator(joint_interface));
67
    add_motion_generator(new MouthMotionGenerator(joint_interface_));
67 68

  
68 69
    // eyebrow motion generator
69
    add_motion_generator(new EyebrowMotionGenerator(joint_interface));
70
    add_motion_generator(new EyebrowMotionGenerator(joint_interface_));
70 71
}
71 72

  
72 73
//! add a single motion genrator
73 74
void Controller::add_motion_generator(MotionGenerator *m) {
74
    motion_generator_vector.push_back(m);
75
    motion_generator_vector_.push_back(m);
75 76
}
76 77

  
77 78
//! calculate target angles for all motion generators:
78 79
void Controller::calculate_targets() {
79 80
    Controller::motion_generator_vector_t::iterator it;
80
    for (it = motion_generator_vector.begin(); it < motion_generator_vector.end(); it++) {
81
    for (it = motion_generator_vector_.begin(); it < motion_generator_vector_.end(); it++) {
81 82
        (*it)->calculate_targets();
82 83
    }
83 84
}
......
86 87
//! NOTE: this is done in an extra loop to have a low delay between consequent sets:
87 88
void Controller::publish_targets() {
88 89
    Controller::motion_generator_vector_t::iterator it;
89
    for (it = motion_generator_vector.begin(); it < motion_generator_vector.end(); it++) {
90
    for (it = motion_generator_vector_.begin(); it < motion_generator_vector_.end(); it++) {
90 91
        (*it)->publish_targets();
91 92
    }
92 93
}
......
102 103

  
103 104
    // check if this timestamp allows a valid conversion:
104 105
    Timestamp history_begin =
105
            joint_interface->get_ts_position(JointInterface::ID_NECK_PAN).get_first_timestamp();
106
            joint_interface_->get_ts_position(JointInterface::ID_NECK_PAN).get_first_timestamp();
106 107
    // Timestamp history_end   =
107 108
    //       joint_interface->get_ts_position(JointInterface::ID_NECK_PAN).get_last_timestamp();
108 109

  
......
115 116
        // to do any guesswork and try to calculate a valid absolute target
116 117
        // therefore we will use the last known targets (see below)
117 118
        // in case we did not see this timestamp before, show a warning:
118
        if (last_known_absolute_timestamp != relative_target_timestamp) {
119
        if (last_known_absolute_timestamp_ != relative_target_timestamp) {
119 120
            printf("> WARNING: restored/guessed absolute target for unknown timestamp %f "
120 121
                   "[this should not happen]\n", relative_target_timestamp.to_seconds());
121
            last_known_absolute_target_pan = 0.0;
122
            last_known_absolute_target_tilt = 0.0;
123
            last_known_absolute_target_roll = 0.0;
122
            last_known_absolute_target_pan_ = 0.0;
123
            last_known_absolute_target_tilt_ = 0.0;
124
            last_known_absolute_target_roll_ = 0.0;
124 125
        }
125 126
    } else {
126 127
        // all fine, we can reconstruct the absolute target
127 128
        // fetch head / camera pose during that timestamp
128
        double neck_pan  = joint_interface->get_ts_position(
129
        double neck_pan  = joint_interface_->get_ts_position(
129 130
                JointInterface::ID_NECK_PAN).get_interpolated_value(relative_target_timestamp);
130
        double eye_l_pan = joint_interface->get_ts_position(
131
        double eye_l_pan = joint_interface_->get_ts_position(
131 132
                JointInterface::ID_EYES_LEFT_LR).get_interpolated_value(relative_target_timestamp);
132
        double eye_r_pan = joint_interface->get_ts_position(
133
        double eye_r_pan = joint_interface_->get_ts_position(
133 134
                JointInterface::ID_EYES_RIGHT_LR).get_interpolated_value(relative_target_timestamp);
134
        last_known_absolute_target_pan       = neck_pan + (eye_l_pan + eye_r_pan)/2.0;
135
        last_known_absolute_target_pan_       = neck_pan + (eye_l_pan + eye_r_pan)/2.0;
135 136
        //
136
        double neck_tilt = joint_interface->get_ts_position(
137
        double neck_tilt = joint_interface_->get_ts_position(
137 138
                JointInterface::ID_NECK_TILT).get_interpolated_value(relative_target_timestamp);
138
        double eye_tilt  = joint_interface->get_ts_position(
139
        double eye_tilt  = joint_interface_->get_ts_position(
139 140
                JointInterface::ID_EYES_BOTH_UD).get_interpolated_value(relative_target_timestamp);
140
        last_known_absolute_target_tilt      = neck_tilt + eye_tilt;
141
        last_known_absolute_target_tilt_      = neck_tilt + eye_tilt;
141 142
        //
142
        last_known_absolute_target_roll      = joint_interface->get_ts_position(
143
        last_known_absolute_target_roll_      = joint_interface_->get_ts_position(
143 144
                JointInterface::ID_NECK_ROLL).get_interpolated_value(relative_target_timestamp);
144 145

  
145 146
        // safe this timestamp as known:
146
        last_known_absolute_timestamp = relative_target_timestamp;
147
        last_known_absolute_timestamp_ = relative_target_timestamp;
147 148
    }
148 149

  
149
    pan  = last_known_absolute_target_pan;
150
    tilt = last_known_absolute_target_tilt;
151
    roll = last_known_absolute_target_roll;
150
    pan  = last_known_absolute_target_pan_;
151
    tilt = last_known_absolute_target_tilt_;
152
    roll = last_known_absolute_target_roll_;
152 153

  
153 154
    // substract offsets
154 155
    pan  -= relative.pan_offset;
......
176 177

  
177 178
//! activate controller
178 179
void Controller::set_activated(void) {
179
    activated = true;
180
    activated_ = true;
180 181
}
181 182

  
182 183
//! update gaze target:
183 184
//! \param GazeState with target values for the overall gaze
184 185
void Controller::set_gaze_target(humotion::GazeState new_gaze_target) {
185
    if (!activated) {
186
    if (!activated_) {
186 187
        // not yet initialized, ignore incoming targets
187 188
        return;
188 189
    }
......
200 201
    }
201 202

  
202 203
    Controller::motion_generator_vector_t::iterator it;
203
    for (it = motion_generator_vector.begin(); it < motion_generator_vector.end(); it++) {
204
    for (it = motion_generator_vector_.begin(); it < motion_generator_vector_.end(); it++) {
204 205
        (*it)->set_gaze_target(target_gaze);
205 206
    }
206 207
}
......
208 209
//! update mouth state:
209 210
//! \param MouthState with target values for the mouth joints
210 211
void Controller::set_mouth_target(MouthState s) {
211
    if (!activated) {
212
    if (!activated_) {
212 213
        // not yet initialized, ignore incoming targets
213 214
        return;
214 215
    }
215 216

  
216 217
    Controller::motion_generator_vector_t::iterator it;
217
    for (it = motion_generator_vector.begin(); it < motion_generator_vector.end(); it++) {
218
    for (it = motion_generator_vector_.begin(); it < motion_generator_vector_.end(); it++) {
218 219
        (*it)->set_mouth_target(s);
219 220
    }
220 221
}

Also available in: Unified diff