Revision cc3bdc80

View differences:

examples/yarp_icub/src/icub_jointinterface.cpp
61 61
    enum_id_bimap.insert(enum_id_bimap_entry_t(ICUB_ID_EYES_RIGHT_BROW, ID_EYES_RIGHT_BROW));
62 62

  
63 63
    //init pd control variables
64
    enum_id_bimap_t::right_const_iterator it;
65
    for(it = enum_id_bimap.left.begin(); it == enum_id_bimap.left.end(); it++) {
66
        last_position_error[*it] = 0.0;
64
    enum_id_bimap_t::const_iterator it;
65
    for(it = enum_id_bimap.begin(); it != enum_id_bimap.end(); ++it) {
66
        int id = it->left;
67
        last_position_error[id] = 0.0;
67 68
        PID_P[id] = 0.5;
68 69
        PID_D[id] = 0.1;
69 70
    }
......
207 208
void iCubJointInterface::set_target_in_velocitymode(int id){
208 209
    // set speed cacluated as in velocity + set position -> replicates smoothmotion from flobi?!
209 210
    //first: calculate necessary speed to reach the given target within the next clock tick:
210
    double distance = value - target_angle_previous[id];
211
    double distance = target_angle[id] - target_angle_previous[id];
211 212

  
212 213
    //make the motion smooth: we want to reach 85% of the target in the next iteration:
213 214
    distance = 0.85 * distance;
......
241 242
        //TODO: add interpolation into future!
242 243
        //humotion::Timestamp data_ts = humotion::Timestamp::now(); and extend get_interpol value with get_future_value
243 244
        double position_error = target_angle[id] - get_ts_position(id).get_interpolated_value(data_ts);
244
        double error_d = (position_error - last_position_error[id]) / (((double) rate)*1000.0);
245
        double error_d = (position_error - last_position_error[id]) / (framerate*1000.0);
245 246
        last_position_error[id] = position_error;
246 247
        //finally do a PD loop to get the target velocity
247 248
        double target_velocity = PID_P[id] * position_error + PID_D[id]*error_d + speed;
248 249

  
249 250
        //if (id == ICUB_ID_NECK_PAN) speed = -speed;
250 251
        ivel->velocityMove(id, target_velocity);
251
        printf("> VEL now=%3.2f target=%3.2f --> dist=%3.2f speed=%3.2f\n",target_angle_previous[id],value,distance,speed);
252
        printf("> VEL now=%3.2f target=%3.2f --> dist=%3.2f speed=%3.2f\n",target_angle_previous[id],target_angle[id],distance,speed);
252 253
    }
253 254

  
254 255
    target_angle_previous[id] = get_ts_position(convert_motorid_to_enum(id)).get_newest_value();
......
261 262
    if (POSITION_CONTROL){
262 263
        //position control
263 264
        for(int i=ICUB_ID_NECK_TILT; i<=ICUB_ID_EYES_VERGENCE; i++){
264
            set_target_in_positionmode(i, target_angle[i]);
265
            set_target_in_positionmode(i);
265 266
        }
266 267
    }else{
267 268
        //velocity control
268 269
        for(int i=ICUB_ID_NECK_TILT; i<=ICUB_ID_EYES_VERGENCE; i++){
269
            set_target_in_velocitymode(i, target_angle[i]);
270
            set_target_in_velocitymode(i);
270 271
        }
271 272
    }
272 273
    //printf("> TARGET PAN = %3.2f\n",target_angle[ICUB_ID_NECK_PAN]);

Also available in: Unified diff