libmove3d
3.13.0
|
00001 #ifndef GRASP_PLANNING_H 00002 #define GRASP_PLANNING_H 00003 00004 00014 00015 // cd BioMove3Dgit/BioMove3D/build_test/ 00016 // ./Debug/bin/i386-linux/move3d-studio -f ~/BioMove3DDemos/Bauzil/gsSAHand.p3d 00017 00026 #include <time.h> 00027 #include <sys/times.h> 00028 #include <stdio.h> 00029 00030 #include <vector> 00031 #include <list> 00032 #include <string> 00033 #include <sstream> 00034 #include "P3d-pkg.h" 00035 #include "Graphic-pkg.h" 00036 #include "p3d_type.h" 00037 #include "p3d.h" 00038 00039 00040 //debug mode 00041 #ifndef GP_DEBUG 00042 #define GP_DEBUG 00043 #endif 00044 00045 #define GP_OK 0 00046 #define GP_ERROR 1 00047 00048 00049 #define RADTODEG (180.0f/M_PI) 00050 #define DEGTORAD (M_PI/180.0f) 00051 00053 #define GP_EPSILON 0.00001 00054 00056 #define GP_FRICTION_COEFFICIENT 0.3 00057 00058 00060 #define GP_VERSION "0.0.2" 00061 00063 template<class T> std::string convertToString(const T& t) 00064 { 00065 std::ostringstream stream; 00066 stream << t; 00067 return stream.str(); 00068 } 00069 00071 #define GP_GRIPPERJOINT "fingerJointGripper" 00072 00074 #define GP_THUMBJOINT1 "fingerJointThumbRotation" 00075 #define GP_THUMBJOINT2 "fingerJointThumbBase" 00076 #define GP_THUMBJOINT3 "fingerJointThumbProx" 00077 #define GP_THUMBJOINT4 "fingerJointThumbMid" 00078 #define GP_THUMBJOINT5 "fingerJointThumbDist" 00079 #define GP_FOREFINGERJOINT1 "fingerJointForeBase" 00080 #define GP_FOREFINGERJOINT2 "fingerJointForeProx" 00081 #define GP_FOREFINGERJOINT3 "fingerJointForeMid" 00082 #define GP_FOREFINGERJOINT4 "fingerJointForeDist" 00083 #define GP_MIDDLEFINGERJOINT1 "fingerJointMiddleBase" 00084 #define GP_MIDDLEFINGERJOINT2 "fingerJointMiddleProx" 00085 #define GP_MIDDLEFINGERJOINT3 "fingerJointMiddleMid" 00086 #define GP_MIDDLEFINGERJOINT4 "fingerJointMiddleDist" 00087 #define GP_RINGFINGERJOINT1 "fingerJointRingBase" 00088 #define GP_RINGFINGERJOINT2 "fingerJointRingProx" 00089 #define GP_RINGFINGERJOINT3 "fingerJointRingMid" 00090 #define GP_RINGFINGERJOINT4 "fingerJointRingDist" 00091 00092 00094 // #define GP_OBJECT_NAME "DuploObject" 00095 // #define GP_OBJECT_NAME_DEFAULT "DuploObject" 00096 // #define GP_OBJECT_NAME_DEFAULT "Horse" 00097 #define GP_OBJECT_NAME_DEFAULT "PaperDog" 00098 // #define GP_OBJECT_NAME_DEFAULT "Mug" 00099 00102 #define GP_ROBOT_NAME "JIDOKUKA_ROBOT" 00103 00106 #define GP_GRIPPER_ROBOT_NAME "JIDO_GRIPPER" 00107 #define GP_PR2_GRIPPER_ROBOT_NAME "PR2_GRIPPER" 00108 #define GP_SAHAND_RIGHT_ROBOT_NAME "SAHandRight" 00109 #define GP_SAHAND_LEFT_ROBOT_NAME "SAHandLeft" 00110 00112 #define GP_PA1 "PA1" 00113 #define GP_PA2 "PA2" 00114 #define GP_PA3 "PA3" 00115 #define GP_PA4 "PA4" 00116 #define GP_PA5 "PA5" 00117 #define GP_PA6 "PA6" 00118 #define GP_PA7 "PA7" 00119 00120 00123 #define GP_PLATFORM_BODY_PREFIX "platform" 00124 #define GP_ARM_BODY_PREFIX "arm" 00125 #define GP_HAND_BODY_PREFIX "hand" 00126 #define GP_FINGER_BODY_PREFIX "finger" 00127 00128 00130 #define GP_FINGERTIP_BODY_NAME "fingertip" 00131 00132 00133 00136 #define GP_INNER_RADIUS 0.5 00137 #define GP_OUTER_RADIUS 1.1 00138 00139 00140 #define DBG printf("%s: %d \n", __FILE__, __LINE__) 00141 00144 typedef enum gpHand_type 00145 { 00146 GP_GRIPPER, 00147 GP_SAHAND_RIGHT, 00148 GP_SAHAND_LEFT, 00149 GP_PR2_GRIPPER, 00150 GP_HAND_NONE 00151 } gpHand_type; 00152 00155 typedef enum gpArm_type 00156 { 00157 GP_PA10, 00158 GP_LWR, 00159 GP_ARM_NONE, 00160 } gpArm_type; 00161 00162 00166 typedef enum gpGrasp_collision_state 00167 { 00168 NOT_TESTED, 00169 COLLIDING, 00170 COLLISION_FREE 00171 } gpGrasp_collision_state; 00172 00173 00177 class gpHand_properties 00178 { 00179 public: 00180 gpHand_type type; 00181 00182 unsigned int nb_fingers; 00183 00185 unsigned int nb_dofs; 00186 00188 double fingertip_radius; 00189 00190 00194 p3d_matrix4 Tgrasp_frame_hand; 00195 00196 00200 p3d_matrix4 Thand_wrist; 00201 00203 double edgeAngleThreshold; 00204 double edgeDistanceThreshold; 00206 00207 unsigned int nb_positions, nb_directions, nb_rotations, max_nb_grasp_frames; 00208 00210 std::vector<double> qmin, qmax; 00212 std::vector<double> qrest; 00214 std::vector<double> qopen; 00215 00217 double fingertip_distance; 00218 double min_opening; 00219 double max_opening; 00220 double min_opening_jnt_value; 00221 double max_opening_jnt_value; 00222 00223 00225 double joint_fingertip_distance; 00227 00228 00229 double length_thumbBase, length_proxPha, length_midPha, length_distPha; 00230 00232 p3d_matrix4 Twrist_finger[4]; 00233 00235 // double q0min[4], q0max[4]; /*!< thumb's first joint */ 00236 // double q1min[4], q1max[4]; /*!< abduction */ 00237 // double q2min[4], q2max[4]; /*!< subduction */ 00238 // double q3min[4], q3max[4]; /*!< proximal phalanx/middle phalanx joint */ 00239 00241 std::vector<class gpSphere> workspace; 00243 gpHand_properties(); 00244 int initialize(gpHand_type hand_type); 00245 struct rob* initialize(); 00246 int setThand_wrist(p3d_matrix4 T); 00247 int setArmType(gpArm_type arm_type); 00248 int draw(p3d_matrix4 pose); 00249 }; 00250 00253 class gpVector3D 00254 { 00255 public: 00256 double x, y, z; 00257 double cost; 00259 gpVector3D() 00260 { 00261 x= y= z= 0.0; 00262 } 00263 00264 gpVector3D(double x0, double y0, double z0) 00265 { 00266 x= x0; 00267 y= y0; 00268 z= z0; 00269 } 00270 00271 double operator [] (unsigned int i) const 00272 { 00273 switch(i) 00274 { 00275 case 0: 00276 return x; 00277 break; 00278 case 1: 00279 return y; 00280 break; 00281 case 2: 00282 return z; 00283 break; 00284 default: 00285 printf("%s: %d: gpVector3D::operator []: index exceeds vector dimensions.\n",__FILE__,__LINE__); 00286 return 0; 00287 break; 00288 } 00289 } 00290 00291 double& operator [] (unsigned int i) 00292 { 00293 switch(i) 00294 { 00295 case 0: 00296 return x; 00297 break; 00298 case 1: 00299 return y; 00300 break; 00301 case 2: 00302 return z; 00303 break; 00304 default: 00305 printf("%s: %d: gpVector3D::operator []: index exceeds vector dimensions.\n",__FILE__,__LINE__); 00306 return x; 00307 break; 00308 } 00309 } 00310 00311 bool operator < (const gpVector3D &vector3D) 00312 { return (cost < vector3D.cost) ? true : false; } 00313 00314 bool operator > (const gpVector3D &vector3D) 00315 { return (cost > vector3D.cost) ? true : false; } 00316 00317 int set(double x0, double y0, double z0) 00318 { 00319 if(this==NULL) 00320 { 00321 printf("%s: %d: gpVector3D::setCenter(): the calling instance is NULL.\n",__FILE__,__LINE__); 00322 return GP_ERROR; 00323 } 00324 x= x0; 00325 y= y0; 00326 z= z0; 00327 00328 return GP_OK; 00329 } 00330 00331 void draw(double red, double green, double blue) 00332 { 00333 glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_POINT_BIT); 00334 glPointSize(4); 00335 glDisable(GL_LIGHTING); 00336 glColor3f(red, green, blue); 00337 glBegin(GL_POINTS); 00338 glVertex3f(x, y, z); 00339 glEnd(); 00340 glPopAttrib(); 00341 } 00342 00343 void print() 00344 { 00345 printf("v= [ %f %f %f ]\n", x, y, z); 00346 } 00347 }; 00348 00349 00352 class gpSphere 00353 { 00354 public: 00355 p3d_vector3 center; 00356 double radius; 00357 00358 gpSphere() 00359 { 00360 center[0]= center[1]= center[2]= 0.0; 00361 radius= 0.0; 00362 } 00363 00364 gpSphere(const gpSphere &sphere) 00365 { 00366 center[0]= sphere.center[0]; 00367 center[1]= sphere.center[1]; 00368 center[2]= sphere.center[2]; 00369 radius = sphere.radius; 00370 } 00371 00372 gpSphere & operator = (const gpSphere &sphere) 00373 { 00374 if(this==&sphere) 00375 { return *this; } 00376 center[0]= sphere.center[0]; 00377 center[1]= sphere.center[1]; 00378 center[2]= sphere.center[2]; 00379 radius = sphere.radius; 00380 return *this; 00381 } 00382 00383 int setCenter(double x, double y, double z) 00384 { 00385 if(this==NULL) 00386 { 00387 printf("%s: %d: gpSphere::setCenter(): the calling instance is NULL.\n",__FILE__,__LINE__); 00388 return GP_ERROR; 00389 } 00390 center[0]= x; 00391 center[1]= y; 00392 center[2]= z; 00393 return GP_OK; 00394 } 00395 }; 00396 00397 00401 class gpHTMatrix 00402 { 00403 public: 00404 float m11, m12, m13, m14; 00405 float m21, m22, m23, m24; 00406 float m31, m32, m33, m34; 00407 00408 gpHTMatrix() 00409 { 00410 m11= m22= m33= 1.0; 00411 m12= m13= m14= 0.0; 00412 m21= m23= m24= 0.0; 00413 m31= m32= m34= 0.0; 00414 } 00415 00416 void setRotation(p3d_matrix3 R) 00417 { 00418 m11= R[0][0]; m12= R[0][1]; m13= R[0][2]; 00419 m21= R[1][0]; m22= R[1][1]; m23= R[1][2]; 00420 m31= R[2][0]; m32= R[2][1]; m33= R[2][2]; 00421 } 00422 00423 void set(p3d_matrix4 M) 00424 { 00425 m11= M[0][0]; m12= M[0][1]; m13= M[0][2]; m14= M[0][3]; 00426 m21= M[1][0]; m22= M[1][1]; m23= M[1][2]; m24= M[1][3]; 00427 m31= M[2][0]; m32= M[2][1]; m33= M[2][2]; m34= M[2][3]; 00428 } 00429 00430 void copyIn_p3d_matrix4(p3d_matrix4 M) 00431 { 00432 M[0][0]= m11; M[0][1]= m12; M[0][2]= m13; M[0][3]= m14; 00433 M[1][0]= m21; M[1][1]= m22; M[1][2]= m23; M[1][3]= m24; 00434 M[2][0]= m31; M[2][1]= m32; M[2][2]= m33; M[2][3]= m34; 00435 M[3][0]= 0.0; M[3][1]= 0.0; M[3][2]= 0.0; M[3][3]= 1.0; 00436 } 00437 00438 void draw() 00439 { 00440 p3d_matrix4 M; 00441 copyIn_p3d_matrix4(M); 00442 g3d_draw_frame(M, 0.05); 00443 } 00444 00445 void print() 00446 { 00447 printf("M= \n"); 00448 printf("[ %f %f %f %f ]\n", m11, m12, m13, m14); 00449 printf("[ %f %f %f %f ]\n", m21, m22, m23, m24); 00450 printf("[ %f %f %f %f ]\n", m31, m32, m33, m34); 00451 printf("[ 0 0 0 1 ]\n"); 00452 } 00453 }; 00454 00456 class gpIndex 00457 { 00458 public: 00459 unsigned int index; 00460 double cost; 00461 00462 gpIndex() 00463 { 00464 index= 0; 00465 cost= 0; 00466 } 00467 bool operator < (const gpIndex &gpIndex) 00468 { return (cost < gpIndex.cost) ? true : false; } 00469 00470 bool operator > (const gpIndex &gpIndex) 00471 { return (cost > gpIndex.cost) ? true : false; } 00472 }; 00473 00474 00475 #endif 00476