00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00032 #include <humanoid_control_functions.h>
00033 #include <gtk_aux.h>
00034
00035 using namespace std;
00036
00037 short unsigned int ConvertJointAngleByID(int id, double angle_position)
00038 {
00039
00040 humanoid *humanoid_f=(humanoid*) new humanoid();
00041 short unsigned int servo_position=0;
00042 switch (id){
00043 case 61:
00044 {
00045 servo_position=humanoid_f->Head_Pan_Tilt_Conversion(angle_position);
00046 break;
00047 }
00048 case 54:
00049 {
00050 servo_position=humanoid_f->Shoulder_Flexion_Extension_Conversion(RIGHT,angle_position);
00051 break;
00052 }
00053 case 53:
00054 {
00055 servo_position=humanoid_f->Shoulder_Abduction_Adduction_Conversion(RIGHT,angle_position);
00056 break;
00057 }
00058 case 51:
00059 {
00060 servo_position=humanoid_f->Elbow_Flexion_Extension_Conversion(RIGHT,angle_position);
00061 break;
00062 }
00063 case 44:
00064 {
00065 servo_position=humanoid_f->Shoulder_Flexion_Extension_Conversion(LEFT,angle_position);
00066 break;
00067 }
00068 case 43:
00069 {
00070 servo_position=humanoid_f->Shoulder_Abduction_Adduction_Conversion(LEFT,angle_position);
00071 break;
00072 }
00073 case 41:
00074 {
00075 servo_position=humanoid_f->Elbow_Flexion_Extension_Conversion(LEFT,angle_position);
00076 break;
00077 }
00078 case 31:
00079 {
00080 servo_position=humanoid_f->Torso_Rotation_Conversion(angle_position);
00081 break;
00082 }
00083 case 32:
00084 {
00085 servo_position=humanoid_f->Torso_Flexion_Extension_Conversion(angle_position);
00086 break;
00087 }
00088 case 33:
00089 {
00090 servo_position=humanoid_f->Torso_Lateral_Flexion_Extension_Conversion(angle_position);
00091 break;
00092 }
00093 case 21:
00094 {
00095 servo_position=humanoid_f->Ankle_Inversion_Eversion_Conversion(LEFT,angle_position);
00096 break;
00097 }
00098 case 22:
00099 {
00100 servo_position=humanoid_f->Ankle_Flexion_Conversion(LEFT,angle_position);
00101 break;
00102 }
00103 case 23:
00104 {
00105 servo_position=humanoid_f->Knee_Conversion(LEFT,angle_position);
00106 break;
00107 }
00108 case 25:
00109 {
00110 servo_position=humanoid_f->Hip_Abduction_Hiperabduction_Conversion(LEFT,angle_position);
00111 break;
00112 }
00113 case 26:
00114 {
00115 servo_position=humanoid_f->Hip_Flexion_Conversion(LEFT,angle_position);
00116 break;
00117 }
00118 case 11:
00119 {
00120 servo_position=humanoid_f->Ankle_Inversion_Eversion_Conversion(RIGHT,angle_position);
00121 break;
00122 }
00123 case 12:
00124 {
00125 servo_position=humanoid_f->Ankle_Flexion_Conversion(RIGHT,angle_position);
00126 break;
00127 }
00128 case 13:
00129 {
00130 servo_position=humanoid_f->Knee_Conversion(RIGHT,angle_position);
00131 break;
00132 }
00133 case 15:
00134 {
00135 servo_position=humanoid_f->Hip_Abduction_Hiperabduction_Conversion(RIGHT,angle_position);
00136 break;
00137 }
00138 case 16:
00139 {
00140 servo_position=humanoid_f->Hip_Flexion_Conversion(RIGHT,angle_position);
00141 break;
00142 }
00143 default:
00144 {
00145 servo_position=0xFFFF;
00146 break;
00147 }
00148 }
00149 delete humanoid_f;
00150 return servo_position;
00151 }
00152
00153 void UpdateArmsDirKinData(shared_vars_t*RobotVars)
00154 {
00155
00156 double *end_pos_n_RPY= new double[6];
00157
00158
00159 RobotVars->humanoid_f->Dir_Kin_3DOF_Arm(RobotVars->robot_kin_data.LeftShoulderFlexion,
00160 RobotVars->robot_kin_data.LeftShoulderAbduction,
00161 RobotVars->robot_kin_data.LeftElbowFlexion,
00162 LEFT,
00163 end_pos_n_RPY);
00164
00165 RobotVars->robot_kin_data.X_arm_end_left=end_pos_n_RPY[0];
00166 RobotVars->robot_kin_data.Y_arm_end_left=end_pos_n_RPY[1];
00167 RobotVars->robot_kin_data.Z_arm_end_left=end_pos_n_RPY[2];
00168 RobotVars->robot_kin_data.ROLL_arm_end_left=end_pos_n_RPY[3];
00169 RobotVars->robot_kin_data.PITCH_arm_end_left=end_pos_n_RPY[4];
00170 RobotVars->robot_kin_data.YAW_arm_end_left=end_pos_n_RPY[5];
00171
00172 RobotVars->humanoid_f->Dir_Kin_3DOF_Arm(RobotVars->robot_kin_data.RightShoulderFlexion,
00173 RobotVars->robot_kin_data.RightShoulderAbduction,
00174 RobotVars->robot_kin_data.RightElbowFlexion,
00175 RIGHT,
00176 end_pos_n_RPY);
00177
00178 RobotVars->robot_kin_data.X_arm_end_right=end_pos_n_RPY[0];
00179 RobotVars->robot_kin_data.Y_arm_end_right=end_pos_n_RPY[1];
00180 RobotVars->robot_kin_data.Z_arm_end_right=end_pos_n_RPY[2];
00181 RobotVars->robot_kin_data.ROLL_arm_end_right=end_pos_n_RPY[3];
00182 RobotVars->robot_kin_data.PITCH_arm_end_right=end_pos_n_RPY[4];
00183 RobotVars->robot_kin_data.YAW_arm_end_right=end_pos_n_RPY[5];
00184 delete end_pos_n_RPY;
00185 }
00186
00187 void UpdateDetachedLegsDirKinData(shared_vars_t*RobotVars)
00188 {
00189
00190 double *end_pos_n_RPY= new double[6];
00191
00192
00193 RobotVars->humanoid_f->Dir_Kin_4DOF_Detached_Leg(RobotVars->robot_kin_data.LeftAnkleInversion,
00194 RobotVars->robot_kin_data.LeftAnkleFlexion,
00195 RobotVars->robot_kin_data.LeftKneeFlexion,
00196 RobotVars->robot_kin_data.LeftHipAbduction,
00197 LEFT,
00198 end_pos_n_RPY);
00199
00200 RobotVars->robot_kin_data.detached_leg_pos_left[0] = end_pos_n_RPY[0];
00201 RobotVars->robot_kin_data.detached_leg_pos_left[1] = end_pos_n_RPY[1];
00202 RobotVars->robot_kin_data.detached_leg_pos_left[2] = end_pos_n_RPY[2];
00203 RobotVars->robot_kin_data.detached_leg_rpy_left[0] = end_pos_n_RPY[3];
00204 RobotVars->robot_kin_data.detached_leg_rpy_left[1] = end_pos_n_RPY[4];
00205 RobotVars->robot_kin_data.detached_leg_rpy_left[2] = end_pos_n_RPY[5];
00206
00207
00208 RobotVars->humanoid_f->Calculate_Detached_Leg_3DOF_COG(RobotVars->robot_kin_data.LeftAnkleInversion,
00209 RobotVars->robot_kin_data.LeftAnkleFlexion,
00210 RobotVars->robot_kin_data.LeftKneeFlexion,
00211 LEFT,
00212 &RobotVars->robot_kin_data.COG_detached_leg_left);
00213
00214
00215 RobotVars->humanoid_f->Dir_Kin_4DOF_Detached_Leg(RobotVars->robot_kin_data.RightAnkleInversion,
00216 RobotVars->robot_kin_data.RightAnkleFlexion,
00217 RobotVars->robot_kin_data.RightKneeFlexion,
00218 RobotVars->robot_kin_data.RightHipAbduction,
00219 RIGHT,
00220 end_pos_n_RPY);
00221
00222 RobotVars->robot_kin_data.detached_leg_pos_right[0] = end_pos_n_RPY[0];
00223 RobotVars->robot_kin_data.detached_leg_pos_right[1] = end_pos_n_RPY[1];
00224 RobotVars->robot_kin_data.detached_leg_pos_right[2] = end_pos_n_RPY[2];
00225 RobotVars->robot_kin_data.detached_leg_rpy_right[0] = end_pos_n_RPY[3];
00226 RobotVars->robot_kin_data.detached_leg_rpy_right[1] = end_pos_n_RPY[4];
00227 RobotVars->robot_kin_data.detached_leg_rpy_right[2] = end_pos_n_RPY[5];
00228
00229
00230 RobotVars->humanoid_f->Calculate_Detached_Leg_3DOF_COG(RobotVars->robot_kin_data.RightAnkleInversion,
00231 RobotVars->robot_kin_data.RightAnkleFlexion,
00232 RobotVars->robot_kin_data.RightKneeFlexion,
00233 RIGHT,
00234 &RobotVars->robot_kin_data.COG_detached_leg_right);
00235
00236 delete end_pos_n_RPY;
00237 }
00238
00239 void SetRobotHomePosition(shared_vars_t*RobotVars)
00240 {
00241 static short int speed;
00242 double default_angle_position = 0.0;
00243 double default_arms_angle_position = 20.0;
00244 int ret;
00245 int id;
00246 speed = RobotVars->parameters.robot_home_position_base_speed;
00247 if(RobotVars->parameters.kinematic_model==4)
00248 {
00249 id=21;
00250 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00251 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Ankle_Inversion_Eversion_Conversion(LEFT,default_angle_position));
00252 id=22;
00253 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00254 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Ankle_Flexion_Conversion(LEFT,default_angle_position));
00255 id=23;
00256 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00257 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Knee_Conversion(LEFT,default_angle_position));
00258 id=25;
00259 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00260 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Hip_Abduction_Hiperabduction_Conversion(LEFT,default_angle_position));
00261 id=26;
00262 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00263 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Hip_Flexion_Conversion(LEFT,default_angle_position));
00264 }
00265 else if(RobotVars->parameters.kinematic_model==5)
00266 {
00267 id=11;
00268 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00269 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Ankle_Inversion_Eversion_Conversion(RIGHT,default_angle_position));
00270 id=12;
00271 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00272 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Ankle_Flexion_Conversion(RIGHT,default_angle_position));
00273 id=13;
00274 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00275 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Knee_Conversion(RIGHT,default_angle_position));
00276 id=15;
00277 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00278 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Hip_Abduction_Hiperabduction_Conversion(RIGHT,default_angle_position));
00279 id=16;
00280 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00281 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Hip_Flexion_Conversion(RIGHT,default_angle_position));
00282 }
00283 else
00284 {
00285 id=61;
00286 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00287 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Head_Pan_Tilt_Conversion(default_angle_position));
00288 id=44;
00289 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00290 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Shoulder_Flexion_Extension_Conversion(LEFT,default_angle_position));
00291 id=43;
00292 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00293 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Shoulder_Abduction_Adduction_Conversion(LEFT,default_arms_angle_position));
00294 id=41;
00295 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00296 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Elbow_Flexion_Extension_Conversion(LEFT,default_arms_angle_position));
00297 id=54;
00298 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00299 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Shoulder_Flexion_Extension_Conversion(RIGHT,default_angle_position));
00300 RobotVars->parameters.arm_auto_speed[0]=speed;
00301 id=53;
00302 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00303 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Shoulder_Abduction_Adduction_Conversion(RIGHT,default_arms_angle_position));
00304 RobotVars->parameters.arm_auto_speed[1]=speed;
00305 id=51;
00306 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00307 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Elbow_Flexion_Extension_Conversion(RIGHT,default_arms_angle_position));
00308 RobotVars->parameters.arm_auto_speed[2]=speed;
00309 id=31;
00310 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00311 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Torso_Rotation_Conversion(default_angle_position));
00312 id=32;
00313 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00314 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Torso_Flexion_Extension_Conversion(default_angle_position));
00315 id=33;
00316 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00317 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Torso_Lateral_Flexion_Extension_Conversion(default_angle_position));
00318 id=11;
00319 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00320 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Ankle_Inversion_Eversion_Conversion(RIGHT,default_angle_position));
00321 id=12;
00322 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00323 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Ankle_Flexion_Conversion(RIGHT,default_angle_position));
00324 id=13;
00325 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00326 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Knee_Conversion(RIGHT,default_angle_position));
00327 id=15;
00328 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00329 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Hip_Abduction_Hiperabduction_Conversion(RIGHT,default_angle_position));
00330 id=16;
00331 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00332 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Hip_Flexion_Conversion(RIGHT,default_angle_position));
00333 id=21;
00334 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00335 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Ankle_Inversion_Eversion_Conversion(LEFT,default_angle_position));
00336 id=22;
00337 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00338 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Ankle_Flexion_Conversion(LEFT,default_angle_position));
00339 id=23;
00340 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00341 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Knee_Conversion(LEFT,default_angle_position));
00342 id=25;
00343 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00344 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Hip_Abduction_Hiperabduction_Conversion(LEFT,default_angle_position));
00345 id=26;
00346 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00347 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Hip_Flexion_Conversion(LEFT,default_angle_position));
00348 }
00349 RobotVars->parameters.manual_speed = speed;
00350 }
00351
00352 double ConvertServoValueByID(int id, short unsigned int servo_value)
00353 {
00354
00355 humanoid *humanoid_f=(humanoid*) new humanoid();
00356 double joint_angle=0xFFFF;
00357 switch (id){
00358 case 61:
00359 {
00360 joint_angle=humanoid_f->Head_Pan_Tilt_ServoValue_Conversion(servo_value);
00361 break;
00362 }
00363 case 54:
00364 {
00365 joint_angle=humanoid_f->Shoulder_Flexion_Extension_ServoValue_Conversion(RIGHT, servo_value);
00366 break;
00367 }
00368 case 53:
00369 {
00370 joint_angle=humanoid_f->Shoulder_Abduction_Adduction_ServoValue_Conversion(RIGHT, servo_value);
00371 break;
00372 }
00373 case 51:
00374 {
00375 joint_angle=humanoid_f->Elbow_Flexion_Extension_ServoValue_Conversion(RIGHT, servo_value);
00376 break;
00377 }
00378 case 44:
00379 {
00380 joint_angle=humanoid_f->Shoulder_Flexion_Extension_ServoValue_Conversion(LEFT, servo_value);;
00381 break;
00382 }
00383 case 43:
00384 {
00385 joint_angle=humanoid_f->Shoulder_Abduction_Adduction_ServoValue_Conversion(LEFT, servo_value);;
00386 break;
00387 }
00388 case 41:
00389 {
00390 joint_angle=humanoid_f->Elbow_Flexion_Extension_ServoValue_Conversion(LEFT, servo_value);
00391 break;
00392 }
00393 case 31:
00394 {
00395 joint_angle=humanoid_f->Torso_Rotation_ServoValue_Conversion(servo_value);
00396 break;
00397 }
00398 case 32:
00399 {
00400 joint_angle=humanoid_f->Torso_Flexion_Extension_ServoValue_Conversion(servo_value);
00401 break;
00402 }
00403 case 33:
00404 {
00405 joint_angle=humanoid_f->Torso_Lateral_Flexion_Extension_ServoValue_Conversion(servo_value);
00406 break;
00407 }
00408 case 21:
00409 {
00410 joint_angle=humanoid_f->Ankle_Inversion_Eversion_ServoValue_Conversion(LEFT,servo_value);
00411 break;
00412 }
00413 case 22:
00414 {
00415 joint_angle=humanoid_f->Ankle_Flexion_ServoValue_Conversion(LEFT,servo_value);
00416 break;
00417 }
00418 case 23:
00419 {
00420 joint_angle=humanoid_f->Knee_Flexion_ServoValue_Conversion(LEFT,servo_value);
00421 break;
00422 }
00423 case 25:
00424 {
00425 joint_angle=humanoid_f->Hip_Abduction_Hiperabduction_ServoValue_Conversion(LEFT,servo_value);
00426 break;
00427 }
00428 case 26:
00429 {
00430 joint_angle=humanoid_f->Hip_Flexion_ServoValue_Conversion(LEFT,servo_value);
00431 break;
00432 }
00433 case 11:
00434 {
00435 joint_angle=humanoid_f->Ankle_Inversion_Eversion_ServoValue_Conversion(RIGHT,servo_value);
00436 break;
00437 }
00438 case 12:
00439 {
00440 joint_angle=humanoid_f->Ankle_Flexion_ServoValue_Conversion(RIGHT,servo_value);
00441 break;
00442 }
00443 case 13:
00444 {
00445 joint_angle=humanoid_f->Knee_Flexion_ServoValue_Conversion(RIGHT,servo_value);
00446 break;
00447 }
00448 case 15:
00449 {
00450 joint_angle=humanoid_f->Hip_Abduction_Hiperabduction_ServoValue_Conversion(RIGHT,servo_value);
00451 break;
00452 }
00453 case 16:
00454 {
00455 joint_angle=humanoid_f->Hip_Flexion_ServoValue_Conversion(RIGHT,servo_value);
00456 break;
00457 }
00458
00459
00460
00461
00462
00463 }
00464 delete humanoid_f;
00465 return joint_angle;
00466 }
00467
00468 void SetArmSpeed(short int SIDE, short int speed, shared_vars_t*RobotVars)
00469 {
00470 short int id;
00471 int ret;
00472 if(SIDE==RIGHT)
00473 {
00474 id=54;
00475 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00476 id=53;
00477 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00478 id=51;
00479 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00480 return;
00481 }
00482 else if(SIDE==LEFT)
00483 {
00484 id=44;
00485 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00486 id=43;
00487 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00488 id=41;
00489 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00490 return;
00491 }
00492 else
00493 {
00494 return;
00495 }
00496 }
00497
00498 void SetLegSpeed(short int SIDE, short int speed, shared_vars_t*RobotVars)
00499 {
00500 short int id;
00501 int ret;
00502 if(SIDE==RIGHT)
00503 {
00504 id=11;
00505 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00506 id=12;
00507 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00508 id=13;
00509 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00510 id=15;
00511 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00512 id=16;
00513 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00514 return;
00515 }
00516 else if(SIDE==LEFT)
00517 {
00518 id=21;
00519 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00520 id=22;
00521 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00522 id=23;
00523 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00524 id=25;
00525 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00526 id=26;
00527 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00528 return;
00529 }
00530 else
00531 {
00532 return;
00533 }
00534 }
00535
00536 void MoveArmToCartesianPosition(double X, double Y, double Z, short int SIDE, shared_vars_t*RobotVars)
00537 {
00538 short int id;
00539 int ret;
00540 double *thetas= new double[3];
00541 RobotVars->humanoid_f->Inv_Kin_3DOF_Arm(X , Y , Z , thetas);
00542 if(thetas[0]!=1000. && thetas[1]!=1000. && thetas[2]!=1000.)
00543 {
00544 if(SIDE==RIGHT)
00545 {
00546 id=54;
00547 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Shoulder_Flexion_Extension_Conversion(RIGHT,thetas[0]));
00548 id=53;
00549 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Shoulder_Abduction_Adduction_Conversion(RIGHT,thetas[1]));
00550 id=51;
00551 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Elbow_Flexion_Extension_Conversion(RIGHT,thetas[2]));
00552
00553 RobotVars->robot_kin_data.RightShoulderFlexion=thetas[0];
00554 RobotVars->robot_kin_data.RightShoulderAbduction=thetas[1];
00555 RobotVars->robot_kin_data.RightElbowFlexion=thetas[2];
00556 }
00557 else if(SIDE==LEFT)
00558 {
00559 id=44;
00560 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Shoulder_Flexion_Extension_Conversion(LEFT,thetas[0]));
00561 id=43;
00562 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Shoulder_Abduction_Adduction_Conversion(LEFT,thetas[1]));
00563 id=41;
00564 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Elbow_Flexion_Extension_Conversion(LEFT,thetas[2]));
00565
00566 RobotVars->robot_kin_data.LeftShoulderFlexion=thetas[0];
00567 RobotVars->robot_kin_data.LeftShoulderAbduction=thetas[1];
00568 RobotVars->robot_kin_data.LeftElbowFlexion=thetas[2];
00569 }
00570 }
00571 delete thetas;
00572 }
00573
00574 void MoveDetachedLegToCartesianPosition(double X, double Y, double Z, double t4, short int SIDE, shared_vars_t*RobotVars)
00575 {
00576 short int id;
00577 int ret;
00578 double *thetas= new double[3];
00579 RobotVars->humanoid_f->Inv_Kin_3DOF_Detached_Leg(X , Y , Z , thetas);
00580
00581
00582
00583 if(thetas[0]!=1000. && thetas[1]!=1000. && thetas[2]!=1000.)
00584 {
00585 if(SIDE==RIGHT)
00586 {
00587 thetas[0] = thetas[0]*(double)SIDE;
00588 id=11;
00589 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Ankle_Inversion_Eversion_Conversion(RIGHT,thetas[0]));
00590 id=12;
00591 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Ankle_Flexion_Conversion(RIGHT,thetas[1]));
00592 id=13;
00593 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Knee_Conversion(RIGHT,thetas[2]));
00594 id=15;
00595 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Hip_Abduction_Hiperabduction_Conversion(RIGHT,t4));
00596
00597
00598 RobotVars->robot_kin_data.RightAnkleInversion = thetas[0];
00599 RobotVars->robot_kin_data.RightAnkleFlexion = thetas[1];
00600 RobotVars->robot_kin_data.RightKneeFlexion = thetas[2];
00601 RobotVars->robot_kin_data.RightHipAbduction = t4;
00602 }
00603 else if(SIDE==LEFT)
00604 {
00605
00606 id=21;
00607 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Ankle_Inversion_Eversion_Conversion(LEFT,thetas[0]));
00608 id=22;
00609 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Ankle_Flexion_Conversion(LEFT,thetas[1]));
00610 id=23;
00611 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Knee_Conversion(LEFT,thetas[2]));
00612 id=25;
00613 ret=RobotVars->servo->SetPosition(id,RobotVars->humanoid_f->Hip_Abduction_Hiperabduction_Conversion(LEFT,t4));
00614
00615
00616
00617 RobotVars->robot_kin_data.LeftAnkleInversion = thetas[0];
00618 RobotVars->robot_kin_data.LeftAnkleFlexion = thetas[1];
00619 RobotVars->robot_kin_data.LeftKneeFlexion = thetas[2];
00620 RobotVars->robot_kin_data.LeftHipAbduction = t4;
00621 }
00622 }
00623 delete thetas;
00624 }
00625
00626 void UpdateJointDataByID(short int id, double joint_angle, shared_vars_t*RobotVars)
00627 {
00628 switch (id){
00629 case 61:
00630 RobotVars->robot_kin_data.HeadTilt=joint_angle;break;
00631 case 54:
00632 RobotVars->robot_kin_data.RightShoulderFlexion=joint_angle;break;
00633 case 53:
00634 RobotVars->robot_kin_data.RightShoulderAbduction=joint_angle;break;
00635 case 51:
00636 RobotVars->robot_kin_data.RightElbowFlexion=joint_angle;break;
00637 case 44:
00638 RobotVars->robot_kin_data.LeftShoulderFlexion=joint_angle;break;
00639 case 43:
00640 RobotVars->robot_kin_data.LeftShoulderAbduction=joint_angle;break;
00641 case 41:
00642 RobotVars->robot_kin_data.LeftElbowFlexion=joint_angle;break;
00643 case 31:
00644 RobotVars->robot_kin_data.TorsoRotation=joint_angle;break;
00645 case 32:
00646 RobotVars->robot_kin_data.TorsoFlexion=joint_angle;break;
00647 case 33:
00648 RobotVars->robot_kin_data.TorsoLateralFlexion=joint_angle;break;
00649 case 11:
00650 RobotVars->robot_kin_data.RightAnkleInversion=joint_angle;break;
00651 case 12:
00652 RobotVars->robot_kin_data.RightAnkleFlexion=joint_angle;break;
00653 case 13:
00654 RobotVars->robot_kin_data.RightKneeFlexion=joint_angle;break;
00655 case 15:
00656 RobotVars->robot_kin_data.RightHipAbduction=joint_angle;break;
00657 case 16:
00658 RobotVars->robot_kin_data.RightHipFlexion=joint_angle;break;
00659 case 21:
00660 RobotVars->robot_kin_data.LeftAnkleInversion=joint_angle;break;
00661 case 22:
00662 RobotVars->robot_kin_data.LeftAnkleFlexion=joint_angle;break;
00663 case 23:
00664 RobotVars->robot_kin_data.LeftKneeFlexion=joint_angle;break;
00665 case 25:
00666 RobotVars->robot_kin_data.LeftHipAbduction=joint_angle;break;
00667 case 26:
00668 RobotVars->robot_kin_data.LeftHipFlexion=joint_angle;break;
00669 case 1000:
00670 {
00671
00672 const int speed=50;
00673 int position;
00674 double angle_position;
00675 const short int id_list[20]={61,54,53,51,44,43,41,31,32,33,21,22,23,25,26,11,12,13,15,16};
00676 for(int i=0;i<20;i++)
00677 {
00678 position=RobotVars->servo->SetSpeedPosition(id_list[i],speed);
00679 if(position>=606 && position<=2406)
00680 {
00681 angle_position=ConvertServoValueByID(id_list[i],position);
00682 UpdateJointDataByID(id_list[i],angle_position,RobotVars);
00683 }
00684 else
00685 {
00686 UpdateJointDataByID(id_list[i],0.,RobotVars);
00687 }
00688 }
00689 break;
00690 }
00691 default:
00692 break;}
00693 }
00694
00695 void SetArmAutomaticSpeeds(short int SIDE, shared_vars_t*RobotVars)
00696 {
00697 short int id;
00698 int ret;
00699 short unsigned int speed;
00700 if(SIDE==RIGHT)
00701 {
00702 id=54;
00703 speed=RobotVars->servo->ConvertAngularSpeedToServoSpeed(RobotVars->parameters.arm_auto_angular_speed[0], HSR_5980SG);
00704 if(speed!=0xFFFF){
00705 if(speed!=RobotVars->parameters.arm_auto_speed[0])
00706 {
00707 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00708 RobotVars->parameters.arm_auto_speed[0]=speed;
00709 }
00710 }
00711 else{
00712 ret=RobotVars->servo->SetPosition(id,
00713 RobotVars->humanoid_f->Shoulder_Flexion_Extension_Conversion(SIDE,
00714 RobotVars->robot_kin_data.RightShoulderFlexion));
00715 RobotVars->parameters.arm_auto_speed[0]=0.;
00716 }
00717 id=53;
00718 speed=RobotVars->servo->ConvertAngularSpeedToServoSpeed(RobotVars->parameters.arm_auto_angular_speed[1], HSR_5498SG);
00719 if(speed!=0xFFFF){
00720 if(speed!=RobotVars->parameters.arm_auto_speed[1])
00721 {
00722 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00723 RobotVars->parameters.arm_auto_speed[1]=speed;
00724 }
00725 }
00726 else{
00727 ret=RobotVars->servo->SetPosition(id,
00728 RobotVars->humanoid_f->Shoulder_Abduction_Adduction_Conversion(SIDE,
00729 RobotVars->robot_kin_data.RightShoulderAbduction));
00730 RobotVars->parameters.arm_auto_speed[1]=0.;
00731 }
00732 id=51;
00733 speed=RobotVars->servo->ConvertAngularSpeedToServoSpeed(RobotVars->parameters.arm_auto_angular_speed[2], HSR_5498SG);
00734 if(speed!=0xFFFF){
00735 if(speed!=RobotVars->parameters.arm_auto_speed[2])
00736 {
00737 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00738 RobotVars->parameters.arm_auto_speed[2]=speed;
00739 }
00740 }
00741 else{
00742 ret=RobotVars->servo->SetPosition(id,
00743 RobotVars->humanoid_f->Elbow_Flexion_Extension_Conversion(SIDE,
00744 RobotVars->robot_kin_data.RightElbowFlexion));
00745 RobotVars->parameters.arm_auto_speed[2]=0.;
00746 }
00747 return;
00748 }
00749 else if(SIDE==LEFT)
00750 {
00751 id=44;
00752 speed=RobotVars->servo->ConvertAngularSpeedToServoSpeed(RobotVars->parameters.arm_auto_angular_speed[0], HSR_5980SG);
00753 if(speed!=0xFFFF){
00754 if(speed!=RobotVars->parameters.arm_auto_speed[0])
00755 {
00756 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00757 RobotVars->parameters.arm_auto_speed[0]=speed;
00758 }
00759 }
00760 else{
00761 ret=RobotVars->servo->SetPosition(id,
00762 RobotVars->humanoid_f->Shoulder_Flexion_Extension_Conversion(SIDE,
00763 RobotVars->robot_kin_data.LeftShoulderFlexion));
00764 }
00765 id=43;
00766 speed=RobotVars->servo->ConvertAngularSpeedToServoSpeed(RobotVars->parameters.arm_auto_angular_speed[1], HSR_5498SG);
00767 if(speed!=0xFFFF){
00768 if(speed!=RobotVars->parameters.arm_auto_speed[1])
00769 {
00770 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00771 RobotVars->parameters.arm_auto_speed[1]=speed;
00772 }
00773 }
00774 else{
00775 ret=RobotVars->servo->SetPosition(id,
00776 RobotVars->humanoid_f->Shoulder_Abduction_Adduction_Conversion(SIDE,
00777 RobotVars->robot_kin_data.LeftShoulderAbduction));
00778 }
00779 id=41;
00780 speed=RobotVars->servo->ConvertAngularSpeedToServoSpeed(RobotVars->parameters.arm_auto_angular_speed[2], HSR_5498SG);
00781 if(speed!=0xFFFF){
00782 if(speed!=RobotVars->parameters.arm_auto_speed[2]){
00783 cout<<"setting theta3 speed: "<<speed<<endl;fflush(stdout);
00784 ret=RobotVars->servo->SetSpeedPosition(id,speed);
00785 RobotVars->parameters.arm_auto_speed[2]=speed;}
00786 else{
00787 cout<<"theta 3 speed not changed"<<endl;fflush(stdout);}
00788 }
00789 else{
00790 ret=RobotVars->servo->SetPosition(id,
00791 RobotVars->humanoid_f->Elbow_Flexion_Extension_Conversion(SIDE,
00792 RobotVars->robot_kin_data.LeftElbowFlexion));
00793 cout<<"setting theta3 position"<<endl;fflush(stdout);
00794 }
00795 return;
00796 }
00797 else
00798 {
00799 return;
00800 }
00801 }
00802
00803 void CalculateDifferencialArmServoSpeed(double *avg_speed, shared_vars_t*RobotVars)
00804 {
00805
00806 static Eigen::Vector3d speeds_3d;
00807 speeds_3d<< avg_speed[0]/(RobotVars->parameters.pos_coord_scale), avg_speed[1]/(RobotVars->parameters.pos_coord_scale), avg_speed[2]/(RobotVars->parameters.pos_coord_scale);
00808
00809 cout<<"************************************************************"<<endl<<endl<<"3D SPEEDS [mm/s]"<<endl<<speeds_3d<<endl;
00810
00811
00812 static Eigen::Matrix3d jacobian;
00813 static Eigen::Matrix3d jacobian_inverted;
00814 static Eigen::MatrixXd jacobian_alternate(3,2);
00815 static Eigen::MatrixXd jacobian_alternate_inverted(2,3);
00816
00817 RobotVars->humanoid_f->CalculateArmJacobian(RobotVars->robot_kin_data.LeftShoulderFlexion,
00818 RobotVars->robot_kin_data.LeftShoulderAbduction,
00819 RobotVars->robot_kin_data.LeftElbowFlexion,
00820 &jacobian);
00821
00822
00823
00824
00825
00826 cout<<"ANGLES READ"<<endl<<RobotVars->robot_kin_data.LeftShoulderFlexion<<endl<<RobotVars->robot_kin_data.LeftShoulderAbduction<<endl<<RobotVars->robot_kin_data.LeftElbowFlexion<<endl;
00827
00828 cout<<"JACOBIAN MATRIX"<<endl<<jacobian<<endl;
00829
00830 cout<<"JACOBIAN MATRIX DETERMINANT: "<<jacobian.determinant()<<endl;
00831
00832
00833 jacobian_inverted = jacobian.inverse();
00834 cout<<"INVERTED JACOBIAN MATRIX"<<endl<<jacobian_inverted<<endl;
00835
00836
00837
00838
00839 Eigen::Vector3d speeds_angular = ((jacobian_inverted * speeds_3d) * (180./M_PI));
00840
00841 cout<<"FULL JACOBIAN ANGULAR SPEEDS [deg/s]"<<endl<<speeds_angular<<endl<<endl;
00842
00843 if(!isnan(speeds_angular[0]) || !isnan(speeds_angular[1]) || !isnan(speeds_angular[2]))
00844 {
00845 if(fabs(speeds_angular[0])<350. && fabs(speeds_angular[1])<350. && fabs(speeds_angular[2])<350.)
00846 {
00847 cout<<endl<<"-----> NON SINGULARITY!!!!!!!!"<<endl;
00848 RobotVars->parameters.arm_auto_angular_speed[0]=speeds_angular(0);
00849 RobotVars->parameters.arm_auto_angular_speed[1]=speeds_angular(1);
00850 RobotVars->parameters.arm_auto_angular_speed[2]=speeds_angular(2);
00851 return;
00852 }
00853 }
00854
00855 cout<<endl<<"-----> SINGULARITY!!!!!!!!"<<endl;
00856
00857
00858 RobotVars->humanoid_f->CalculateArmAlternateJacobian_No_Theta3_Singularity(RobotVars->robot_kin_data.LeftShoulderFlexion,
00859 RobotVars->robot_kin_data.LeftShoulderAbduction,
00860 RobotVars->robot_kin_data.LeftElbowFlexion,
00861 &jacobian_alternate);
00862
00863
00864
00865 arma::mat jacobian_non_square(3,2);
00866 for(int i=0; i<3; i++)
00867 {
00868 for(int j=0; j<2; j++)
00869 {
00870 jacobian_non_square(i,j)=jacobian_alternate(i,j);
00871 }
00872 }
00873
00874 arma::mat jacobian_non_square_pseudo_inverted = arma::pinv(jacobian_non_square);
00875
00876 for(int i=0; i<2; i++)
00877 {
00878 for(int j=0; j<3; j++)
00879 {
00880 jacobian_alternate_inverted(i,j)=jacobian_non_square_pseudo_inverted(i,j);
00881 }
00882 }
00883
00884 cout<<"REDUCED JACOBIAN MATRIX"<<endl<<jacobian_alternate<<endl;
00885
00886 cout<<"PSEUDO-INVERTED JACOBIAN MATRIX"<<endl<<jacobian_alternate_inverted<<endl;
00887
00888
00889
00890
00891 Eigen::Vector2d reduced_speeds_angular = ((jacobian_alternate_inverted * speeds_3d) * (180./M_PI));
00892
00893 cout<<"REDUCED JACOBIAN ANGULAR SPEEDS [deg/s]"<<endl<<reduced_speeds_angular<<endl<<endl<<"************************************************************"<<endl<<endl;
00894
00895 if(!isnan(reduced_speeds_angular(0)) || !isnan(reduced_speeds_angular(1)))
00896 {
00897 if(fabs(reduced_speeds_angular[0])<350. && fabs(reduced_speeds_angular[1])<350.)
00898 {
00899 RobotVars->parameters.arm_auto_angular_speed[0]=reduced_speeds_angular(0);
00900 RobotVars->parameters.arm_auto_angular_speed[1]=reduced_speeds_angular(1);
00901 RobotVars->parameters.arm_auto_angular_speed[2]=15.;
00902 return;
00903 }
00904 }
00905
00906
00907
00908
00909
00910 }
00911
00912 void StopRobotMovement(shared_vars_t*RobotVars)
00913 {
00914 cout<<"Setting Kinematic Model STOP!"<<endl;
00915 static double curr_jnt_val;
00916 int ret;
00917 if(RobotVars->parameters.kinematic_model==1)
00918 {
00919
00920
00921
00922 curr_jnt_val = ConvertServoValueByID(54,
00923 RobotVars->servo->SetSpeedPosition(54,
00924 RobotVars->parameters.arm_auto_speed[0]));
00925 ret=RobotVars->servo->SetPosition(54,RobotVars->humanoid_f->Shoulder_Flexion_Extension_Conversion(RIGHT,curr_jnt_val));
00926
00927
00928 curr_jnt_val = ConvertServoValueByID(53,
00929 RobotVars->servo->SetSpeedPosition(53,
00930 RobotVars->parameters.arm_auto_speed[1]));
00931 ret=RobotVars->servo->SetPosition(53,RobotVars->humanoid_f->Shoulder_Abduction_Adduction_Conversion(RIGHT,curr_jnt_val));
00932
00933
00934 curr_jnt_val=ConvertServoValueByID(51,
00935 RobotVars->servo->SetSpeedPosition(51,
00936 RobotVars->parameters.arm_auto_speed[2]));
00937 ret=RobotVars->servo->SetPosition(51,RobotVars->humanoid_f->Elbow_Flexion_Extension_Conversion(RIGHT,curr_jnt_val));
00938 }
00939 else if(RobotVars->parameters.kinematic_model==2)
00940 {
00941
00942
00943
00944 curr_jnt_val = ConvertServoValueByID(44,
00945 RobotVars->servo->SetSpeedPosition(44,
00946 RobotVars->parameters.arm_auto_speed[0]));
00947 ret=RobotVars->servo->SetPosition(44,RobotVars->humanoid_f->Shoulder_Flexion_Extension_Conversion(LEFT,curr_jnt_val));
00948
00949
00950 curr_jnt_val = ConvertServoValueByID(43,
00951 RobotVars->servo->SetSpeedPosition(43,
00952 RobotVars->parameters.arm_auto_speed[1]));
00953 ret=RobotVars->servo->SetPosition(43,RobotVars->humanoid_f->Shoulder_Abduction_Adduction_Conversion(LEFT,curr_jnt_val));
00954
00955
00956 curr_jnt_val=ConvertServoValueByID(41,
00957 RobotVars->servo->SetSpeedPosition(41,
00958 RobotVars->parameters.arm_auto_speed[2]));
00959 ret=RobotVars->servo->SetPosition(41,RobotVars->humanoid_f->Elbow_Flexion_Extension_Conversion(LEFT,curr_jnt_val));
00960 }
00961 else if(RobotVars->parameters.kinematic_model==3)
00962 {
00963
00964
00965
00966 curr_jnt_val = ConvertServoValueByID(54,
00967 RobotVars->servo->SetSpeedPosition(54,
00968 RobotVars->parameters.arm_auto_speed[0]));
00969 ret=RobotVars->servo->SetPosition(54,RobotVars->humanoid_f->Shoulder_Flexion_Extension_Conversion(RIGHT,curr_jnt_val));
00970
00971
00972 curr_jnt_val = ConvertServoValueByID(53,
00973 RobotVars->servo->SetSpeedPosition(53,
00974 RobotVars->parameters.arm_auto_speed[1]));
00975 ret=RobotVars->servo->SetPosition(53,RobotVars->humanoid_f->Shoulder_Abduction_Adduction_Conversion(RIGHT,curr_jnt_val));
00976
00977
00978 curr_jnt_val=ConvertServoValueByID(51,
00979 RobotVars->servo->SetSpeedPosition(51,
00980 RobotVars->parameters.arm_auto_speed[2]));
00981 ret=RobotVars->servo->SetPosition(51,RobotVars->humanoid_f->Elbow_Flexion_Extension_Conversion(RIGHT,curr_jnt_val));
00982
00983
00984
00985
00986 curr_jnt_val = ConvertServoValueByID(44,
00987 RobotVars->servo->SetSpeedPosition(44,
00988 RobotVars->parameters.arm_auto_speed[0]));
00989 ret=RobotVars->servo->SetPosition(44,RobotVars->humanoid_f->Shoulder_Flexion_Extension_Conversion(LEFT,curr_jnt_val));
00990
00991
00992 curr_jnt_val = ConvertServoValueByID(43,
00993 RobotVars->servo->SetSpeedPosition(43,
00994 RobotVars->parameters.arm_auto_speed[1]));
00995 ret=RobotVars->servo->SetPosition(43,RobotVars->humanoid_f->Shoulder_Abduction_Adduction_Conversion(LEFT,curr_jnt_val));
00996
00997
00998 curr_jnt_val=ConvertServoValueByID(41,
00999 RobotVars->servo->SetSpeedPosition(41,
01000 RobotVars->parameters.arm_auto_speed[2]));
01001 ret=RobotVars->servo->SetPosition(41,RobotVars->humanoid_f->Elbow_Flexion_Extension_Conversion(LEFT,curr_jnt_val));
01002 }
01003 }
01004
01005 void ArmsDifferencialSpeedControl(double *avg_speed, shared_vars_t*RobotVars)
01006 {
01007 static double curr_jnt_val;
01008 static double jnt_direction_right[3];
01009 static double jnt_direction_left[3];
01010 int ret;
01011
01012 if(RobotVars->parameters.kinematic_model==1)
01013 {
01014
01015
01016
01017 curr_jnt_val = ConvertServoValueByID(54,
01018 RobotVars->servo->SetSpeedPosition(54,
01019 RobotVars->parameters.arm_auto_speed[0]));
01020
01021 if(fabs(curr_jnt_val)<0.5 && fabs(curr_jnt_val)>0.)
01022 curr_jnt_val=0.;
01023 else if(fabs(curr_jnt_val)<90.5 && fabs(curr_jnt_val)>89.5)
01024 curr_jnt_val=90.;
01025 else if(fabs(curr_jnt_val)>179.5)
01026 curr_jnt_val=180.;
01027
01028 RobotVars->robot_kin_data.RightShoulderFlexion = curr_jnt_val;
01029
01030 curr_jnt_val = ConvertServoValueByID(53,
01031 RobotVars->servo->SetSpeedPosition(53,
01032 RobotVars->parameters.arm_auto_speed[1]));
01033
01034 if(fabs(curr_jnt_val)<0.5 && fabs(curr_jnt_val)>0.)
01035 curr_jnt_val=0.;
01036 else if(fabs(curr_jnt_val)<90.5 && fabs(curr_jnt_val)>89.5)
01037 curr_jnt_val=90.;
01038 else if(fabs(curr_jnt_val)>179.5)
01039 curr_jnt_val=180.;
01040
01041 RobotVars->robot_kin_data.RightShoulderAbduction = curr_jnt_val;
01042
01043 curr_jnt_val=ConvertServoValueByID(51,
01044 RobotVars->servo->SetSpeedPosition(51,
01045 RobotVars->parameters.arm_auto_speed[2]));
01046
01047 if(fabs(curr_jnt_val)<0.5 && fabs(curr_jnt_val)>0.)
01048 curr_jnt_val=0.;
01049 else if(fabs(curr_jnt_val)<90.5 && fabs(curr_jnt_val)>89.5)
01050 curr_jnt_val=90.;
01051 else if(fabs(curr_jnt_val)>179.5)
01052 curr_jnt_val=180.;
01053
01054 RobotVars->robot_kin_data.RightElbowFlexion = curr_jnt_val;
01055
01056
01057 avg_speed[2]=-avg_speed[2];
01058 CalculateDifferencialArmServoSpeed(avg_speed,RobotVars);
01059
01060
01061 SetArmAutomaticSpeeds(RIGHT, RobotVars);
01062
01063
01064 if(RobotVars->parameters.arm_auto_speed[0]!=0.)
01065 {
01066
01067 if(get_sign((double) RobotVars->parameters.arm_auto_angular_speed[0])!=jnt_direction_right[0])
01068 {
01069 jnt_direction_right[0]=get_sign((double) RobotVars->parameters.arm_auto_angular_speed[0]);
01070 if(jnt_direction_right[0]>0)
01071 ret=RobotVars->servo->SetPosition(54,RobotVars->humanoid_f->Shoulder_Flexion_Extension_Conversion(RIGHT,135.));
01072 else
01073 ret=RobotVars->servo->SetPosition(54,RobotVars->humanoid_f->Shoulder_Flexion_Extension_Conversion(RIGHT,-45));
01074 }
01075 }
01076 if(RobotVars->parameters.arm_auto_speed[1]!=0.)
01077 {
01078
01079 if(get_sign((double) RobotVars->parameters.arm_auto_angular_speed[1])!=jnt_direction_right[1])
01080 {
01081 jnt_direction_right[1]=get_sign((double) RobotVars->parameters.arm_auto_angular_speed[1]);
01082 if(jnt_direction_right[1]>0)
01083 ret=RobotVars->servo->SetPosition(53,RobotVars->humanoid_f->Shoulder_Abduction_Adduction_Conversion(RIGHT,180.));
01084 else
01085 ret=RobotVars->servo->SetPosition(53,RobotVars->humanoid_f->Shoulder_Abduction_Adduction_Conversion(RIGHT,0.));
01086 }
01087 }
01088 if(RobotVars->parameters.arm_auto_speed[2]!=0.)
01089 {
01090
01091 if(get_sign((double) RobotVars->parameters.arm_auto_angular_speed[2])!=jnt_direction_right[2])
01092 {
01093 jnt_direction_right[2]=get_sign((double) RobotVars->parameters.arm_auto_angular_speed[2]);
01094 if(jnt_direction_right[2]>0)
01095 ret=RobotVars->servo->SetPosition(51,RobotVars->humanoid_f->Elbow_Flexion_Extension_Conversion(RIGHT,120.));
01096 else
01097 ret=RobotVars->servo->SetPosition(51,RobotVars->humanoid_f->Elbow_Flexion_Extension_Conversion(RIGHT,0.));
01098 }
01099 }
01100 }
01101 else if(RobotVars->parameters.kinematic_model==2)
01102 {
01103
01104
01105
01106 curr_jnt_val = ConvertServoValueByID(44,
01107 RobotVars->servo->SetSpeedPosition(44,
01108 RobotVars->parameters.arm_auto_speed[0]));
01109
01110 if(fabs(curr_jnt_val)<0.5 && fabs(curr_jnt_val)>0.)
01111 curr_jnt_val=0.;
01112 else if(fabs(curr_jnt_val)<90.5 && fabs(curr_jnt_val)>89.5)
01113 curr_jnt_val=90.;
01114 else if(fabs(curr_jnt_val)>179.5 && fabs(curr_jnt_val)<180.5)
01115 curr_jnt_val=180.;
01116 else if(fabs(curr_jnt_val)>180.5)
01117 cout<<"Servo responce error..."<<endl;
01118
01119 RobotVars->robot_kin_data.LeftShoulderFlexion = curr_jnt_val;
01120
01121 curr_jnt_val = ConvertServoValueByID(43,
01122 RobotVars->servo->SetSpeedPosition(43,
01123 RobotVars->parameters.arm_auto_speed[1]));
01124
01125 if(fabs(curr_jnt_val)<0.5 && fabs(curr_jnt_val)>0.)
01126 curr_jnt_val=0.;
01127 else if(fabs(curr_jnt_val)<90.5 && fabs(curr_jnt_val)>89.5)
01128 curr_jnt_val=90.;
01129 else if(fabs(curr_jnt_val)>179.5 && fabs(curr_jnt_val)<180.5)
01130 curr_jnt_val=180.;
01131 else if(fabs(curr_jnt_val)>180.5)
01132 cout<<"Servo responce error..."<<endl;
01133
01134 RobotVars->robot_kin_data.LeftShoulderAbduction = curr_jnt_val;
01135
01136 curr_jnt_val=ConvertServoValueByID(41,
01137 RobotVars->servo->SetSpeedPosition(41,
01138 RobotVars->parameters.arm_auto_speed[2]));
01139
01140 if(fabs(curr_jnt_val)<0.5 && fabs(curr_jnt_val)>0.)
01141 curr_jnt_val=0.;
01142 else if(fabs(curr_jnt_val)<90.5 && fabs(curr_jnt_val)>89.5)
01143 curr_jnt_val=90.;
01144 else if(fabs(curr_jnt_val)>179.5 && fabs(curr_jnt_val)<180.5)
01145 curr_jnt_val=180.;
01146 else if(fabs(curr_jnt_val)>180.5)
01147 cout<<"Servo responce error..."<<endl;
01148
01149
01150 RobotVars->robot_kin_data.LeftElbowFlexion = curr_jnt_val;
01151
01152
01153 CalculateDifferencialArmServoSpeed(avg_speed,RobotVars);
01154
01155
01156 SetArmAutomaticSpeeds(LEFT, RobotVars);
01157
01158
01159
01160 if(get_sign((double) RobotVars->parameters.arm_auto_angular_speed[0])!=jnt_direction_left[0])
01161 {
01162 jnt_direction_left[0]=get_sign((double) RobotVars->parameters.arm_auto_angular_speed[0]);
01163 if(jnt_direction_left[0]>0)
01164 ret=RobotVars->servo->SetPosition(44,RobotVars->humanoid_f->Shoulder_Flexion_Extension_Conversion(LEFT,135.));
01165 else
01166 ret=RobotVars->servo->SetPosition(44,RobotVars->humanoid_f->Shoulder_Flexion_Extension_Conversion(LEFT,-45));
01167 }
01168
01169 if(get_sign((double) RobotVars->parameters.arm_auto_angular_speed[1])!=jnt_direction_left[1])
01170 {
01171 jnt_direction_left[1]=get_sign((double) RobotVars->parameters.arm_auto_angular_speed[1]);
01172 if(jnt_direction_left[1]>0)
01173 ret=RobotVars->servo->SetPosition(43,RobotVars->humanoid_f->Shoulder_Abduction_Adduction_Conversion(LEFT,180.));
01174 else
01175 ret=RobotVars->servo->SetPosition(43,RobotVars->humanoid_f->Shoulder_Abduction_Adduction_Conversion(LEFT,0.));;
01176 }
01177
01178 if(get_sign((double) RobotVars->parameters.arm_auto_angular_speed[2])!=jnt_direction_left[2])
01179 {
01180 jnt_direction_left[2]=get_sign((double) RobotVars->parameters.arm_auto_angular_speed[2]);
01181 if(jnt_direction_left[2]>0)
01182 ret=RobotVars->servo->SetPosition(41,RobotVars->humanoid_f->Elbow_Flexion_Extension_Conversion(LEFT,120.));
01183 else
01184 ret=RobotVars->servo->SetPosition(41,RobotVars->humanoid_f->Elbow_Flexion_Extension_Conversion(LEFT,0.));
01185 }
01186 }
01187 else if(RobotVars->parameters.kinematic_model==3)
01188 {
01189
01190
01191 curr_jnt_val = ConvertServoValueByID(44,
01192 RobotVars->servo->SetSpeedPosition(44,
01193 RobotVars->parameters.arm_auto_speed[0]));
01194
01195 if(fabs(curr_jnt_val)<0.5 && fabs(curr_jnt_val)>0.)
01196 curr_jnt_val=0.;
01197 else if(fabs(curr_jnt_val)<90.5 && fabs(curr_jnt_val)>89.5)
01198 curr_jnt_val=90.;
01199 else if(fabs(curr_jnt_val)>179.5)
01200 curr_jnt_val=180.;
01201
01202 RobotVars->robot_kin_data.LeftShoulderFlexion = curr_jnt_val;
01203
01204 curr_jnt_val = ConvertServoValueByID(43,
01205 RobotVars->servo->SetSpeedPosition(43,
01206 RobotVars->parameters.arm_auto_speed[1]));
01207
01208 if(fabs(curr_jnt_val)<0.5 && fabs(curr_jnt_val)>0.)
01209 curr_jnt_val=0.;
01210 else if(fabs(curr_jnt_val)<90.5 && fabs(curr_jnt_val)>89.5)
01211 curr_jnt_val=90.;
01212 else if(fabs(curr_jnt_val)>179.5)
01213 curr_jnt_val=180.;
01214
01215 RobotVars->robot_kin_data.LeftShoulderAbduction = curr_jnt_val;
01216
01217 curr_jnt_val=ConvertServoValueByID(41,
01218 RobotVars->servo->SetSpeedPosition(41,
01219 RobotVars->parameters.arm_auto_speed[2]));
01220
01221 if(fabs(curr_jnt_val)<0.5 && fabs(curr_jnt_val)>0.)
01222 curr_jnt_val=0.;
01223 else if(fabs(curr_jnt_val)<90.5 && fabs(curr_jnt_val)>89.5)
01224 curr_jnt_val=90.;
01225 else if(fabs(curr_jnt_val)>179.5)
01226 curr_jnt_val=180.;
01227
01228 RobotVars->robot_kin_data.LeftElbowFlexion = curr_jnt_val;
01229
01230
01231 CalculateDifferencialArmServoSpeed(avg_speed,RobotVars);
01232
01233 SetArmAutomaticSpeeds(LEFT, RobotVars);
01234
01235
01236
01237
01238 if(get_sign((double) RobotVars->parameters.arm_auto_angular_speed[0])!=jnt_direction_left[0])
01239 {
01240 jnt_direction_left[0]=get_sign((double) RobotVars->parameters.arm_auto_angular_speed[0]);
01241 if(jnt_direction_left[0]>0)
01242 ret=RobotVars->servo->SetPosition(44,RobotVars->humanoid_f->Shoulder_Flexion_Extension_Conversion(LEFT,135.));
01243 else
01244 ret=RobotVars->servo->SetPosition(44,RobotVars->humanoid_f->Shoulder_Flexion_Extension_Conversion(LEFT,-45));
01245 }
01246
01247 if(get_sign((double) RobotVars->parameters.arm_auto_angular_speed[1])!=jnt_direction_left[1])
01248 {
01249 jnt_direction_left[1]=get_sign((double) RobotVars->parameters.arm_auto_angular_speed[1]);
01250 if(jnt_direction_left[1]>0)
01251 ret=RobotVars->servo->SetPosition(43,RobotVars->humanoid_f->Shoulder_Abduction_Adduction_Conversion(LEFT,180.));
01252 else
01253 ret=RobotVars->servo->SetPosition(43,RobotVars->humanoid_f->Shoulder_Abduction_Adduction_Conversion(LEFT,0.));
01254 }
01255
01256 if(get_sign((double) RobotVars->parameters.arm_auto_angular_speed[2])!=jnt_direction_left[2])
01257 {
01258 jnt_direction_left[2]=get_sign((double) RobotVars->parameters.arm_auto_angular_speed[2]);
01259 if(jnt_direction_left[2]>0)
01260 ret=RobotVars->servo->SetPosition(41,RobotVars->humanoid_f->Elbow_Flexion_Extension_Conversion(LEFT,120.));
01261 else
01262 ret=RobotVars->servo->SetPosition(41,RobotVars->humanoid_f->Elbow_Flexion_Extension_Conversion(LEFT,0.));
01263 }
01264
01265
01266
01267
01268 curr_jnt_val = ConvertServoValueByID(54,
01269 RobotVars->servo->SetSpeedPosition(54,
01270 RobotVars->parameters.arm_auto_speed[0]));
01271
01272 if(fabs(curr_jnt_val)<0.5 && fabs(curr_jnt_val)>0.)
01273 curr_jnt_val=0.;
01274 else if(fabs(curr_jnt_val)<90.5 && fabs(curr_jnt_val)>89.5)
01275 curr_jnt_val=90.;
01276 else if(fabs(curr_jnt_val)>179.5)
01277 curr_jnt_val=180.;
01278
01279 RobotVars->robot_kin_data.RightShoulderFlexion = curr_jnt_val;
01280
01281 curr_jnt_val = ConvertServoValueByID(53,
01282 RobotVars->servo->SetSpeedPosition(53,
01283 RobotVars->parameters.arm_auto_speed[1]));
01284
01285 if(fabs(curr_jnt_val)<0.5 && fabs(curr_jnt_val)>0.)
01286 curr_jnt_val=0.;
01287 else if(fabs(curr_jnt_val)<90.5 && fabs(curr_jnt_val)>89.5)
01288 curr_jnt_val=90.;
01289 else if(fabs(curr_jnt_val)>179.5)
01290 curr_jnt_val=180.;
01291
01292 RobotVars->robot_kin_data.RightShoulderAbduction = curr_jnt_val;
01293
01294 curr_jnt_val=ConvertServoValueByID(51,
01295 RobotVars->servo->SetSpeedPosition(51,
01296 RobotVars->parameters.arm_auto_speed[2]));
01297
01298 if(fabs(curr_jnt_val)<0.5 && fabs(curr_jnt_val)>0.)
01299 curr_jnt_val=0.;
01300 else if(fabs(curr_jnt_val)<90.5 && fabs(curr_jnt_val)>89.5)
01301 curr_jnt_val=90.;
01302 else if(fabs(curr_jnt_val)>179.5)
01303 curr_jnt_val=180.;
01304
01305 RobotVars->robot_kin_data.RightElbowFlexion = curr_jnt_val;
01306
01307
01308 avg_speed[2]=-avg_speed[2];
01309 CalculateDifferencialArmServoSpeed(avg_speed,RobotVars);
01310
01311
01312 SetArmAutomaticSpeeds(RIGHT, RobotVars);
01313
01314
01315
01316
01317 if(get_sign((double) RobotVars->parameters.arm_auto_angular_speed[0])!=jnt_direction_right[0])
01318 {
01319 jnt_direction_right[0]=get_sign((double) RobotVars->parameters.arm_auto_angular_speed[0]);
01320 if(jnt_direction_right[0]>0)
01321 ret=RobotVars->servo->SetPosition(54,RobotVars->humanoid_f->Shoulder_Flexion_Extension_Conversion(RIGHT,135.));
01322 else
01323 ret=RobotVars->servo->SetPosition(54,RobotVars->humanoid_f->Shoulder_Flexion_Extension_Conversion(RIGHT,-45));
01324 }
01325
01326 if(get_sign((double) RobotVars->parameters.arm_auto_angular_speed[1])!=jnt_direction_right[1])
01327 {
01328 jnt_direction_right[1]=get_sign((double) RobotVars->parameters.arm_auto_angular_speed[1]);
01329 if(jnt_direction_right[1]>0)
01330 ret=RobotVars->servo->SetPosition(53,RobotVars->humanoid_f->Shoulder_Abduction_Adduction_Conversion(RIGHT,180.));
01331 else
01332 ret=RobotVars->servo->SetPosition(53,RobotVars->humanoid_f->Shoulder_Abduction_Adduction_Conversion(RIGHT,0.));
01333 }
01334
01335 if(get_sign((double) RobotVars->parameters.arm_auto_angular_speed[2])!=jnt_direction_right[2])
01336 {
01337 jnt_direction_right[2]=get_sign((double) RobotVars->parameters.arm_auto_angular_speed[2]);
01338 if(jnt_direction_right[2]>0)
01339 ret=RobotVars->servo->SetPosition(51,RobotVars->humanoid_f->Elbow_Flexion_Extension_Conversion(RIGHT,120.));
01340 else
01341 ret=RobotVars->servo->SetPosition(51,RobotVars->humanoid_f->Elbow_Flexion_Extension_Conversion(RIGHT,0.));
01342 }
01343 }
01344 }
01345
01346
01347 void DemoUserPath_WritePoints(shared_vars_t*RobotVars)
01348 {
01349 static string file_path = ros::package::getPath("phua_haptic") + "/pnts/" + POINTS_FILE_NAME_STRING;
01350 static ofstream pnts_file;
01351
01352 pnts_file.open(file_path.c_str(),ios::app);
01353 if(pnts_file)
01354 {
01355
01356 if(RobotVars->parameters.kinematic_model==1)
01357 {
01358 pnts_file << RIGHT_ARM_SAVE_STRING;
01359 }
01360 else if(RobotVars->parameters.kinematic_model==2)
01361 {
01362 pnts_file << LEFT_ARM_SAVE_STRING;
01363 }
01364 else if(RobotVars->parameters.kinematic_model==3)
01365 {
01366 pnts_file << BOTH_ARMS_SAVE_STRING;
01367 }
01368 else if(RobotVars->parameters.kinematic_model==4)
01369 {
01370 pnts_file << LEFT_D_LEG_SAVE_STRING;
01371 }
01372 else if(RobotVars->parameters.kinematic_model==5)
01373 {
01374 pnts_file << RIGHT_D_LEG_SAVE_STRING;
01375 }
01376
01377 if(RobotVars->parameters.kinematic_model==1)
01378 {
01379
01380 pnts_file << RobotVars->robot_kin_data.X_arm_end_right << " "
01381 << RobotVars->robot_kin_data.Y_arm_end_right << " "
01382 << RobotVars->robot_kin_data.Z_arm_end_right << endl;
01383 }
01384 else if(RobotVars->parameters.kinematic_model==2)
01385 {
01386
01387 pnts_file <<RobotVars->robot_kin_data.X_arm_end_left << " "
01388 << RobotVars->robot_kin_data.Y_arm_end_left << " "
01389 << RobotVars->robot_kin_data.Z_arm_end_left << endl;
01390 }
01391 else if(RobotVars->parameters.kinematic_model==3)
01392 {
01393
01394 pnts_file <<RobotVars->robot_kin_data.X_arm_end_left << " "
01395 << RobotVars->robot_kin_data.Y_arm_end_left << " "
01396 << RobotVars->robot_kin_data.Z_arm_end_left << endl;
01397 }
01398 else if(RobotVars->parameters.kinematic_model==4)
01399 {
01400
01401 pnts_file << RobotVars->robot_kin_data.detached_leg_pos_left[0] << " "
01402 << RobotVars->robot_kin_data.detached_leg_pos_left[1] << " "
01403 << RobotVars->robot_kin_data.detached_leg_pos_left[2] << endl;
01404 }
01405 else if(RobotVars->parameters.kinematic_model==5)
01406 {
01407
01408 pnts_file << RobotVars->robot_kin_data.detached_leg_pos_right[0] << " "
01409 << RobotVars->robot_kin_data.detached_leg_pos_right[1] << " "
01410 << RobotVars->robot_kin_data.detached_leg_pos_right[2] << endl;
01411 }
01412
01413 pnts_file.close();
01414 }
01415 else
01416 {
01417 perror("Points file error");
01418 }
01419
01420 }
01421
01422 void DemoUserPath_ReadPoints(shared_vars_t*RobotVars)
01423 {
01424 static string file_path = ros::package::getPath("phua_haptic") + "/pnts/" + POINTS_FILE_NAME_STRING;
01425 static ifstream pnts_file;
01426 string STRING;
01427
01428 int line = 1;
01429
01430 pnts_file.open(file_path.c_str());
01431
01432 if(pnts_file)
01433 {
01434
01435 RobotVars->haptics_data.user_path_X_pnts.clear();
01436 RobotVars->haptics_data.user_path_Y_pnts.clear();
01437 RobotVars->haptics_data.user_path_Z_pnts.clear();
01438
01439 while(!pnts_file.eof())
01440 {
01441 getline(pnts_file,STRING);
01442 string::iterator it1,it2;
01443 it1 = STRING.begin();
01444
01445 if(STRING.compare(RIGHT_ARM_SAVE_STRING) > 1 && RobotVars->parameters.kinematic_model==1)
01446 {
01447 it2 = STRING.begin() + strlen(RIGHT_ARM_SAVE_STRING);
01448 STRING.erase(it1,it2);
01449
01450 std::istringstream iss(STRING);
01451 double value;
01452 int i = 0;
01453 while ( iss >> value )
01454 {
01455 if(i == 0)
01456 RobotVars->haptics_data.user_path_X_pnts.push_back(value);
01457 else if(i ==1)
01458 RobotVars->haptics_data.user_path_Y_pnts.push_back(value);
01459 else if(i == 2)
01460 RobotVars->haptics_data.user_path_Z_pnts.push_back(value);
01461 i++;
01462 }
01463 }
01464 else if(STRING.compare(LEFT_ARM_SAVE_STRING) > 1 && RobotVars->parameters.kinematic_model==2)
01465 {
01466 it2 = STRING.begin() + strlen(LEFT_ARM_SAVE_STRING);
01467 STRING.erase(it1,it2);
01468
01469 std::istringstream iss(STRING);
01470 double value;
01471 int i = 0;
01472 while ( iss >> value )
01473 {
01474 if(i == 0)
01475 RobotVars->haptics_data.user_path_X_pnts.push_back(value);
01476 else if(i ==1)
01477 RobotVars->haptics_data.user_path_Y_pnts.push_back(value);
01478 else if(i == 2)
01479 RobotVars->haptics_data.user_path_Z_pnts.push_back(value);
01480 i++;
01481 }
01482 }
01483 else if(STRING.compare(BOTH_ARMS_SAVE_STRING) > 1 && RobotVars->parameters.kinematic_model==3)
01484 {
01485 it2 = STRING.begin() + strlen(BOTH_ARMS_SAVE_STRING);
01486 STRING.erase(it1,it2);
01487
01488 std::istringstream iss(STRING);
01489 double value;
01490 int i = 0;
01491 while ( iss >> value )
01492 {
01493 if(i == 0)
01494 RobotVars->haptics_data.user_path_X_pnts.push_back(value);
01495 else if(i ==1)
01496 RobotVars->haptics_data.user_path_Y_pnts.push_back(value);
01497 else if(i == 2)
01498 RobotVars->haptics_data.user_path_Z_pnts.push_back(value);
01499 i++;
01500 }
01501 }
01502 else if(STRING.compare(RIGHT_D_LEG_SAVE_STRING) > 1 && RobotVars->parameters.kinematic_model==5)
01503 {
01504 it2 = STRING.begin() + strlen(RIGHT_D_LEG_SAVE_STRING);
01505 STRING.erase(it1,it2);
01506
01507 std::istringstream iss(STRING);
01508 double value;
01509 int i = 0;
01510 while ( iss >> value )
01511 {
01512 if(i == 0)
01513 RobotVars->haptics_data.user_path_X_pnts.push_back(value);
01514 else if(i ==1)
01515 RobotVars->haptics_data.user_path_Y_pnts.push_back(value);
01516 else if(i == 2)
01517 RobotVars->haptics_data.user_path_Z_pnts.push_back(value);
01518 i++;
01519 }
01520 }
01521 else if(STRING.compare(LEFT_D_LEG_SAVE_STRING) > 1 && RobotVars->parameters.kinematic_model==4)
01522 {
01523 it2 = STRING.begin() + strlen(LEFT_D_LEG_SAVE_STRING);
01524 STRING.erase(it1,it2);
01525
01526 std::istringstream iss(STRING);
01527 double value;
01528 int i = 0;
01529 while ( iss >> value )
01530 {
01531 if(i == 0)
01532 RobotVars->haptics_data.user_path_X_pnts.push_back(value);
01533 else if(i ==1)
01534 RobotVars->haptics_data.user_path_Y_pnts.push_back(value);
01535 else if(i == 2)
01536 RobotVars->haptics_data.user_path_Z_pnts.push_back(value);
01537 i++;
01538 }
01539 }
01540 else
01541 {
01542 if(STRING.size()>0)
01543 {
01544 cout << "Points file error @ line " << line << ".";
01545 RobotVars->haptics_data.demo_user_path_run_start = FALSE;
01546 pnts_file.close();
01547 return;
01548 }
01549
01550 }
01551 line++;
01552 }
01553 pnts_file.close();
01554 if(RobotVars->haptics_data.user_path_X_pnts.size()>0 && RobotVars->haptics_data.user_path_Y_pnts.size()>0 && RobotVars->haptics_data.user_path_Z_pnts.size()>0)
01555 {
01556
01557 RobotVars->haptics_data.demo_user_path_run_start = TRUE;
01558 }
01559 else
01560 {
01561 cout << "NO POINTS READ!" << endl;
01562 RobotVars->haptics_data.demo_user_path_run_start = FALSE;
01563 }
01564 }
01565 else
01566 {
01567 perror("Points file error");
01568 RobotVars->haptics_data.demo_user_path_run_start = FALSE;
01569 }
01570 }
01571
01572 void PathFollowingExecute(shared_vars_t*RobotVars)
01573 {
01574 static unsigned int incr = 0;
01575 static double next_point[3];
01576 static double curr_point[3];
01577
01578 if((RobotVars->haptics_data.user_path_X_pnts.size()>0 && RobotVars->haptics_data.user_path_Y_pnts.size()>0 && RobotVars->haptics_data.user_path_Z_pnts.size()>0)
01579 &&
01580 RobotVars->haptics_data.chosen_demo == 3
01581 &&
01582 RobotVars->haptics_data.demo_user_path_run_start)
01583 {
01584 next_point[0] = RobotVars->haptics_data.user_path_X_pnts[incr];
01585 next_point[1] = RobotVars->haptics_data.user_path_Y_pnts[incr];
01586 next_point[2] = RobotVars->haptics_data.user_path_Z_pnts[incr];
01587
01588 double margin = (double)PATH_FOLLOWING_POSITION_ERROR;
01589
01590
01591 UpdateJointDataByID(1000, 0., RobotVars);
01592
01593
01594 if(RobotVars->parameters.kinematic_model==1)
01595 {
01596
01597 UpdateArmsDirKinData(RobotVars);
01598 curr_point[0] = RobotVars->robot_kin_data.X_arm_end_right;
01599 curr_point[1] = RobotVars->robot_kin_data.Y_arm_end_right;
01600 curr_point[2] = RobotVars->robot_kin_data.Z_arm_end_right;
01601 }
01602 else if(RobotVars->parameters.kinematic_model==2)
01603 {
01604
01605 UpdateArmsDirKinData(RobotVars);
01606 curr_point[0] = RobotVars->robot_kin_data.X_arm_end_left;
01607 curr_point[1] = RobotVars->robot_kin_data.Y_arm_end_left;
01608 curr_point[2] = RobotVars->robot_kin_data.Z_arm_end_left;
01609 }
01610 else if(RobotVars->parameters.kinematic_model==3)
01611 {
01612
01613 UpdateArmsDirKinData(RobotVars);
01614 curr_point[0] = RobotVars->robot_kin_data.X_arm_end_right;
01615 curr_point[1] = RobotVars->robot_kin_data.Y_arm_end_right;
01616 curr_point[2] = RobotVars->robot_kin_data.Z_arm_end_right;
01617 }
01618 else if(RobotVars->parameters.kinematic_model==4)
01619 {
01620
01621 UpdateDetachedLegsDirKinData(RobotVars);
01622 memcpy(&curr_point, RobotVars->robot_kin_data.detached_leg_pos_left, sizeof(RobotVars->robot_kin_data.detached_leg_pos_left));
01623 }
01624 else if(RobotVars->parameters.kinematic_model==5)
01625 {
01626
01627 UpdateDetachedLegsDirKinData(RobotVars);
01628 memcpy(&curr_point, RobotVars->robot_kin_data.detached_leg_pos_right, sizeof(RobotVars->robot_kin_data.detached_leg_pos_right));
01629 }
01630
01631
01632 if(IsWithinRange(curr_point[0], (next_point[0] - margin), (next_point[0] + margin))
01633 &&
01634 IsWithinRange(curr_point[1], (next_point[1] - margin), (next_point[1] + margin))
01635 &&
01636 IsWithinRange(curr_point[2], (next_point[2] - margin), (next_point[2] + margin)))
01637 {
01638
01639 cout<<"-> Reached point "<<incr+1<<": X["<<curr_point[0]<<"] Y["<<curr_point[1]<<"] Z["<<curr_point[2]<<"]"<<endl;
01640
01641 incr++;
01642 }
01643 else
01644 {
01645 cout<<"-> Sending next point: X["<<next_point[0]<<"] Y["<<next_point[1]<<"] Z["<<next_point[2]<<"]"<<endl;
01646
01647 if(RobotVars->parameters.kinematic_model==1)
01648 {
01649 MoveArmToCartesianPosition(next_point[0],
01650 next_point[1],
01651 next_point[2],
01652 RIGHT,
01653 RobotVars);
01654 }
01655 else if(RobotVars->parameters.kinematic_model==2)
01656 {
01657 MoveArmToCartesianPosition(next_point[0],
01658 next_point[1],
01659 next_point[2],
01660 LEFT,
01661 RobotVars);
01662 }
01663 else if(RobotVars->parameters.kinematic_model==3)
01664 {
01665 MoveArmToCartesianPosition(next_point[0],
01666 next_point[1],
01667 next_point[2],
01668 RIGHT,
01669 RobotVars);
01670 MoveArmToCartesianPosition(next_point[0],
01671 next_point[1],
01672 next_point[2],
01673 LEFT,
01674 RobotVars);
01675 }
01676 else if(RobotVars->parameters.kinematic_model==4)
01677 {
01678 MoveDetachedLegToCartesianPosition(next_point[0],
01679 next_point[1],
01680 next_point[2],
01681 0.,
01682 LEFT,
01683 RobotVars);
01684 }
01685 else if(RobotVars->parameters.kinematic_model==5)
01686 {
01687 MoveDetachedLegToCartesianPosition(next_point[0],
01688 next_point[1],
01689 next_point[2],
01690 0.,
01691 RIGHT,
01692 RobotVars);
01693 }
01694 }
01695
01696 cout<<"INCR: "<<incr<<endl;
01697 cout<<"SIZE: "<<RobotVars->haptics_data.user_path_X_pnts.size()<<endl;
01698 cout<<"CHECK INCR: "<<(incr > RobotVars->haptics_data.user_path_X_pnts.size() ? "TRUE" : "FALSE" )<<endl;
01699
01700 if(incr >= RobotVars->haptics_data.user_path_X_pnts.size())
01701 {
01702
01703 if(RobotVars->haptics_data.demo_user_path_is_run_once)
01704 {
01705
01706 incr = 0;
01707 RobotVars->haptics_data.demo_user_path_run_start = FALSE;
01708 cout<<"-> End!"<<endl;
01709
01710
01711
01712
01713
01714
01715
01716
01717
01718
01719
01720
01721
01722
01723
01724
01725
01726
01727
01728
01729
01730
01731
01732
01733
01734
01735
01736
01737
01738
01739
01740
01741
01742
01743
01744
01745
01746
01747
01748
01749 SetRobotHomePosition(RobotVars);
01750 return;
01751 }
01752 else
01753 {
01754
01755 incr = 0;
01756 cout<<"-> Restarting routine."<<endl;
01757 return;
01758 }
01759 }
01760 }
01761 else
01762 {
01763 incr = 0;
01764 return;
01765 }
01766 }
01767
01768 void UpdateKinematicModelDirKin(shared_vars_t*RobotVars)
01769 {
01770
01771 if(RobotVars->parameters.kinematic_model==1)
01772 {
01773
01774 UpdateArmsDirKinData(RobotVars);
01775 }
01776 else if(RobotVars->parameters.kinematic_model==2)
01777 {
01778
01779 UpdateArmsDirKinData(RobotVars);
01780 }
01781 else if(RobotVars->parameters.kinematic_model==3)
01782 {
01783
01784 UpdateArmsDirKinData(RobotVars);
01785 }
01786 else if(RobotVars->parameters.kinematic_model==4)
01787 {
01788
01789 UpdateDetachedLegsDirKinData(RobotVars);
01790 }
01791 else if(RobotVars->parameters.kinematic_model==5)
01792 {
01793
01794 UpdateDetachedLegsDirKinData(RobotVars);
01795 }
01796 else
01797 {
01798 UpdateArmsDirKinData(RobotVars);
01799 UpdateDetachedLegsDirKinData(RobotVars);
01800 }
01801 }