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
00028
00029
00030
00031
00032
00037 #include <math.h>
00038 #include <iostream>
00039
00040 #include "grasp_preshape.h"
00041
00045 preshape::preshape(){
00046 pType = PR_None;
00047 updateAngles();
00048 }
00049
00053 preshape::preshape(preshapeType p){
00054 pType = p;
00055 updateAngles();
00056 }
00057
00061 preshape::preshape(const preshape& p){
00062 pType = p.get_preshapeType();
00063 p.get_preshape(a, f1, f2, f3);
00064 updateAngles();
00065 }
00066
00070 void
00071 preshape::set_preshapeType(preshapeType p){
00072 pType = p;
00073 updateAngles();
00074 }
00075
00079 void
00080 preshape::set_preshape(double aa, double ff1, double ff2, double ff3){
00081
00082 pType = PR_None;
00083 a=aa; f1 = ff1; f2 = ff2; f3=ff3;
00084 }
00085
00089 preshapeType
00090 preshape::get_preshapeType() const{
00091 return pType;
00092 }
00093
00097 void
00098 preshape::get_preshape(double& aa, double& ff1, double& ff2, double& ff3) const{
00099 aa = a;
00100 ff1 = f1;
00101 ff2 = f2;
00102 ff3 = f3;
00103 return;
00104 }
00105
00111 double
00112 preshape::distanceTo(preshape p) const{
00113 double aa,ff1,ff2,ff3;
00114 p.get_preshape(aa,ff1,ff2,ff3);
00115 if((aa*aa+ff1*ff1+ff2*ff2+ff3*ff3) == 0.0 &&
00116 (a*a +f1*f1 +f2*f2 +f3*f3) == 0.0)
00117 return 0.0;
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 return fabs((a-aa)/(a>aa?a:aa));
00130 }
00131
00135 void
00136 preshape::updateAngles(){
00137 if (pType != PR_None){
00138 switch (pType) {
00139 case PR_circle:
00140 a = PR_circle_Angle;
00141 f1 = PR_circle_F1;
00142 f2 = PR_circle_F2;
00143 f3 = PR_circle_F3;
00144 break;
00145 case PR_two_opp_one:
00146 a = PR_two_opp_one_Angle;
00147 f1 = PR_two_opp_one_F1;
00148 f2 = PR_two_opp_one_F2;
00149 f3 = PR_two_opp_one_F3;
00150 break;
00151 case PR_three_opp_palm:
00152 a = PR_three_opp_palm_Angle;
00153 f1 = PR_three_opp_palm_F1;
00154 f2 = PR_three_opp_palm_F2;
00155 f3 = PR_three_opp_palm_F3;
00156 break;
00157 case PR_t_shape:
00158 a = PR_t_shape_Angle;
00159 f1 = PR_t_shape_F1;
00160 f2 = PR_t_shape_F2;
00161 f3 = PR_t_shape_F3;
00162 break;
00163 default:
00164 std::cout << "Preshape not defined or implemented." << std::endl;
00165 break;
00166 }
00167 }
00168 }
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183