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
00027
00034 #include <humanoid_control/servohumanoid.h>
00035
00036
00037 ServoHumanoid::ServoHumanoid(const char* path)
00038 {
00039 SetParameters();
00040
00041 hitec=(hitec_5980SG*) new hitec_5980SG(path);
00042
00043
00044
00045 int speed=25;
00046 int position;
00047
00048
00049 const short int id_list[12]={11,21,12,22,13,32,15,25,16,26,31,23};
00050 for(int i=0;i<12;i++)
00051 {
00052 position=SetJointSpeed(id_list[i],speed);
00053 ROS_INFO("Servo %d --> responce : %d", id_list[i], position);
00054 RoboState.joint_wanted[i]=0;
00055 }
00056 }
00057
00058 void ServoHumanoid::SetParameters(void)
00059 {
00060
00061 robot_dimensions.arm_length = 123.;
00062 robot_dimensions.forearm_length = 106.;
00063 robot_dimensions.shin_length = 139.;
00064 robot_dimensions.thigh_length = 143.;
00065 robot_dimensions.foot_length = 150.;
00066 robot_dimensions.foot_width = 50.;
00067 robot_dimensions.ankle_height = 50.;
00068
00069
00070
00071 robot_servo_conversion.head_servo_offset = 2400.;
00072 robot_servo_conversion.shoulder_flexion_servo_offset_left = 1050.;
00073 robot_servo_conversion.shoulder_flexion_servo_offset_right = 1975.;
00074 robot_servo_conversion.shoulder_abduction_servo_offset_left = 600.;
00075 robot_servo_conversion.shoulder_abduction_servo_offset_right = 2400.;
00076 robot_servo_conversion.elbow_flexion_servo_offset_left = 2400.;
00077 robot_servo_conversion.elbow_flexion_servo_offset_right = 600.;
00078 robot_servo_conversion.torso_rotation_servo_offset = 1500.;
00079 robot_servo_conversion.torso_flexion_servo_offset = 750.;
00080 robot_servo_conversion.torso_lateral_flexion_servo_offset = 1500.;
00081 robot_servo_conversion.knee_flexion_b_value_left = 600.;
00082 robot_servo_conversion.knee_flexion_b_value_right = 2400.;
00083 robot_servo_conversion.hip_flexion_b_value_left = 900.;
00084 robot_servo_conversion.hip_flexion_b_value_right = 1600.;
00085
00086 robot_joint_limits.head_min_tilt = 0.;
00087 robot_joint_limits.head_max_tilt = 10.;
00088 robot_joint_limits.shoulder_min_flexion = -45.;
00089 robot_joint_limits.shoulder_max_flexion = 135.;
00090 robot_joint_limits.shoulder_min_abduction = 0.;
00091 robot_joint_limits.shoulder_max_abduction = 180.;
00092 robot_joint_limits.elbow_min_flexion = 0.;
00093 robot_joint_limits.elbow_max_flexion = 120.;
00094 robot_joint_limits.torso_min_rotation = -90.;
00095 robot_joint_limits.torso_max_rotation = 90.;
00096 robot_joint_limits.torso_min_flexion = -15.;
00097 robot_joint_limits.torso_max_flexion = 90.;
00098 robot_joint_limits.torso_min_lateral_flexion = -90.;
00099 robot_joint_limits.torso_max_lateral_flexion = 90.;
00100 robot_joint_limits.ankle_min_inversion = -30.;
00101 robot_joint_limits.ankle_max_inversion = 45.;
00102 robot_joint_limits.ankle_min_flexion = -40.;
00103 robot_joint_limits.ankle_max_flexion = 20.;
00104 robot_joint_limits.knee_min_flexion = 0.;
00105 robot_joint_limits.knee_max_flexion = 130.;
00106 robot_joint_limits.hip_min_abduction = -40.;
00107 robot_joint_limits.hip_max_abduction = 45;
00108 robot_joint_limits.hip_min_flexion = -30.;
00109 robot_joint_limits.hip_max_flexion = 120.;
00110
00111 robot_element_mass.foot_mass = 0.444;
00112 robot_element_mass.shin_mass = 0.343;
00113 robot_element_mass.thigh_mass = 0.243;
00114
00115 robot_relative_COM.foot_CoM << 9.06, 2.746, 31.7;
00116 robot_relative_COM.shin_CoM << 0.182, 15.861, 88.519;
00117 robot_relative_COM.thigh_CoM << -2.262, 1.418, 101.284;
00118
00119
00120 joint_offset.torso_rotation_joint_offset=0.;
00121 joint_offset.torso_flexion_joint_offset=-20.;
00122 joint_offset.torso_lateral_flexion_joint_offset=0.;
00123 joint_offset.knee_flexion_joint_offset_left=0. + 5.;
00124 joint_offset.knee_flexion_joint_offset_right=-3. + 5.;
00125 joint_offset.hip_flexion_joint_offset_left=-5. - 5;
00126 joint_offset.hip_flexion_joint_offset_right=5. - 5;
00127 joint_offset.hip_abduction_joint_offset_left=-3.;
00128 joint_offset.hip_abduction_joint_offset_right=0.;
00129 joint_offset.feet_flexion_joint_offset_left=5. ;
00130 joint_offset.feet_flexion_joint_offset_right=5. ;
00131 joint_offset.feet_inversion_joint_offset_left=0.;
00132 joint_offset.feet_inversion_joint_offset_right=20.;
00133
00134
00135 RoboState.speed_g_static=20;
00136 for (int i = 0; i < 12; i++)
00137 {
00138
00139 RoboState.speed_wanted[i]=RoboState.speed_g_static;
00140 }
00141 }
00142
00143 void ServoHumanoid::HomePosition(void)
00144 {
00145 const short int id_list[12]={11,21,12,22,13,32,15,25,16,26,31,23};
00146 short unsigned int resp = 65535;
00147
00148 for (uint i = 0 ; i < 12 ; i++)
00149 {
00150 resp = MoveJoint(id_list[i], 0.0);
00151 ROS_INFO("Servo with ID %d was set to Home position and gave the responce %d", id_list[i], resp);
00152 }
00153 for (uint i = 0 ; i < 12 ; i++)
00154 {
00155 resp=SetJointSpeed(id_list[i],RoboState.speed_wanted[i]);
00156 RoboState.joint_now[i]=ConvertServoValueByID(id_list[i], resp);
00157 }
00158
00159 }
00160
00161
00162 short unsigned int ServoHumanoid::MoveJoint(short int id, double joint_angle)
00163 {
00164 short unsigned int resp = 65535;
00165
00166 switch(id)
00167 {
00168 case 31:
00169 {
00170 resp = Torso_Rotation_Movement(joint_angle + joint_offset.torso_rotation_joint_offset);
00171 break;
00172 }
00173 case 23:
00174 {
00175 resp = Torso_Flexion_Extension_Movement(joint_angle + joint_offset.torso_flexion_joint_offset);
00176 break;
00177 }
00178
00179
00180
00181
00182
00183 case 21:
00184 {
00185 resp = Ankle_Inversion_Eversion_Movement(id,joint_angle + joint_offset.feet_inversion_joint_offset_left);
00186 break;
00187 }
00188 case 22:
00189 {
00190 resp = Ankle_Flexion_Movement(id,joint_angle + joint_offset.feet_flexion_joint_offset_left);
00191 break;
00192 }
00193 case 32:
00194 {
00195 resp = Knee_Movement(id,joint_angle + joint_offset.knee_flexion_joint_offset_left);
00196 break;
00197 }
00198 case 25:
00199 {
00200 resp = Hip_Abduction_Hiperabduction_Movement(id,joint_angle + joint_offset.hip_abduction_joint_offset_left);
00201 break;
00202 }
00203 case 26:
00204 {
00205 resp = Hip_Flexion_Movement(id,joint_angle + joint_offset.hip_flexion_joint_offset_left);
00206 break;
00207 }
00208 case 11:
00209 {
00210 resp = Ankle_Inversion_Eversion_Movement(id,joint_angle + joint_offset.feet_inversion_joint_offset_right);
00211 break;
00212 }
00213 case 12:
00214 {
00215 resp = Ankle_Flexion_Movement(id,joint_angle + joint_offset.feet_flexion_joint_offset_right);
00216 break;
00217 }
00218 case 13:
00219 {
00220 resp = Knee_Movement(id,joint_angle + joint_offset.knee_flexion_joint_offset_right);
00221 break;
00222 }
00223 case 15:
00224 {
00225 resp = Hip_Abduction_Hiperabduction_Movement(id,joint_angle + joint_offset.hip_abduction_joint_offset_right);
00226 break;
00227 }
00228 case 16:
00229 {
00230 resp = Hip_Flexion_Movement(id,joint_angle + joint_offset.hip_flexion_joint_offset_right);
00231 break;
00232 }
00233 case 1000:
00234 {
00235 HomePosition();
00236
00237 }
00238 default:
00239 {
00240 ROS_INFO("Servo ID %d not recognized", id);
00241 break;
00242 }
00243 }
00244
00245 return resp;
00246 }
00247
00248
00249 short unsigned int ServoHumanoid::SetJointSpeed(short int id, unsigned int speed)
00250 {
00251 short unsigned int resp;
00252
00253 switch(id)
00254 {
00255 case 31:
00256 {
00257 resp = hitec->SetSpeedPosition(id, speed);
00258 break;
00259 }
00260 case 23:
00261 {
00262 resp = hitec->SetSpeedPosition(id, speed);
00263 break;
00264 }
00265 case 33:
00266 {
00267 resp = hitec->SetSpeedPosition(id, speed);
00268 break;
00269 }
00270 case 21:
00271 {
00272 resp = hitec->SetSpeedPosition(id, speed*4./2.);
00273 break;
00274 }
00275 case 22:
00276 {
00277 resp = hitec->SetSpeedPosition(id, speed*4./2.);
00278 break;
00279 }
00280 case 32:
00281 {
00282 resp = hitec->SetSpeedPosition(id, speed*(30./22.));
00283 break;
00284 }
00285 case 25:
00286 {
00287 resp = hitec->SetSpeedPosition(id, speed*4./2.);
00288 break;
00289 }
00290 case 26:
00291 {
00292 resp = hitec->SetSpeedPosition(id, speed*(30./22.));
00293 break;
00294 }
00295 case 11:
00296 {
00297 resp = hitec->SetSpeedPosition(id, speed*4./2.);
00298 break;
00299 }
00300 case 12:
00301 {
00302 resp = hitec->SetSpeedPosition(id, speed*4./2.);
00303 break;
00304 }
00305 case 13:
00306 {
00307 resp = hitec->SetSpeedPosition(id, speed*(30./22.));
00308 break;
00309 }
00310 case 15:
00311 {
00312 resp = hitec->SetSpeedPosition(id, speed*4./2.);
00313 break;
00314 }
00315 case 16:
00316 {
00317 resp = hitec->SetSpeedPosition(id, speed*(30./22.));
00318 break;
00319 }
00320 case 1000:
00321 {
00322 const short int id_list[12]={11,21,12,22,13,32,15,25,16,26,31,23};
00323 for(int i=0;i<12;i++)
00324 {
00325 resp=SetJointSpeed(id_list[i],speed);
00326 }
00327 ROS_INFO("Setting all Servo's speed to %d", speed);
00328 }
00329 default:
00330 {
00331 ROS_INFO("Servo ID %d not recognized", id);
00332 resp = 65535;
00333 break;
00334 }
00335 }
00336 return resp;
00337 }
00338
00339
00340 double ServoHumanoid::ConvertServoValueByID(int id, short unsigned int servo_value)
00341 {
00342
00343 double joint_angle=0xFFFF;
00344 switch (id)
00345 {
00346 case 31:
00347 {
00348 joint_angle=Torso_Rotation_ServoValue_Conversion(servo_value) - joint_offset.torso_rotation_joint_offset;
00349 break;
00350 }
00351 case 23:
00352 {
00353 joint_angle=Torso_Flexion_Extension_ServoValue_Conversion(servo_value) - joint_offset.torso_flexion_joint_offset;
00354 break;
00355 }
00356
00357
00358
00359
00360
00361 case 21:
00362 {
00363 joint_angle=Ankle_Inversion_Eversion_ServoValue_Conversion(id,servo_value) - joint_offset.feet_inversion_joint_offset_left;
00364 break;
00365 }
00366 case 22:
00367 {
00368 joint_angle=Ankle_Flexion_ServoValue_Conversion(id,servo_value) - joint_offset.feet_flexion_joint_offset_left;
00369 break;
00370 }
00371 case 32:
00372 {
00373 joint_angle=Knee_Flexion_ServoValue_Conversion(id,servo_value) - joint_offset.knee_flexion_joint_offset_left;
00374 break;
00375 }
00376 case 25:
00377 {
00378 joint_angle=Hip_Abduction_Hiperabduction_ServoValue_Conversion(id,servo_value) - joint_offset.hip_abduction_joint_offset_left;
00379 break;
00380 }
00381 case 26:
00382 {
00383 joint_angle=Hip_Flexion_ServoValue_Conversion(id,servo_value) - joint_offset.hip_flexion_joint_offset_left;
00384 break;
00385 }
00386 case 11:
00387 {
00388 joint_angle=Ankle_Inversion_Eversion_ServoValue_Conversion(id,servo_value) - joint_offset.feet_inversion_joint_offset_right;
00389 break;
00390 }
00391 case 12:
00392 {
00393 joint_angle=Ankle_Flexion_ServoValue_Conversion(id,servo_value) - joint_offset.feet_flexion_joint_offset_right;
00394 break;
00395 }
00396 case 13:
00397 {
00398 joint_angle=Knee_Flexion_ServoValue_Conversion(id,servo_value) - joint_offset.knee_flexion_joint_offset_right;
00399 break;
00400 }
00401 case 15:
00402 {
00403 joint_angle=Hip_Abduction_Hiperabduction_ServoValue_Conversion(id,servo_value) - joint_offset.hip_abduction_joint_offset_right;
00404 break;
00405 }
00406 case 16:
00407 {
00408 joint_angle=Hip_Flexion_ServoValue_Conversion(id,servo_value) - joint_offset.hip_flexion_joint_offset_right;
00409 break;
00410 }
00411 default:
00412 {
00413 joint_angle=0xFFFF;
00414 break;
00415 }
00416 }
00417
00418 return joint_angle;
00419 }
00420
00421
00422 short unsigned int ServoHumanoid::Torso_Rotation_Movement(double joint_angle)
00423 {
00424 short unsigned int move, resp = 65535;
00425
00426
00427
00428
00429
00430 if(joint_angle<robot_joint_limits.torso_min_rotation || joint_angle>robot_joint_limits.torso_max_rotation)
00431 return 0;
00432
00433
00434 move = (robot_servo_conversion.torso_rotation_servo_offset+joint_angle*10.);
00435
00436 resp = hitec->SetPosition(31,move);
00437
00438 return resp;
00439
00440 }
00441
00442 short unsigned int ServoHumanoid::Torso_Flexion_Extension_Movement(double joint_angle)
00443 {
00444 short unsigned int move, resp = 65535;
00445
00446
00447
00448
00449
00450 if(joint_angle<robot_joint_limits.torso_min_flexion || joint_angle>robot_joint_limits.torso_max_flexion)
00451 return 0;
00452
00453
00454 move = (robot_servo_conversion.torso_flexion_servo_offset+joint_angle*10.);
00455
00456
00457 resp = hitec->SetPosition(23,move);
00458
00459 return resp;
00460
00461 }
00462
00463
00464 short unsigned int ServoHumanoid::Torso_Lateral_Flexion_Extension_Movement(double joint_angle)
00465 {
00466 short unsigned int move, resp = 65535;
00467
00468
00469
00470
00471
00472 if(joint_angle<robot_joint_limits.torso_min_lateral_flexion || joint_angle>robot_joint_limits.torso_max_lateral_flexion)
00473 return 0;
00474
00475
00476 move = (robot_servo_conversion.torso_lateral_flexion_servo_offset+joint_angle*10.);
00477
00478 resp = hitec->SetPosition(33,move);
00479
00480 return resp;
00481
00482 }
00483
00484
00485 short unsigned int ServoHumanoid::Ankle_Flexion_Movement(short int id, double joint_angle)
00486 {
00487 short unsigned int move, resp = 65535;
00488
00489
00490 if(joint_angle<robot_joint_limits.ankle_min_flexion || joint_angle>robot_joint_limits.ankle_max_flexion)
00491 return 0;
00492
00493 double sign;
00494 if(id== 22)
00495 {
00496
00497
00498
00499 sign=(double) LEFT;
00500 }
00501 else if(id== 12)
00502 {
00503
00504
00505
00506 sign=(double) RIGHT;
00507 }
00508 else
00509 return resp;
00510
00511
00512 double b=1500.;
00513
00514 if(joint_angle==0)
00515 move = 1500;
00516 else if(joint_angle<0)
00517 {
00518
00519 double m=(1500.-600.)/(-robot_joint_limits.ankle_min_flexion);
00520 move = round(sign*(m*joint_angle)+b);
00521 }
00522 else
00523 {
00524
00525 double m=(2400.-1500.)/(robot_joint_limits.ankle_max_flexion);
00526 move = round(sign*(m*joint_angle)+b);
00527 }
00528
00529 resp = hitec->SetPosition(id,move);
00530
00531 return resp;
00532 }
00533
00534
00535 short unsigned int ServoHumanoid::Ankle_Inversion_Eversion_Movement(short int id, double joint_angle)
00536 {
00537 short unsigned int move, resp = 65535;
00538
00539
00540
00541 if(joint_angle<robot_joint_limits.ankle_min_inversion || joint_angle>robot_joint_limits.ankle_max_inversion)
00542 return 0;
00543
00544 double sign;
00545 if(id==21)
00546 {
00547
00548
00549 sign=(double) LEFT;
00550 }
00551 else if(id==11)
00552 {
00553
00554
00555 sign=(double) RIGHT;
00556 }
00557 else
00558 return resp;
00559
00560 double b=1500.;
00561
00562
00563 if(joint_angle==0)
00564 move = 1500;
00565 else if(joint_angle<0)
00566 {
00567 double m=(1500.-600.)/(-robot_joint_limits.ankle_min_inversion);
00568 move = round(sign*(m*joint_angle)+b);
00569 }
00570 else
00571 {
00572 double m=(2400.-1500.)/(robot_joint_limits.ankle_max_inversion);
00573 move = round(sign*(m*joint_angle)+b);
00574 }
00575
00576 resp = hitec->SetPosition(id,move);
00577
00578 return resp;
00579 }
00580
00581
00582 short unsigned int ServoHumanoid::Knee_Movement(short int id, double joint_angle)
00583 {
00584 short unsigned int move, resp = 65535;
00585
00586
00587 if(joint_angle<robot_joint_limits.knee_min_flexion || joint_angle>robot_joint_limits.knee_max_flexion)
00588 return 0;
00589
00590
00591
00592
00593
00594 double sign;
00595 double b;
00596 if(id==32)
00597 {
00598
00599
00600
00601 b=robot_servo_conversion.knee_flexion_b_value_left;
00602 sign=(double) LEFT;
00603 }
00604 else if(id==13)
00605 {
00606
00607
00608
00609 b=robot_servo_conversion.knee_flexion_b_value_right;
00610 sign=(double) RIGHT;
00611 }
00612 else
00613 return resp;
00614
00615
00616 double m=sign*(2400.-600.)/(robot_joint_limits.knee_max_flexion-robot_joint_limits.knee_min_flexion);
00617 move = round((m*joint_angle)+b);
00618
00619 resp = hitec->SetPosition(id,move);
00620
00621 return resp;
00622 }
00623
00624
00625 short unsigned int ServoHumanoid::Hip_Abduction_Hiperabduction_Movement(short int id, double joint_angle)
00626 {
00627 short unsigned int move, resp = 65535;
00628
00629
00630
00631
00632
00633 if(joint_angle<robot_joint_limits.hip_min_abduction || joint_angle>robot_joint_limits.hip_max_abduction)
00634 return 0;
00635
00636 double sign;
00637 if(id==25)
00638 {
00639
00640
00641
00642 sign=(double) RIGHT;
00643 }
00644 else if(id==15)
00645 {
00646
00647
00648
00649 sign=(double) LEFT;
00650 }
00651 else
00652 return resp;
00653
00654 double b=1500.;
00655
00656 if(joint_angle==0)
00657 move = 1500;
00658 else if(joint_angle<0)
00659 {
00660 double m=900./(-robot_joint_limits.hip_min_abduction);
00661 move = round(sign*(m*joint_angle)+b);
00662 }
00663 else
00664 {
00665 double m=900./(robot_joint_limits.hip_max_abduction);
00666 move = round(sign*(m*joint_angle)+b);
00667 }
00668
00669 resp = hitec->SetPosition(id,move);
00670
00671 return resp;
00672 }
00673
00674
00675
00676 short unsigned int ServoHumanoid::Hip_Flexion_Movement(short int id, double joint_angle)
00677 {
00678 short unsigned int move, resp = 65535;
00679
00680
00681
00682
00683
00684 if(joint_angle<robot_joint_limits.hip_min_flexion || joint_angle>robot_joint_limits.hip_max_flexion)
00685 return 0;
00686
00687 double sign;
00688 double offset;
00689 if(id==26)
00690 {
00691
00692
00693
00694 offset=robot_servo_conversion.hip_flexion_b_value_left;
00695 sign=(double) LEFT;
00696 }
00697 else if(id==16)
00698 {
00699
00700
00701
00702 offset=robot_servo_conversion.hip_flexion_b_value_right;
00703 sign=(double) RIGHT;
00704 }
00705 else
00706 return resp;
00707
00708
00709 move = offset+sign*joint_angle*10.;
00710
00711
00712 resp = hitec->SetPosition(id,move);
00713
00714 return resp;
00715
00716
00717 }
00718
00719
00720 double ServoHumanoid::Torso_Rotation_ServoValue_Conversion(short unsigned int servo_value)
00721 {
00722 if(servo_value<595 || servo_value>2405)
00723 {
00724 return 0xFFFF;
00725 }
00726
00727
00728
00729
00730 return ((double)servo_value-robot_servo_conversion.torso_rotation_servo_offset)/10.;
00731 }
00732
00733 double ServoHumanoid::Torso_Flexion_Extension_ServoValue_Conversion(short unsigned int servo_value)
00734 {
00735 if(servo_value<595 || servo_value>2405)
00736 {
00737 return 0xFFFF;
00738 }
00739
00740
00741
00742
00743 return ((double)servo_value-robot_servo_conversion.torso_flexion_servo_offset)/10.;
00744 }
00745
00746 double ServoHumanoid::Torso_Lateral_Flexion_Extension_ServoValue_Conversion(short unsigned int servo_value)
00747 {
00748 if(servo_value<595 || servo_value>2405)
00749 {
00750 return 0xFFFF;
00751 }
00752
00753
00754
00755
00756 return ((double)servo_value-robot_servo_conversion.torso_lateral_flexion_servo_offset)/10.;
00757 }
00758
00759
00760
00761 double ServoHumanoid::Ankle_Inversion_Eversion_ServoValue_Conversion(short int id, short unsigned int servo_value)
00762 {
00763
00764 if(servo_value<595 || servo_value>2405)
00765 {
00766 return 0xFFFF;
00767 }
00768
00769
00770 if(servo_value==1500)
00771 return 0.;
00772
00773 if(id==11)
00774 {
00775
00776
00777 if(servo_value<1500)
00778 {
00779 return servo_value*(robot_joint_limits.ankle_max_inversion/-900.)-(robot_joint_limits.ankle_max_inversion/-900.)*1500.;
00780 }
00781 else
00782 {
00783 return servo_value*(robot_joint_limits.ankle_min_inversion/900.)-(robot_joint_limits.ankle_min_inversion/900.)*1500.;
00784 }
00785 }
00786 else if(id==21)
00787 {
00788 if(servo_value<1500)
00789 {
00790 return servo_value*(robot_joint_limits.ankle_min_inversion/-900.)-(robot_joint_limits.ankle_min_inversion/-900.)*1500.;
00791 }
00792 else
00793 {
00794 return servo_value*(robot_joint_limits.ankle_max_inversion/900.)-(robot_joint_limits.ankle_max_inversion/900.)*1500.;
00795 }
00796 }
00797 else
00798 {
00799 return 0xFFFF;
00800 }
00801 }
00802
00803 double ServoHumanoid::Ankle_Flexion_ServoValue_Conversion(short int id, short unsigned int servo_value)
00804 {
00805
00806 if(servo_value<595 || servo_value>2405)
00807 {
00808 return 0xFFFF;
00809 }
00810
00811
00812 if(servo_value==1500)
00813 return 0.;
00814
00815 if(id==12)
00816 {
00817
00818
00819 if(servo_value<1500)
00820 {
00821 return (double)servo_value*(robot_joint_limits.ankle_max_flexion/-900.)-(robot_joint_limits.ankle_max_flexion/-900.)*1500.;
00822 }
00823 else
00824 {
00825 return (double)servo_value*(robot_joint_limits.ankle_min_flexion/900.)-(robot_joint_limits.ankle_min_flexion/900.)*1500.;
00826 }
00827 }
00828 else if(id==22)
00829 {
00830 if(servo_value<1500)
00831 {
00832 return (double)servo_value*(robot_joint_limits.ankle_min_flexion/-900.)-(robot_joint_limits.ankle_min_flexion/-900.)*1500.;
00833 }
00834 else
00835 {
00836 return (double)servo_value*(robot_joint_limits.ankle_max_flexion/900.)-(robot_joint_limits.ankle_max_flexion/900.)*1500.;
00837 }
00838 }
00839 else
00840 {
00841 return 0xFFFF;
00842 }
00843 }
00844
00845 double ServoHumanoid::Knee_Flexion_ServoValue_Conversion(short int id, short unsigned int servo_value)
00846 {
00847
00848 if(servo_value<595 || servo_value>2405)
00849 {
00850 return 0xFFFF;
00851 }
00852
00853 double sign;
00854 if(id==32)
00855 {
00856
00857
00858
00859 sign=(double) LEFT;
00860 return ((double)servo_value-robot_servo_conversion.knee_flexion_b_value_left)/(sign*(2400.-600.)/(robot_joint_limits.knee_max_flexion-robot_joint_limits.knee_min_flexion));
00861 }
00862 else if(id==13)
00863 {
00864
00865
00866
00867 sign=(double) RIGHT;
00868 return ((double)servo_value-robot_servo_conversion.knee_flexion_b_value_right)/(sign*(2400.-600.)/(robot_joint_limits.knee_max_flexion-robot_joint_limits.knee_min_flexion));
00869 }
00870 else
00871 return 0xFFFF;
00872 }
00873
00874 double ServoHumanoid::Hip_Abduction_Hiperabduction_ServoValue_Conversion(short int id, short unsigned int servo_value)
00875 {
00876
00877 if(servo_value<595 || servo_value>2405)
00878 {
00879 return 0xFFFF;
00880 }
00881
00882 if(servo_value==1500)
00883 return 0.;
00884
00885 double sign;
00886 if(id==25)
00887 {
00888
00889
00890
00891 sign=(double) RIGHT;
00892 if(servo_value<1500)
00893 {
00894 double m=900./(-robot_joint_limits.hip_min_abduction);
00895 return ((double)servo_value-1500.)/(sign*m);
00896 }
00897 else
00898 {
00899 double m=900./(robot_joint_limits.hip_max_abduction);
00900 return ((double)servo_value-1500.)/(sign*m);
00901 }
00902 }
00903 else if(id==15)
00904 {
00905
00906
00907
00908 sign=(double) LEFT;
00909 if(servo_value<1500)
00910 {
00911 double m=900./(-robot_joint_limits.hip_min_abduction);
00912 return ((double)servo_value-1500.)/(sign*m);
00913 }
00914 else
00915 {
00916 double m=900./(robot_joint_limits.hip_max_abduction);
00917 return ((double)servo_value-1500.)/(sign*m);
00918 }
00919 }
00920 else
00921 return 0xFFFF;
00922 }
00923
00924 double ServoHumanoid::Hip_Flexion_ServoValue_Conversion(short int id, short unsigned int servo_value)
00925 {
00926
00927 if(servo_value<595 || servo_value>2405)
00928 {
00929 return 0xFFFF;
00930 }
00931
00932 double sign;
00933 double offset;
00934 if(id==26)
00935 {
00936
00937
00938
00939 offset=robot_servo_conversion.hip_flexion_b_value_left;
00940 sign=(double) LEFT;
00941 if(servo_value==offset)
00942 return 0.;
00943 }
00944 else if(id==16)
00945 {
00946
00947
00948
00949 offset=robot_servo_conversion.hip_flexion_b_value_right;
00950 sign=(double) RIGHT;
00951 if(servo_value==offset)
00952 return 0.;
00953 }
00954 else
00955 return 0xFFFF;
00956
00957
00958 return sign*((double)servo_value-offset)/10.;
00959 }
00960
00961
00962
00963
00965
00966
00967
00968
00971
00972
00973
00974
00975
00977
00978
00979
00980
00981
00982
00983
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
01000
01001
01002
01003
01004
01005
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01022
01023
01024
01025
01032
01033
01034
01035
01036
01043
01044
01045
01046
01047
01054
01055
01056
01057
01058
01059
01063
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076