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
00038
00039 #include <stdio.h>
00040 #include <iostream>
00041
00042
00043
00044 #include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
00045 #include <Inventor/actions/SoGetBoundingBoxAction.h>
00046 #include <Inventor/actions/SoSearchAction.h>
00047 #include <Inventor/nodes/SoCylinder.h>
00048 #include <Inventor/nodes/SoCone.h>
00049 #include <Inventor/nodes/SoCube.h>
00050 #include <Inventor/nodes/SoSphere.h>
00051 #include <Inventor/SoLists.h>
00052 #include "SoArrow.h"
00053 #include "SoTorquePointer.h"
00054 #include "SoComplexShape.h"
00055 #include <Inventor/fields/SoSFFloat.h>
00056 #include <Inventor/actions/SoGetMatrixAction.h>
00057 #include <Inventor/SbLinear.h>
00058 #include <Inventor/nodes/SoRotation.h>
00059 #include <Inventor/nodes/SoCamera.h>
00060 #include <Inventor/nodes/SoTransformSeparator.h>
00061 #include <Inventor/nodes/SoDirectionalLight.h>
00062
00063 #ifdef Q_WS_X11
00064 #include <unistd.h>
00065 #endif
00066
00067
00068 #include "contact.h"
00069 #include "graspitGUI.h"
00070 #include "ivmgr.h"
00071 #include "world.h"
00072 #include "robot.h"
00073 #include "body.h"
00074 #include "matvec3D.h"
00075 #include "grasp.h"
00076
00077
00078 #include <list>
00079
00080
00081 #include "grasp_coordinates.h"
00082 #include "grasp_directions.h"
00083 #include "grasp_preshape.h"
00084 #include "grasp_visualization.h"
00085 #include "grasp_grasps.h"
00086 #include "grasp_planner.h"
00087
00088 #
00089
00090 #ifdef GRASPITDBG
00091 extern FILE *debugfile;
00092 #endif
00093
00094
00095
00096
00097
00101 grasp_planner::grasp_planner()
00102 {
00103
00104 ivmgr = graspItGUI->getIVmgr();
00105
00106 myViewer = ivmgr->getViewer();
00107 my_body = NULL;
00108
00109 nr_of_360_deg_steps = NR_OF_360_DEG_STEPS;
00110 nr_of_parallel_planes_width = NR_OF_PARALLEL_PLANES;
00111 nr_of_parallel_planes_height = NR_OF_PARALLEL_PLANES;
00112 nr_of_parallel_planes_depth = NR_OF_PARALLEL_PLANES;
00113 nr_of_180_deg_grasps = NR_OF_180_DEG_GRASPS;
00114 nr_of_grasp_rotations = NR_OF_GRASP_ROTATIONS;
00115
00116 parameterMode = DEFAULT_PARAMETER_MODE;
00117 }
00118
00122 grasp_planner::~grasp_planner()
00123 {
00124 #ifdef GRASPITDBG
00125 std::cout << "PL_OUT: grasp_planner destroyed." << std::endl;
00126 #endif
00127 }
00128
00129
00138 std::list<plannedGrasp*>
00139 grasp_planner::planIt(GraspableBody* gb,SoGroup *IVPrimitives)
00140 {
00141 #ifdef PLAN_GRASP_ON_ALL_BODIES
00142 int numGB = ivmgr->getWorld()->getNumGB();
00143 #endif
00144 std::list <GraspDirection*> gd_list;
00145 std::list <plannedGrasp*> graspList;
00146 std::list <plannedGrasp*> finalList;
00147 std::list <plannedGrasp*>::iterator gl_it;
00148
00149 my_body = gb;
00150 IVGeomPrimitives = IVPrimitives;
00151
00152 #ifdef PLAN_GRASP_ON_ALL_BODIES
00153
00154 for (int num=0; num<numGB; num++){
00155 my_body = ivmgr->getGB(num);
00156 #ifdef GRASPITDBG
00157 std::cout << "PL_OUT: get Object Nr " << num << std::endl;
00158 #endif
00159 #endif
00160
00161
00162 SoPathList pl = searchPrimitives(my_body);
00163
00164 int length = pl.getLength();
00165 #ifdef GRASPITDBG
00166 std::cout << "PL_OUT: " << length << " primitives found." << std::endl;
00167 #endif
00168
00169 if (length){
00170
00171 #ifdef GRASPITDBG
00172 std::cout << "PL_OUT: Grasp planning started." << std::endl;
00173 #endif
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 for (int item=0; item<length; item++){
00189 #ifdef GRASPITDBG
00190 std::cout << "PL_OUT: Primitive " << item << std::endl;
00191 #endif
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201 if (parameterMode){
00202
00203 #ifdef GRASPITDBG
00204 std::cout <<
00205 "PL_OUT: Setting the planning parameters for this primitive." <<
00206 std::endl;
00207 #endif
00208 if (!set_planningParametersFromPrimitive(pl[item])) {
00209
00210 #ifdef GRASPITDBG
00211 std::cout << "PL_OUT: Didn't work!" << std::endl;
00212 #endif
00213 }
00214 }
00215
00216
00217
00218
00219
00220
00221 #ifdef GRASPITDBG
00222 std::cout <<
00223 "PL_OUT: getPlannedDirections on this primitive." << std::endl;
00224 #endif
00225 graspList = getPlannedGraspDirections(pl[item]);
00226
00227
00228
00229
00230
00231
00232
00233
00234 #ifdef GRASPITDBG
00235 std::cout <<
00236 "PL_OUT: compute preshapes for this primitive." << std::endl;
00237 #endif
00238 computeGraspPreshapes(graspList, pl[item]);
00239
00240
00241
00242
00243
00244
00245 #ifdef GRASPITDBG
00246 std::cout << "PL_OUT: change coordinate system to global." <<
00247 std::endl;
00248 #endif
00249 localToGlobalCoordinates(graspList, pl[item],gb->getTran());
00250
00251 #ifdef GRASPITDBG
00252 std::cout << "PL_OUT: Copy all grasps to final list." << std::endl;
00253 #endif
00254
00255 for (gl_it=graspList.begin(); gl_it!=graspList.end(); gl_it++){
00256 (*gl_it)->set_graspableBody(my_body);
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266 #if 0
00267 if (!existsInList(**gl_it, finalList))
00268 #endif
00269
00270 finalList.push_back(new plannedGrasp(**gl_it));
00271 }
00272 graspList.clear();
00273 }
00274
00275 #ifdef GRASPITDBG
00276 std::cout<<"PL_OUT: Number of grasps " << finalList.size() << std::endl;
00277 #endif
00278 }
00279
00280 #ifdef GRASPITDBG
00281 else std::cout<<"PL_OUT: No graspable object found in IVtree" << std::endl;
00282 #endif
00283
00284 #ifdef PLAN_GRASP_ON_ALL_BODIES
00285 }
00286 #endif
00287
00288 return finalList;
00289 }
00290
00300 bool
00301 grasp_planner::set_planningParametersFromPrimitive(SoPath* sop)
00302 {
00303 if (parameterMode <= 0)
00304 return false;
00305
00306 if (sop->getTail()->isOfType(SoCylinder::getClassTypeId())){
00307
00308
00309
00310 double radius = ((SoCylinder*)sop->getTail())->radius.getValue();
00311 double height = ((SoCylinder*)sop->getTail())->height.getValue();
00312 switch (parameterMode){
00313 case 1:
00314 nr_of_parallel_planes_height = 1;
00315 nr_of_360_deg_steps = (int)(radius/100.0) * 4 + 4;
00316 nr_of_180_deg_grasps = 1;
00317 nr_of_grasp_rotations = 2;
00318 break;
00319 case 2:
00320 nr_of_parallel_planes_height = 2 * (int)(height/100.0) + 1;
00321 nr_of_360_deg_steps = (int)(radius/100.0) * 8 + 8;
00322 nr_of_180_deg_grasps = 1;
00323 nr_of_grasp_rotations = 4;
00324 break;
00325 case 3:
00326 nr_of_parallel_planes_height = 2 * (int)(height/80.0) + 3;
00327 nr_of_360_deg_steps = (int)(radius/50.0) * 16 + 16;
00328 nr_of_180_deg_grasps = 2;
00329 nr_of_grasp_rotations = 4;
00330 break;
00331 default:
00332 nr_of_parallel_planes_height = 2 * (int)(height/70.0) + 2 * parameterMode + 1;
00333 nr_of_360_deg_steps = (int)(radius/50.0) * 24 + 4 * parameterMode;
00334 nr_of_180_deg_grasps = 2;
00335 nr_of_grasp_rotations = parameterMode + 4;
00336 break;
00337 }
00338 #ifdef GRASPITDBG
00339 std::cout << "PL_OUT: no of parallel planes in height " << nr_of_parallel_planes_height << std::endl;
00340 std::cout << "PL_OUT: no of 360 deg samples " << nr_of_360_deg_steps << std::endl;
00341 std::cout << "PL_OUT: no of 180 deg grasps " << nr_of_180_deg_grasps << std::endl;
00342 std::cout << "PL_OUT: no of grasp rotations " << nr_of_grasp_rotations << std::endl;
00343 #endif
00344 }
00345 else if (sop->getTail()->isOfType(SoCube::getClassTypeId())){
00346
00347
00348
00349 double width = ((SoCube*)sop->getTail())->width.getValue();
00350 double height = ((SoCube*)sop->getTail())->height.getValue();
00351 double depth = ((SoCube*)sop->getTail())->depth.getValue();
00352 switch (parameterMode){
00353 case 1:
00354 nr_of_parallel_planes_width = 1;
00355 nr_of_parallel_planes_height = 1;
00356 nr_of_parallel_planes_depth = 1;
00357 nr_of_180_deg_grasps = 1;
00358 break;
00359 case 2:
00360 nr_of_parallel_planes_width = 2 * (int)(width/100.0) + 1;
00361 nr_of_parallel_planes_height = 2 * (int)(height/100.0) + 1;
00362 nr_of_parallel_planes_depth = 2 * (int)(depth/100.0) + 1;
00363 nr_of_180_deg_grasps = 1;
00364 break;
00365 case 3:
00366 nr_of_parallel_planes_width = 2 * (int)(width/50.0) + 1;
00367 nr_of_parallel_planes_height = 2 * (int)(height/50.0) + 1;
00368 nr_of_parallel_planes_depth = 2 * (int)(depth/50.0) + 1;
00369 nr_of_180_deg_grasps = 2;
00370 break;
00371 default:
00372 nr_of_parallel_planes_width = 2 * (int)(width/50.0) + 2 * parameterMode + 1;
00373 nr_of_parallel_planes_height = 2 * (int)(height/50.0) + 2 * parameterMode + 1;
00374 nr_of_parallel_planes_depth = 2 * (int)(depth/50.0) + 2 * parameterMode + 1;
00375 nr_of_180_deg_grasps = 2;
00376 break;
00377 }
00378 #ifdef GRASPITDBG
00379 std::cout << "PL_OUT: no of parallel planes in height " << nr_of_parallel_planes_height << std::endl;
00380 std::cout << "PL_OUT: no of parallel planes in width " << nr_of_parallel_planes_width << std::endl;
00381 std::cout << "PL_OUT: no of parallel planes in depth " << nr_of_parallel_planes_depth << std::endl;
00382 std::cout << "PL_OUT: no of 180 deg grasps " << nr_of_180_deg_grasps << std::endl;
00383 #endif
00384 }
00385 else if (sop->getTail()->isOfType(SoCone::getClassTypeId())){
00386
00387
00388
00389 double bottomRadius = ((SoCone*)sop->getTail())->bottomRadius.getValue();
00390 double height = ((SoCone*)sop->getTail())->height.getValue();
00391 double side_height = sqrt(bottomRadius * bottomRadius + height * height);
00392 switch (parameterMode){
00393 case 1:
00394 nr_of_parallel_planes_height = 1;
00395 nr_of_360_deg_steps = (int)(bottomRadius/100.0) * 4 + 4;
00396 nr_of_180_deg_grasps = 1;
00397 nr_of_grasp_rotations = 2;
00398 break;
00399 case 2:
00400 nr_of_parallel_planes_height = 2 * (int)(side_height/100.0) + 1;
00401 nr_of_360_deg_steps = (int)(bottomRadius/100.0) * 8 + 8;
00402 nr_of_180_deg_grasps = 1;
00403 nr_of_grasp_rotations = 4;
00404 break;
00405 case 3:
00406 nr_of_parallel_planes_height = 2 * (int)(side_height/80.0) + 3;
00407 nr_of_360_deg_steps = (int)(bottomRadius/50.0) * 16 + 16;
00408 nr_of_180_deg_grasps = 2;
00409 nr_of_grasp_rotations = 4;
00410 break;
00411 default:
00412 nr_of_parallel_planes_height = 2 * (int)(side_height/70.0) + 2 * parameterMode + 1;
00413 nr_of_360_deg_steps = (int)(bottomRadius/50.0) * 24 + 4 * parameterMode;
00414 nr_of_180_deg_grasps = 2;
00415 nr_of_grasp_rotations = parameterMode + 4;
00416 break;
00417 }
00418 #ifdef GRASPITDBG
00419 std::cout << "PL_OUT: no of parallel planes in height " << nr_of_parallel_planes_height << std::endl;
00420 std::cout << "PL_OUT: no of 360 deg samples " << nr_of_360_deg_steps << std::endl;
00421 std::cout << "PL_OUT: no of 180 deg grasps " << nr_of_180_deg_grasps << std::endl;
00422 std::cout << "PL_OUT: no of grasp rotations " << nr_of_grasp_rotations << std::endl;
00423 #endif
00424 }
00425 else if (sop->getTail()->isOfType(SoSphere::getClassTypeId())){
00426
00427
00428
00429 double radius = ((SoSphere*)sop->getTail())->radius.getValue();
00430 switch (parameterMode){
00431 case 1:
00432 nr_of_360_deg_steps = (int)(radius/100.0) * 4 + 4;
00433 nr_of_grasp_rotations = 2;
00434 break;
00435 case 2:
00436 nr_of_360_deg_steps = (int)(radius/100.0) * 8 + 8;
00437 nr_of_grasp_rotations = 4;
00438 break;
00439 case 3:
00440 nr_of_360_deg_steps = (int)(radius/50.0) * 16 + 16;
00441 nr_of_grasp_rotations = 4;
00442 break;
00443 default:
00444 nr_of_360_deg_steps = (int)(radius/50.0) * 24 + 4 * parameterMode;
00445 nr_of_grasp_rotations = parameterMode + 4;
00446 break;
00447 }
00448 #ifdef GRASPITDBG
00449 std::cout << "PL_OUT: no of 360 deg samples " << nr_of_360_deg_steps << std::endl;
00450 std::cout << "PL_OUT: no of grasp rotations " << nr_of_grasp_rotations << std::endl;
00451 #endif
00452 }
00453
00454 return true;
00455 }
00456
00462 int
00463 grasp_planner::determineNumberOfGrasps(SoPathList pl){
00464 int nrOfPrim = pl.getLength();
00465 int nrOfGrasps = 0;
00466
00467 for (int i=0; i<nrOfPrim; i++){
00468
00469 if (pl[i]->getTail()->isOfType(SoCylinder::getClassTypeId())){
00470
00471
00472
00473 nrOfGrasps += nr_of_360_deg_steps * nr_of_parallel_planes_height * nr_of_180_deg_grasps * 2 +
00474 nr_of_grasp_rotations * 2;
00475 }
00476 else if (pl[i]->getTail()->isOfType(SoCube::getClassTypeId())){
00477
00478
00479
00480 nrOfGrasps += nr_of_parallel_planes_width * nr_of_parallel_planes_height * nr_of_180_deg_grasps * 12;
00481 }
00482 else if (pl[i]->getTail()->isOfType(SoCone::getClassTypeId())){
00483
00484
00485
00486 nrOfGrasps += nr_of_360_deg_steps * nr_of_parallel_planes_height * nr_of_180_deg_grasps * 2 +
00487 nr_of_360_deg_steps * nr_of_180_deg_grasps * 2 +
00488 nr_of_grasp_rotations * 2;
00489 }
00490 else if (pl[i]->getTail()->isOfType(SoSphere::getClassTypeId())){
00491
00492
00493
00494
00495 nrOfGrasps += nr_of_grasp_rotations * nr_of_360_deg_steps * nr_of_360_deg_steps;
00496 }
00497 }
00498 return nrOfGrasps;
00499 }
00500
00508 bool
00509 grasp_planner::existsInList(plannedGrasp pg, std::list<plannedGrasp*> pgList)
00510 {
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531 pg = pg;
00532 pgList = pgList;
00533 assert(0);
00534 return false;
00535 }
00536
00540 bool
00541 grasp_planner::set_planningParameters(int nr_of_360_deg_steps_in,
00542 int nr_of_parallel_planes_in,
00543 int nr_of_180_deg_grasps_in,
00544 int nr_of_grasp_rotations_in){
00545
00546 if ((nr_of_360_deg_steps_in > 0) &&
00547 ((nr_of_360_deg_steps_in % 2) == 0) &&
00548 ((nr_of_parallel_planes_in > 0) &&
00549 ((nr_of_parallel_planes_in % 2) == 1)) &&
00550 ((nr_of_180_deg_grasps_in == 1) ||
00551 (nr_of_180_deg_grasps_in == 2)) &&
00552 (nr_of_grasp_rotations_in > 0)){
00553
00554 nr_of_360_deg_steps = nr_of_360_deg_steps_in;
00555 nr_of_parallel_planes_width = nr_of_parallel_planes_in;
00556 nr_of_parallel_planes_height = nr_of_parallel_planes_in;
00557 nr_of_parallel_planes_depth = nr_of_parallel_planes_in;
00558 nr_of_180_deg_grasps = nr_of_180_deg_grasps_in;
00559 nr_of_grasp_rotations = nr_of_grasp_rotations_in;
00560 return true;
00561 }
00562 return false;
00563 }
00564
00568 void
00569 grasp_planner::get_planningParameters(int& nr_of_360_deg_steps_in,
00570 int& nr_of_parallel_planes_in,
00571 int& nr_of_180_deg_grasps_in,
00572 int& nr_of_grasp_rotations_in){
00573 nr_of_360_deg_steps_in = nr_of_360_deg_steps;
00574 nr_of_parallel_planes_in = nr_of_parallel_planes_height;
00575 nr_of_180_deg_grasps_in = nr_of_180_deg_grasps;
00576 nr_of_grasp_rotations_in = nr_of_grasp_rotations;
00577 }
00578
00585 SoPathList
00586 grasp_planner::searchPrimitives(GraspableBody* bg)
00587 {
00588 SoPathList pl_ret;
00589 SoPathList pl;
00590 SoSearchAction *saction = new SoSearchAction;
00591 SoGroup *primGeomRoot;
00592 int j;
00593
00594 bg = NULL;
00595 primGeomRoot = IVGeomPrimitives;
00596
00597
00598 saction->setType(SoCylinder::getClassTypeId());
00599 saction->setInterest(SoSearchAction::ALL);
00600 saction->apply(primGeomRoot);
00601
00602 pl = saction->getPaths();
00603 for (j=0; j<pl.getLength(); j++)
00604 {
00605 if (pl[j]->getTail()->isOfType(SoCylinder::getClassTypeId()))
00606 {
00607 pl_ret.append(pl[j]);
00608 }
00609 }
00610
00611
00612 saction->setType(SoCube::getClassTypeId());
00613 saction->apply(primGeomRoot);
00614
00615 pl = saction->getPaths();
00616 for (j=0; j<pl.getLength(); j++)
00617 {
00618 if (pl[j]->getTail()->isOfType(SoCube::getClassTypeId()))
00619 {
00620 pl_ret.append(pl[j]);
00621 }
00622 else pl.remove(j);
00623 }
00624
00625
00626 saction->setType(SoCone::getClassTypeId());
00627 saction->apply(primGeomRoot);
00628
00629 pl = saction->getPaths();
00630 for (j=0; j<pl.getLength(); j++)
00631 {
00632 if (pl[j]->getTail()->isOfType(SoCone::getClassTypeId()))
00633 {
00634 pl_ret.append(pl[j]);
00635 }
00636 }
00637
00638
00639 saction->setType(SoSphere::getClassTypeId());
00640 saction->apply(primGeomRoot);
00641
00642 pl = saction->getPaths();
00643 for (j=0; j<pl.getLength(); j++)
00644 {
00645 if (pl[j]->getTail()->isOfType(SoSphere::getClassTypeId()))
00646 {
00647 pl_ret.append(pl[j]);
00648 }
00649 }
00650
00651 delete saction;
00652 return pl_ret;
00653 }
00654
00660 SoPath*
00661 grasp_planner::getGlobalPath(SoNode *node)
00662 {
00663 SoPathList pl;
00664
00665 SoSearchAction saction;
00666
00667
00668 saction.setNode(node);
00669 saction.setInterest(SoSearchAction::ALL);
00670 saction.apply(ivmgr->getWorld()->getIVRoot());
00671 pl = saction.getPaths();
00672
00673
00674 if (pl.getLength())
00675 return new SoPath(*pl[0]);
00676 #ifdef GRASPITDBG
00677 std::cout << "PL_OUT: Global path not found" << std::endl;
00678 #endif
00679 return NULL;
00680 }
00681
00688 void
00689 grasp_planner::localToGlobalCoordinates(std::list<plannedGrasp*>& graspList,
00690 SoPath *pathToPrim,
00691 const transf &objTran)
00692 {
00693 std::list <plannedGrasp*>::iterator it;
00694 cartesianGraspDirection cgd;
00695 SoGetMatrixAction *gma;
00696 SoTransform *IVprimTran;
00697 transf primTran;
00698
00699 IVprimTran= new SoTransform;
00700 IVprimTran->ref();
00701
00702
00703
00704 gma = new SoGetMatrixAction(myViewer->getViewportRegion());
00705 gma->apply(pathToPrim);
00706 IVprimTran->setMatrix(gma->getMatrix());
00707 primTran.set(IVprimTran);
00708 delete gma;
00709 IVprimTran->unref();
00710
00711
00712 primTran = primTran * objTran;
00713
00714 for (it=graspList.begin(); it!=graspList.end(); it++){
00715
00716
00717
00718 position graspPos = (*it)->get_graspDirection().get_point()+position::ORIGIN;
00719 cgd.set_point(graspPos*primTran - position::ORIGIN);
00720
00721 cgd.set_dir((*it)->get_graspDirection().get_dir()*primTran);
00722
00723
00724 (*it)->set_graspDirection(cgd);
00725 (*it)->set_fixedFingerDirection((*it)->get_fixedFingerDirection()*primTran);
00726 }
00727 }
00728
00735 std::list <plannedGrasp*>
00736 grasp_planner::getPlannedGraspDirections(SoPath* sop)
00737 {
00738
00739 std::list <GraspDirection*> gd_list;
00740 std::list <GraspDirection*>::iterator gd_it;
00741 std::list <plannedGrasp*> graspList;
00742
00743 if (sop->getTail()->isOfType(SoCylinder::getClassTypeId())){
00744
00745
00746
00747 gd_list = getCylinderGraspDirections(sop);
00748 }
00749 else if (sop->getTail()->isOfType(SoCube::getClassTypeId())){
00750
00751
00752
00753 gd_list = getCubeGraspDirections(sop);
00754 }
00755 else if (sop->getTail()->isOfType(SoCone::getClassTypeId())){
00756
00757
00758
00759 gd_list = getConeGraspDirections(sop);
00760 }
00761 else if (sop->getTail()->isOfType(SoSphere::getClassTypeId())){
00762
00763
00764
00765 gd_list = getSphereGraspDirections(sop);
00766 }
00767 #ifdef GRASPITDBG
00768 else std::cout << "PL_OUT: not a valid primitive. " << std::endl;
00769 #endif
00770
00771
00772 for (gd_it=gd_list.begin(); gd_it!=gd_list.end(); gd_it++){
00773
00774
00775
00776 graspList.push_back(new plannedGrasp(*gd_it));
00777 delete (*gd_it);
00778 }
00779
00780 return graspList;
00781
00782 }
00783
00784
00791 std::list <GraspDirection*>
00792 grasp_planner::getCylinderGraspDirections(SoPath* sop)
00793 {
00794
00795 std::list <GraspDirection*> gd_list;
00796 std::list <GraspDirection*>::iterator gd_it;
00797
00798
00799
00800
00801 GraspDirection* cgd;
00802
00803 cylindrical_coordinates ccpoint;
00804 cylindrical_coordinates ccdir;
00805 double radius = ((SoCylinder*)sop->getTail())->radius.getValue();
00806 double height = ((SoCylinder*)sop->getTail())->height.getValue();
00807 double plane_height;
00808
00809
00810 cgd = new cartesianGraspDirection;
00811 ccpoint[0] = 0.0; ccpoint[1] = 0.0; ccpoint[2] = height/2 + STARTING_DISTANCE;
00812 ccdir[0] = 0.0; ccdir[1] = 0.0; ccdir[2] = -1.0;
00813
00814 cgd->set_point(ccpoint.get_pos_cartesian());
00815 cgd->set_dir(ccdir.get_vec_cartesian(ccpoint));
00816 cgd->set_gdType(GDT_CYL_TOP_BOTTOM);
00817
00818 gd_list.push_back(cgd);
00819
00820
00821 cgd = new cartesianGraspDirection;
00822 ccpoint[0] = 0.0; ccpoint[1] = 0.0; ccpoint[2] = (-1) * (height/2 + STARTING_DISTANCE);
00823 ccdir[0] = 0.0; ccdir[1] = 0.0; ccdir[2] = 1.0;
00824
00825 cgd->set_point(ccpoint.get_pos_cartesian());
00826 cgd->set_dir(ccdir.get_vec_cartesian(ccpoint));
00827 cgd->set_gdType(GDT_CYL_TOP_BOTTOM);
00828
00829 gd_list.push_back(cgd);
00830
00831
00832 for (int curr_plane=1; curr_plane<=nr_of_parallel_planes_height; curr_plane++){
00833 plane_height = -height/2 + curr_plane*(height/(nr_of_parallel_planes_height + 1));
00834 for (double step=0.0; step <= 2*M_PI-DELTA_360_DEG_ERROR; step+=(2*M_PI)/nr_of_360_deg_steps){
00835 cgd = new cartesianGraspDirection;
00836 ccpoint[0] = radius + STARTING_DISTANCE; ccpoint[1] = step; ccpoint[2] = plane_height;
00837 ccdir[0] = -1.0; ccdir[1] = 0.0; ccdir[2] = 0.0;
00838
00839 cgd->set_point(ccpoint.get_pos_cartesian());
00840 cgd->set_dir(ccdir.get_vec_cartesian(ccpoint));
00841 cgd->set_gdType(GDT_CYL_SIDES);
00842
00843 gd_list.push_back(cgd);
00844 }
00845 }
00846
00847
00848
00849
00850
00851
00852
00853
00854 for (gd_it=gd_list.begin(); gd_it!=gd_list.end(); gd_it++){
00855
00856 cartesian_coordinates cctmp((*gd_it)->get_point());
00857 double ytmp = cctmp[1];
00858 cctmp[1] = cctmp[2];
00859 cctmp[2] = ytmp;
00860 (*gd_it)->set_point(cctmp);
00861
00862 cctmp = (*gd_it)->get_dir();
00863 ytmp = cctmp[1];
00864 cctmp[1] = cctmp[2];
00865 cctmp[2] = ytmp;
00866 (*gd_it)->set_dir(cctmp);
00867 }
00868 return gd_list;
00869 }
00870
00877 std::list <GraspDirection*>
00878 grasp_planner::getCubeGraspDirections(SoPath* sop)
00879 {
00880
00881 std::list <GraspDirection*> gd_list;
00882 GraspDirection* cgd;
00883
00884
00885
00886
00887
00888 cartesian_coordinates ccpoint;
00889 cartesian_coordinates ccdir;
00890 double width = ((SoCube*)sop->getTail())->width.getValue();
00891 double height = ((SoCube*)sop->getTail())->height.getValue();
00892 double depth = ((SoCube*)sop->getTail())->depth.getValue();
00893 double plane_heightA;
00894 double plane_heightB;
00895 int curr_planeA,curr_planeB;
00896
00897
00898 for (curr_planeA = 1; curr_planeA <= nr_of_parallel_planes_width; curr_planeA++){
00899 for (curr_planeB = 1; curr_planeB <= nr_of_parallel_planes_depth; curr_planeB++){
00900 plane_heightA = - width/2 + curr_planeA * (width/(nr_of_parallel_planes_width + 1));
00901 plane_heightB = - depth/2 + curr_planeB * (depth/(nr_of_parallel_planes_depth + 1));
00902
00903 cgd = new cartesianGraspDirection;
00904 ccpoint[0] = plane_heightA; ccpoint[1] = height + STARTING_DISTANCE; ccpoint[2] = plane_heightB;
00905 ccdir[0] = 0.0; ccdir[1] = -1.0; ccdir[2] = 0.0;
00906
00907 cgd->set_point(ccpoint.get_pos_cartesian());
00908 cgd->set_dir(ccdir.get_vec_cartesian(ccpoint));
00909 cgd->set_gdType(GDT_CUBE_HEIGHT);
00910
00911 gd_list.push_back(cgd);
00912 }
00913 }
00914
00915 for (curr_planeA = 1; curr_planeA <= nr_of_parallel_planes_width; curr_planeA++){
00916 for (curr_planeB = 1; curr_planeB <= nr_of_parallel_planes_depth; curr_planeB++){
00917 plane_heightA = - width/2 + curr_planeA * (width/(nr_of_parallel_planes_width + 1));
00918 plane_heightB = - depth/2 + curr_planeB * (depth/(nr_of_parallel_planes_depth + 1));
00919
00920 cgd = new cartesianGraspDirection;
00921 ccpoint[0] = plane_heightA; ccpoint[1] = -1 * (height + STARTING_DISTANCE); ccpoint[2] = plane_heightB;
00922 ccdir[0] = 0.0; ccdir[1] = 1.0; ccdir[2] = 0.0;
00923
00924 cgd->set_point(ccpoint.get_pos_cartesian());
00925 cgd->set_dir(ccdir.get_vec_cartesian(ccpoint));
00926 cgd->set_gdType(GDT_CUBE_HEIGHT);
00927
00928 gd_list.push_back(cgd);
00929 }
00930 }
00931
00932 for (curr_planeA = 1; curr_planeA <= nr_of_parallel_planes_height; curr_planeA++){
00933 for (curr_planeB = 1; curr_planeB <= nr_of_parallel_planes_depth; curr_planeB++){
00934 plane_heightA = - height/2 + curr_planeA * (height/(nr_of_parallel_planes_height + 1));
00935 plane_heightB = - depth/2 + curr_planeB * (depth/(nr_of_parallel_planes_depth + 1));
00936
00937 cgd = new cartesianGraspDirection;
00938 ccpoint[0] = width + STARTING_DISTANCE; ccpoint[1] = plane_heightA; ccpoint[2] = plane_heightB;
00939 ccdir[0] = -1.0; ccdir[1] = 0.0; ccdir[2] = 0.0;
00940
00941 cgd->set_point(ccpoint.get_pos_cartesian());
00942 cgd->set_dir(ccdir.get_vec_cartesian(ccpoint));
00943 cgd->set_gdType(GDT_CUBE_WIDTH);
00944
00945 gd_list.push_back(cgd);
00946 }
00947 }
00948
00949 for (curr_planeA = 1; curr_planeA <= nr_of_parallel_planes_height; curr_planeA++){
00950 for (curr_planeB = 1; curr_planeB <= nr_of_parallel_planes_depth; curr_planeB++){
00951 plane_heightA = - height/2 + curr_planeA * (height/(nr_of_parallel_planes_height + 1));
00952 plane_heightB = - depth/2 + curr_planeB * (depth/(nr_of_parallel_planes_depth + 1));
00953
00954 cgd = new cartesianGraspDirection;
00955 ccpoint[0] = -1 * (width + STARTING_DISTANCE); ccpoint[1] = plane_heightA; ccpoint[2] = plane_heightB;
00956 ccdir[0] = 1.0; ccdir[1] = 0.0; ccdir[2] = 0.0;
00957
00958 cgd->set_point(ccpoint.get_pos_cartesian());
00959 cgd->set_dir(ccdir.get_vec_cartesian(ccpoint));
00960 cgd->set_gdType(GDT_CUBE_WIDTH);
00961
00962 gd_list.push_back(cgd);
00963 }
00964 }
00965
00966 for (curr_planeA = 1; curr_planeA <= nr_of_parallel_planes_width; curr_planeA++){
00967 for (curr_planeB = 1; curr_planeB <= nr_of_parallel_planes_height; curr_planeB++){
00968 plane_heightA = - width/2 + curr_planeA * (width/(nr_of_parallel_planes_width + 1));
00969 plane_heightB = - height/2 + curr_planeB * (height/(nr_of_parallel_planes_height + 1));
00970
00971 cgd = new cartesianGraspDirection;
00972 ccpoint[0] = plane_heightA; ccpoint[1] = plane_heightB; ccpoint[2] = depth + STARTING_DISTANCE;
00973 ccdir[0] = 0.0; ccdir[1] = 0.0; ccdir[2] = -1.0;
00974
00975 cgd->set_point(ccpoint.get_pos_cartesian());
00976 cgd->set_dir(ccdir.get_vec_cartesian(ccpoint));
00977 cgd->set_gdType(GDT_CUBE_DEPTH);
00978
00979 gd_list.push_back(cgd);
00980 }
00981 }
00982
00983 for (curr_planeA = 1; curr_planeA <= nr_of_parallel_planes_width; curr_planeA++){
00984 for (curr_planeB = 1; curr_planeB <= nr_of_parallel_planes_height; curr_planeB++){
00985 plane_heightA = - width/2 + curr_planeA * (width/(nr_of_parallel_planes_width + 1));
00986 plane_heightB = - height/2 + curr_planeB * (height/(nr_of_parallel_planes_height + 1));
00987
00988 cgd = new cartesianGraspDirection;
00989 ccpoint[0] = plane_heightA; ccpoint[1] = plane_heightB; ccpoint[2] = -1 * (depth + STARTING_DISTANCE);
00990 ccdir[0] = 0.0; ccdir[1] = 0.0; ccdir[2] = 1.0;
00991
00992 cgd->set_point(ccpoint.get_pos_cartesian());
00993 cgd->set_dir(ccdir.get_vec_cartesian(ccpoint));
00994 cgd->set_gdType(GDT_CUBE_DEPTH);
00995
00996 gd_list.push_back(cgd);
00997 }
00998 }
00999
01000 return gd_list;
01001 }
01002
01009 std::list <GraspDirection*>
01010 grasp_planner::getSphereGraspDirections(SoPath* sop)
01011 {
01012
01013 std::list <GraspDirection*> gd_list;
01014
01015
01016
01017
01018 GraspDirection* cgd;
01019
01020 spherical_coordinates ccpoint;
01021 spherical_coordinates ccdir;
01022 double radius = ((SoSphere*)sop->getTail())->radius.getValue();
01023 double teta, phi;
01024 for (teta=0.0; teta<=M_PI; teta+=M_PI/(nr_of_360_deg_steps/2)){
01025 if (teta == 0.0 || teta >= M_PI){
01026 cgd = new cartesianGraspDirection;
01027 ccpoint[0] = radius + STARTING_DISTANCE; ccpoint[1] = teta; ccpoint[2] = 0.0;
01028 ccdir[0] = -1.0; ccdir[1] = 0.0; ccdir[2] = 0.0;
01029
01030 cgd->set_point(ccpoint.get_pos_cartesian());
01031 cgd->set_dir(ccdir.get_vec_cartesian(ccpoint));
01032 cgd->set_gdType(GDT_SPH);
01033
01034 gd_list.push_back(cgd);
01035 }
01036 else{
01037 for (phi=0.0; phi <= 2*M_PI; phi+=(2*M_PI)/((int)(nr_of_360_deg_steps * sin(teta))+1)){
01038
01039 cgd = new cartesianGraspDirection;
01040 ccpoint[0] = radius + STARTING_DISTANCE; ccpoint[1] = teta; ccpoint[2] = phi;
01041 ccdir[0] = -1.0; ccdir[1] = 0.0; ccdir[2] = 0.0;
01042
01043 cgd->set_point(ccpoint.get_pos_cartesian());
01044 cgd->set_dir(ccdir.get_vec_cartesian(ccpoint));
01045 cgd->set_gdType(GDT_SPH);
01046
01047 gd_list.push_back(cgd);
01048 }
01049 }
01050 }
01051 return gd_list;
01052 }
01053
01060 std::list <GraspDirection*>
01061 grasp_planner::getConeGraspDirections(SoPath* sop)
01062 {
01063
01064
01065
01066 std::list <GraspDirection*> gd_list;
01067 std::list <GraspDirection*>::iterator gd_it;
01068
01069
01070
01071
01072 GraspDirection* cgd;
01073
01074 cylindrical_coordinates ccpoint;
01075 cylindrical_coordinates ccdir;
01076 double bottomRadius = ((SoCone*)sop->getTail())->bottomRadius.getValue();
01077 double height = ((SoCone*)sop->getTail())->height.getValue();
01078 double side_height = sqrt(bottomRadius * bottomRadius + height * height);
01079 double bottomAngle = atan2(height, bottomRadius);
01080 double plane_height;
01081
01082
01083 cgd = new cartesianGraspDirection;
01084 ccpoint[0] = 0.0; ccpoint[1] = 0.0; ccpoint[2] = height/2 + STARTING_DISTANCE;
01085 ccdir[0] = 0.0; ccdir[1] = 0.0; ccdir[2] = -1.0;
01086
01087 cgd->set_point(ccpoint.get_pos_cartesian());
01088 cgd->set_dir(ccdir.get_vec_cartesian(ccpoint));
01089 cgd->set_gdType(GDT_CONE_TOP);
01090
01091 gd_list.push_back(cgd);
01092
01093
01094 cgd = new cartesianGraspDirection;
01095 ccpoint[0] = 0.0; ccpoint[1] = 0.0; ccpoint[2] = (-1) * (height/2 + STARTING_DISTANCE);
01096 ccdir[0] = 0.0; ccdir[1] = 0.0; ccdir[2] = 1.0;
01097
01098 cgd->set_point(ccpoint.get_pos_cartesian());
01099 cgd->set_dir(ccdir.get_vec_cartesian(ccpoint));
01100 cgd->set_gdType(GDT_CONE_BOTTOM);
01101
01102 gd_list.push_back(cgd);
01103
01104
01105 for (int curr_plane = 1; curr_plane <= nr_of_parallel_planes_height; curr_plane++){
01106 plane_height = curr_plane * (side_height/(nr_of_parallel_planes_height + 1));
01107
01108 for (double step=0.0; step <= 2*M_PI-DELTA_360_DEG_ERROR; step+=(2*M_PI)/nr_of_360_deg_steps){
01109 cgd = new cartesianGraspDirection;
01110 ccpoint[0] = bottomRadius - plane_height * cos(bottomAngle) + STARTING_DISTANCE * sin(bottomAngle);
01111 ccpoint[1] = step;
01112 ccpoint[2] = -height/2 + plane_height * sin(bottomAngle) + STARTING_DISTANCE * cos(bottomAngle);
01113
01114 ccdir[0] = (-1) * sin(bottomAngle);
01115 ccdir[1] = 0.0;
01116 ccdir[2] = (-1) * cos(bottomAngle);
01117
01118 cgd->set_point(ccpoint.get_pos_cartesian());
01119 cgd->set_dir(ccdir.get_vec_cartesian(ccpoint));
01120 cgd->set_gdType(GDT_CONE_SIDE_PLANE);
01121
01122 gd_list.push_back(cgd);
01123 }
01124 }
01125
01126
01127 for (double step=0.0; step <= 2*M_PI-DELTA_360_DEG_ERROR; step+=(2*M_PI)/nr_of_360_deg_steps){
01128 cgd = new cartesianGraspDirection;
01129 ccpoint[0] = bottomRadius + STARTING_DISTANCE * cos(bottomAngle/2);
01130 ccpoint[1] = step;
01131 ccpoint[2] = -height/2 - STARTING_DISTANCE * sin(bottomAngle/2);
01132
01133 ccdir[0] = (-1) * cos(bottomAngle/2);
01134 ccdir[1] = 0.0;
01135 ccdir[2] = sin(bottomAngle/2);
01136
01137 cgd->set_point(ccpoint.get_pos_cartesian());
01138 cgd->set_dir(ccdir.get_vec_cartesian(ccpoint));
01139 cgd->set_gdType(GDT_CONE_EDGE);
01140
01141 gd_list.push_back(cgd);
01142 }
01143
01144
01145
01146
01147
01148
01149
01150
01151
01152 for (gd_it=gd_list.begin(); gd_it!=gd_list.end(); gd_it++){
01153
01154 cartesian_coordinates cctmp((*gd_it)->get_point());
01155 double ytmp = cctmp[1];
01156 cctmp[1] = cctmp[2];
01157 cctmp[2] = ytmp;
01158 (*gd_it)->set_point(cctmp);
01159
01160 cctmp = (*gd_it)->get_dir();
01161 ytmp = cctmp[1];
01162 cctmp[1] = cctmp[2];
01163 cctmp[2] = ytmp;
01164 (*gd_it)->set_dir(cctmp);
01165 }
01166 return gd_list;
01167 }
01168
01175 void
01176 grasp_planner::computeGraspPreshapes(std::list<plannedGrasp*>& graspList, SoPath* sop)
01177 {
01178 std::list<plannedGrasp*> retList;
01179
01180 if (sop->getTail()->isOfType(SoCylinder::getClassTypeId())){
01181
01182
01183
01184 computeCylinderGraspPreshapes(graspList, sop);
01185 }
01186 else if (sop->getTail()->isOfType(SoCube::getClassTypeId())){
01187
01188
01189
01190 computeCubeGraspPreshapes(graspList, sop);
01191 }
01192 else if (sop->getTail()->isOfType(SoCone::getClassTypeId())){
01193
01194
01195
01196 computeConeGraspPreshapes(graspList, sop);
01197 }
01198 else if (sop->getTail()->isOfType(SoSphere::getClassTypeId())){
01199
01200
01201
01202 computeSphereGraspPreshapes(graspList, sop);
01203 }
01204 #ifdef GRASPITDBG
01205 else std::cout << "PL_OUT: not a valid primitive. " << std::endl;
01206 #endif
01207
01208 return;
01209 }
01210
01218 void
01219 grasp_planner::computeCubeGraspPreshapes(std::list<plannedGrasp*>& graspList, SoPath* sop)
01220 {
01221 preshape comp_preshape;
01222
01223 cartesian_coordinates help;
01224 cartesian_coordinates ffd;
01225 plannedGrasp *pg;
01226 std::list<plannedGrasp*> retList;
01227 std::list<plannedGrasp*>::iterator it;
01228 double width = ((SoCube*)sop->getTail())->width.getValue();
01229 double height = ((SoCube*)sop->getTail())->height.getValue();
01230 double depth = ((SoCube*)sop->getTail())->depth.getValue();
01231
01232 for (it=graspList.begin(); it!=graspList.end(); it++){
01233
01234
01235
01236 if ((*it)->get_graspDirection().get_dir().x() != 0.0)
01237 help = cartesian_coordinates(0.0, 1.0, 0.0);
01238 else if ((*it)->get_graspDirection().get_dir().y() != 0.0)
01239 help = cartesian_coordinates(1.0, 0.0, 0.0);
01240 else if ((*it)->get_graspDirection().get_dir().z() != 0.0)
01241 help = cartesian_coordinates(1.0, 0.0, 0.0);
01242
01243
01244 pg = new plannedGrasp((*it)->get_graspDirection());
01245 comp_preshape.set_preshapeType(PRESHAPE_CUBE_GRASP);
01246 pg->set_preshape(comp_preshape);
01247 ffd = cartesian_coordinates((*it)->get_graspDirection().get_dir() * help);
01248 pg->set_fixedFingerDirection(ffd);
01249
01250 if((ffd[0]!=0.0 && width <= GP_MAX_CUBE_SIZE && width >= GP_MIN_CUBE_SIZE) ||
01251 (ffd[1]!=0.0 && height <= GP_MAX_CUBE_SIZE && height >= GP_MIN_CUBE_SIZE) ||
01252 (ffd[2]!=0.0 && depth <= GP_MAX_CUBE_SIZE && depth >= GP_MIN_CUBE_SIZE)){
01253 retList.push_back(pg);
01254 }
01255 else delete pg;
01256
01257 ffd = cartesian_coordinates((*it)->get_graspDirection().get_dir() * ffd);
01258 pg = new plannedGrasp((*it)->get_graspDirection());
01259 comp_preshape.set_preshapeType(PRESHAPE_CUBE_GRASP);
01260 pg->set_preshape(comp_preshape);
01261 pg->set_fixedFingerDirection(ffd);
01262
01263 if((ffd[0]!=0.0 && width <= GP_MAX_CUBE_SIZE && width >= GP_MIN_CUBE_SIZE) ||
01264 (ffd[1]!=0.0 && height <= GP_MAX_CUBE_SIZE && height >= GP_MIN_CUBE_SIZE) ||
01265 (ffd[2]!=0.0 && depth <= GP_MAX_CUBE_SIZE && depth >= GP_MIN_CUBE_SIZE)){
01266 retList.push_back(pg);
01267 }
01268 else delete pg;
01269
01270 ffd = cartesian_coordinates((*it)->get_graspDirection().get_dir() * ffd);
01271 if (nr_of_180_deg_grasps == 2){
01272 pg = new plannedGrasp((*it)->get_graspDirection());
01273 comp_preshape.set_preshapeType(PRESHAPE_CUBE_GRASP);
01274 pg->set_preshape(comp_preshape);
01275 pg->set_fixedFingerDirection(ffd);
01276
01277 if((ffd[0]!=0.0 && width <= GP_MAX_CUBE_SIZE && width >= GP_MIN_CUBE_SIZE) ||
01278 (ffd[1]!=0.0 && height <= GP_MAX_CUBE_SIZE && height >= GP_MIN_CUBE_SIZE) ||
01279 (ffd[2]!=0.0 && depth <= GP_MAX_CUBE_SIZE && depth >= GP_MIN_CUBE_SIZE)){
01280 retList.push_back(pg);
01281 }
01282 else delete pg;
01283 }
01284
01285 ffd = cartesian_coordinates((*it)->get_graspDirection().get_dir() * ffd);
01286 if (nr_of_180_deg_grasps == 2){
01287 pg = new plannedGrasp((*it)->get_graspDirection());
01288 comp_preshape.set_preshapeType(PRESHAPE_CUBE_GRASP);
01289 pg->set_preshape(comp_preshape);
01290 pg->set_fixedFingerDirection(ffd);
01291
01292 if((ffd[0]!=0.0 && width <= GP_MAX_CUBE_SIZE && width >= GP_MIN_CUBE_SIZE) ||
01293 (ffd[1]!=0.0 && height <= GP_MAX_CUBE_SIZE && height >= GP_MIN_CUBE_SIZE) ||
01294 (ffd[2]!=0.0 && depth <= GP_MAX_CUBE_SIZE && depth >= GP_MIN_CUBE_SIZE)){
01295 retList.push_back(pg);
01296 }
01297 else delete pg;
01298 }
01299 }
01300
01301 for (it=graspList.begin(); it!=graspList.end(); it++){
01302 delete (*it);
01303 }
01304 graspList.clear();
01305
01306 graspList = retList;
01307
01308 return;
01309 }
01310
01319 void
01320 grasp_planner::computeCylinderGraspPreshapes(std::list<plannedGrasp*>& graspList, SoPath* sop)
01321 {
01322 cartesian_coordinates help1;
01323 cartesian_coordinates help2;
01324 cartesian_coordinates ffd;
01325 preshape comp_preshape;
01326 plannedGrasp *pg;
01327 std::list<plannedGrasp*> retList;
01328 std::list<plannedGrasp*>::iterator it;
01329 double radius = ((SoCylinder*)sop->getTail())->radius.getValue();
01330 double height = ((SoCylinder*)sop->getTail())->height.getValue();
01331 double step;
01332
01333 for (it=graspList.begin(); it!=graspList.end(); it++){
01334 if ((*it)->get_graspDirection().get_gdType() == GDT_CYL_TOP_BOTTOM){
01335 if((radius <= GP_MAX_CYL_TBGRASP_DIAMETER) &&
01336 (radius >= GP_MIN_CYL_TBGRASP_DIAMETER)){
01337
01338 comp_preshape.set_preshapeType(PRESHAPE_CYLINDER_TOP_BOTTOM_GRASP);
01339
01340 help1 = cartesian_coordinates(1.0, 0.0, 0.0);
01341 help2 = (*it)->get_graspDirection().get_dir() * help1;
01342
01343 for (int i=0; i< nr_of_grasp_rotations; i++){
01344 step = (double)i*2.0*M_PI/(double)nr_of_grasp_rotations;
01345 pg = new plannedGrasp((*it)->get_graspDirection());
01346 pg->set_preshape(comp_preshape);
01347 ffd = cartesian_coordinates(cos(step) * help1 + sin(step) * help2);
01348 pg->set_fixedFingerDirection(ffd);
01349 retList.push_back(pg);
01350 }
01351 }
01352 }
01353 else if ((*it)->get_graspDirection().get_gdType() == GDT_CYL_SIDES){
01354
01355 comp_preshape.set_preshapeType(PRESHAPE_CYLINDER_SIDE_GRASP);
01356
01357
01358 pg = new plannedGrasp((*it)->get_graspDirection());
01359 pg->set_preshape(comp_preshape);
01360 ffd = cartesian_coordinates((*it)->get_graspDirection().get_dir() * cartesian_coordinates(0.0, 1.0, 0.0));
01361 pg->set_fixedFingerDirection(ffd);
01362 if((radius <= GP_MAX_CYL_SIDEGRASP_DIAMETER) &&
01363 (radius >= GP_MIN_CYL_SIDEGRASP_DIAMETER) &&
01364 (height >= GP_MIN_CYL_SIDEGRASP_HEIGHT))
01365 retList.push_back(pg);
01366 else delete pg;
01367
01368
01369 pg = new plannedGrasp((*it)->get_graspDirection());
01370 pg->set_preshape(comp_preshape);
01371 ffd = cartesian_coordinates((*it)->get_graspDirection().get_dir() * ffd);
01372 pg->set_fixedFingerDirection(ffd);
01373 if (height <= GP_MAX_CYL_SIDEGRASP_HEIGHT)
01374 retList.push_back(pg);
01375 else delete pg;
01376
01377 if (nr_of_180_deg_grasps == 2){
01378
01379 pg = new plannedGrasp((*it)->get_graspDirection());
01380 pg->set_preshape(comp_preshape);
01381 ffd = cartesian_coordinates((*it)->get_graspDirection().get_dir() * ffd);
01382 pg->set_fixedFingerDirection(ffd);
01383 if((radius <= GP_MAX_CYL_SIDEGRASP_DIAMETER) &&
01384 (radius >= GP_MIN_CYL_SIDEGRASP_DIAMETER) &&
01385 (height >= GP_MIN_CYL_SIDEGRASP_HEIGHT))
01386 retList.push_back(pg);
01387 else delete pg;
01388
01389
01390 pg = new plannedGrasp((*it)->get_graspDirection());
01391 pg->set_preshape(comp_preshape);
01392 ffd = cartesian_coordinates((*it)->get_graspDirection().get_dir() * ffd);
01393 pg->set_fixedFingerDirection(ffd);
01394 if (height <= GP_MAX_CYL_SIDEGRASP_HEIGHT)
01395 retList.push_back(pg);
01396 else delete pg;
01397 }
01398 }
01399 }
01400
01401 for (it=graspList.begin(); it!=graspList.end(); it++){
01402 delete (*it);
01403 }
01404 graspList.clear();
01405
01406 graspList = retList;
01407
01408 return;
01409 }
01410
01418 void
01419 grasp_planner::computeSphereGraspPreshapes(std::list<plannedGrasp*>& graspList, SoPath* sop)
01420 {
01421 cartesian_coordinates help1;
01422 cartesian_coordinates help2;
01423 cartesian_coordinates help3;
01424 cartesian_coordinates help4;
01425 cartesian_coordinates ffd;
01426 preshape comp_preshape;
01427 plannedGrasp *pg;
01428 std::list<plannedGrasp*> retList;
01429 std::list<plannedGrasp*>::iterator it;
01430 double radius = ((SoSphere*)sop->getTail())->radius.getValue();
01431 double step;
01432
01433 if((radius <= GP_MAX_SPH_DIAMETER) &&
01434 (radius >= GP_MIN_SPH_DIAMETER)){
01435
01436 comp_preshape.set_preshapeType(PRESHAPE_SPHERE_GRASP);
01437
01438 for (it=graspList.begin(); it!=graspList.end(); it++){
01439
01440
01441
01442 help3 = cartesian_coordinates(1., 0., 0.);
01443 help4 = cartesian_coordinates(0., 1., 1.);
01444 if ((*it)->get_graspDirection().get_dir() % help3 > (*it)->get_graspDirection().get_dir() % help4)
01445 help3 = help4;
01446
01447 help1 = cartesian_coordinates((*it)->get_graspDirection().get_dir() * help3);
01448
01449 help2 = (*it)->get_graspDirection().get_dir() * help1;
01450
01451
01452 for (int i=0; i< nr_of_grasp_rotations; i++){
01453 step = (double)i*2.0*M_PI/(double)nr_of_grasp_rotations;
01454 pg = new plannedGrasp((*it)->get_graspDirection());
01455 pg->set_preshape(comp_preshape);
01456 ffd = cartesian_coordinates(cos(step) * help1 + sin(step) * help2);
01457 pg->set_fixedFingerDirection(ffd);
01458 retList.push_back(pg);
01459 }
01460 }
01461 }
01462
01463 for (it=graspList.begin(); it!=graspList.end(); it++){
01464 delete (*it);
01465 }
01466 graspList.clear();
01467
01468 graspList = retList;
01469
01470 return;
01471 }
01472
01481 void
01482 grasp_planner::computeConeGraspPreshapes(std::list<plannedGrasp*>& graspList, SoPath* sop)
01483 {
01484 cartesian_coordinates help1;
01485 cartesian_coordinates help2;
01486 cartesian_coordinates ffd;
01487 preshape comp_preshape;
01488 plannedGrasp *pg;
01489 std::list<plannedGrasp*> retList;
01490 std::list<plannedGrasp*>::iterator it;
01491 double bottomRadius = ((SoCone*)sop->getTail())->bottomRadius.getValue();
01492 double height = ((SoCone*)sop->getTail())->height.getValue();
01493 double step;
01494
01495 for (it=graspList.begin(); it!=graspList.end(); it++){
01496
01497 if ((*it)->get_graspDirection().get_gdType() == GDT_CONE_TOP){
01498 if((bottomRadius <= GP_MAX_CONE_TGRASP_DIAMETER) &&
01499 (bottomRadius >= GP_MIN_CONE_TGRASP_DIAMETER) &&
01500 (height >= GP_MIN_CONE_TGRASP_HEIGHT)){
01501
01502 comp_preshape.set_preshapeType(PRESHAPE_CONE_TOP_BOTTOM_GRASP);
01503
01504 help1 = cartesian_coordinates(1.0, 0.0, 0.0);
01505 help2 = (*it)->get_graspDirection().get_dir() * help1;
01506
01507 for (int i=0; i< nr_of_grasp_rotations; i++){
01508 step = (double)i*2.0*M_PI/(double)nr_of_grasp_rotations;
01509 pg = new plannedGrasp((*it)->get_graspDirection());
01510 pg->set_preshape(comp_preshape);
01511 ffd = cartesian_coordinates(cos(step) * help1 + sin(step) * help2);
01512 pg->set_fixedFingerDirection(ffd);
01513 retList.push_back(pg);
01514 }
01515 }
01516 }
01517
01518 else if ((*it)->get_graspDirection().get_gdType() == GDT_CONE_BOTTOM){
01519 if((bottomRadius <= GP_MAX_CONE_BGRASP_DIAMETER) &&
01520 (bottomRadius >= GP_MIN_CONE_BGRASP_DIAMETER) &&
01521 (height >= GP_MIN_CONE_BGRASP_HEIGHT)){
01522
01523 comp_preshape.set_preshapeType(PRESHAPE_CONE_TOP_BOTTOM_GRASP);
01524
01525 help1 = cartesian_coordinates(1.0, 0.0, 0.0);
01526 help2 = (*it)->get_graspDirection().get_dir() * help1;
01527
01528 for (int i=0; i< nr_of_grasp_rotations; i++){
01529 step = (double)i*2.0*M_PI/(double)nr_of_grasp_rotations;
01530 pg = new plannedGrasp((*it)->get_graspDirection());
01531 pg->set_preshape(comp_preshape);
01532 ffd = cartesian_coordinates(cos(step) * help1 + sin(step) * help2);
01533 pg->set_fixedFingerDirection(ffd);
01534 retList.push_back(pg);
01535 }
01536 }
01537 }
01538
01539
01540 else if ((*it)->get_graspDirection().get_gdType() == GDT_CONE_SIDE_PLANE){
01541
01542 comp_preshape.set_preshapeType(PRESHAPE_CONE_SIDE_GRASP);
01543
01544
01545 pg = new plannedGrasp((*it)->get_graspDirection());
01546 pg->set_preshape(comp_preshape);
01547 if ((*it)->get_graspDirection().get_dir().x() != 0.0 ||
01548 (*it)->get_graspDirection().get_dir().y() != 1.0 ||
01549 (*it)->get_graspDirection().get_dir().z() != 0.0)
01550 ffd = cartesian_coordinates(normalise((*it)->get_graspDirection().get_dir() * cartesian_coordinates(0.0, 1.0, 0.0)));
01551 else
01552 ffd = cartesian_coordinates(normalise((*it)->get_graspDirection().get_dir() * cartesian_coordinates(1.0, 0.0, 0.0)));
01553
01554 pg->set_fixedFingerDirection(ffd);
01555 if((bottomRadius <= GP_MAX_CONE_SIDEGRASP_DIAMETER) &&
01556 (bottomRadius >= GP_MIN_CONE_SIDEGRASP_DIAMETER) &&
01557 (height >= GP_MIN_CONE_SIDEGRASP_HEIGHT))
01558 retList.push_back(pg);
01559 else delete pg;
01560
01561
01562 pg = new plannedGrasp((*it)->get_graspDirection());
01563 pg->set_preshape(comp_preshape);
01564 ffd = cartesian_coordinates((*it)->get_graspDirection().get_dir() * ffd);
01565 pg->set_fixedFingerDirection(ffd);
01566 if (height <= GP_MAX_CONE_SIDEGRASP_HEIGHT)
01567 retList.push_back(pg);
01568 else delete pg;
01569
01570 if (nr_of_180_deg_grasps == 2){
01571
01572 pg = new plannedGrasp((*it)->get_graspDirection());
01573 pg->set_preshape(comp_preshape);
01574 ffd = cartesian_coordinates((*it)->get_graspDirection().get_dir() * ffd);
01575 pg->set_fixedFingerDirection(ffd);
01576 if((bottomRadius <= GP_MAX_CONE_SIDEGRASP_DIAMETER) &&
01577 (bottomRadius >= GP_MIN_CONE_SIDEGRASP_DIAMETER) &&
01578 (height >= GP_MIN_CONE_SIDEGRASP_HEIGHT))
01579 retList.push_back(pg);
01580 else delete pg;
01581
01582
01583 pg = new plannedGrasp((*it)->get_graspDirection());
01584 pg->set_preshape(comp_preshape);
01585 ffd = cartesian_coordinates((*it)->get_graspDirection().get_dir() * ffd);
01586 pg->set_fixedFingerDirection(ffd);
01587 if (height <= GP_MAX_CONE_SIDEGRASP_HEIGHT)
01588 retList.push_back(pg);
01589 else delete pg;
01590 }
01591 }
01592
01593
01594 else if ((*it)->get_graspDirection().get_gdType() == GDT_CONE_EDGE){
01595
01596 comp_preshape.set_preshapeType(PRESHAPE_CONE_EDGE_GRASP);
01597
01598
01599 pg = new plannedGrasp((*it)->get_graspDirection());
01600 pg->set_preshape(comp_preshape);
01601 if ((*it)->get_graspDirection().get_dir().x() != 0.0 ||
01602 (*it)->get_graspDirection().get_dir().y() != 1.0 ||
01603 (*it)->get_graspDirection().get_dir().z() != 0.0)
01604 ffd = cartesian_coordinates(normalise((*it)->get_graspDirection().get_dir() * cartesian_coordinates(0.0, 1.0, 0.0)));
01605 else
01606 ffd = cartesian_coordinates(normalise((*it)->get_graspDirection().get_dir() * cartesian_coordinates(1.0, 0.0, 0.0)));
01607
01608 pg->set_fixedFingerDirection(ffd);
01609 if((bottomRadius <= GP_MAX_CONE_EDGEGRASP_DIAMETER) &&
01610 (bottomRadius >= GP_MIN_CONE_EDGEGRASP_DIAMETER) &&
01611 (height >= GP_MIN_CONE_EDGEGRASP_HEIGHT))
01612 retList.push_back(pg);
01613 else delete pg;
01614
01615
01616 pg = new plannedGrasp((*it)->get_graspDirection());
01617 pg->set_preshape(comp_preshape);
01618 ffd = cartesian_coordinates((*it)->get_graspDirection().get_dir() * ffd);
01619 pg->set_fixedFingerDirection(ffd);
01620 if (height <= GP_MAX_CONE_EDGEGRASP_HEIGHT)
01621 retList.push_back(pg);
01622 else delete pg;
01623
01624 if (nr_of_180_deg_grasps == 2){
01625
01626 pg = new plannedGrasp((*it)->get_graspDirection());
01627 pg->set_preshape(comp_preshape);
01628 ffd = cartesian_coordinates((*it)->get_graspDirection().get_dir() * ffd);
01629 pg->set_fixedFingerDirection(ffd);
01630 if((bottomRadius <= GP_MAX_CONE_EDGEGRASP_DIAMETER) &&
01631 (bottomRadius >= GP_MIN_CONE_EDGEGRASP_DIAMETER) &&
01632 (height >= GP_MIN_CONE_EDGEGRASP_HEIGHT))
01633 retList.push_back(pg);
01634 else delete pg;
01635
01636
01637 pg = new plannedGrasp((*it)->get_graspDirection());
01638 pg->set_preshape(comp_preshape);
01639 ffd = cartesian_coordinates((*it)->get_graspDirection().get_dir() * ffd);
01640 pg->set_fixedFingerDirection(ffd);
01641 if (height <= GP_MAX_CONE_EDGEGRASP_HEIGHT)
01642 retList.push_back(pg);
01643 else delete pg;
01644 }
01645 }
01646
01647
01648 }
01649
01650
01651 for (it=graspList.begin(); it!=graspList.end(); it++){
01652 delete (*it);
01653 }
01654 graspList.clear();
01655
01656 graspList = retList;
01657
01658 return;
01659 }
01660
01664 int
01665 grasp_planner::get_parameterMode(){
01666 return parameterMode;
01667 }
01668
01672 bool
01673 grasp_planner::set_parameterMode(int in){
01674 if (in >= 0){
01675 parameterMode = in;
01676 return true;
01677 }
01678 return false;
01679 }
01680