Example #1
0
void reset(){
	defineStateNoTime(tripodA, verticalSup, lowPos);
	defineStateNoTime(tripodA, verticalInf, lowPos);
	defineStateNoTime(tripodA, horizontal, centerPos);
	defineStateNoTime(tripodB, verticalSup, lowPos);
	defineStateNoTime(tripodB, verticalInf, lowPos);
	defineStateNoTime(tripodB, horizontal, centerPos);
	moveIt();
}
void SpyMini::stop(){
	setMsg(STOP);
	moveIt();
}
void SpyMini::turnRigt(){
	setMsg(TURNRIGHT);
	moveIt();
}
void SpyMini::turnLeft(){
	setMsg(TURNLEFT);
	moveIt();
}
void SpyMini::backward(){
	setMsg(BACKWARD);
	moveIt();

}
void SpyMini::forward(){
	setMsg(FORWARD);
	moveIt();
}
/*!
  This is the main testing function.  It is called whenever the user is idle,
  and it tests the next grasp in the graspList.  It follows the testing
  process defined above.  When the last grasp is reached, the hand is
  returned to its position before the testing began, the graspList is sorted
  in quality order, and the testingComplete signal is emitted.
*/
void
grasp_tester::testIt()
{
  bool do_iteration;
  bool do_save;

  /* Show status bar */
#ifdef GRASPITDBG
  std::cout << "PL_OUT: Testing grasp no " << actualGraspNr++ << " out of " <<
            nrOfGrasps << std::endl;
#endif

  /* Loop over all planned grasps to test them */
  if (it_gr != (*graspList).end()) {

    do_iteration = false;
    do_save = false;

    /* Update visualization */
#ifdef GRASPITDBG
    std::cout << "PL_OUT: vor change color" << std::endl;
#endif

    (*it_gr)->get_graspRepresentation()->changeColor(1., 0., 0.);
    if (render) {
      myViewer->render();
      projectionViewer->render(); // this doesn't work!!!!!!
    }

#ifdef GRASPITDBG
    std::cout << "PL_OUT: Put hand in position" << std::endl;
#endif

    /* First, put hand to starting point outside the object */
    if (putIt(*it_gr, render) == SUCCESS) {

#ifdef GRASPITDBG
      std::cout << "PL_OUT: set preshape" << std::endl;
#endif

      /* Use given preshape */
      preshapeIt((*it_gr)->get_preshape(), render);

#ifdef GRASPITDBG
      std::cout << "PL_OUT: test for collisions" << std::endl;
#endif

      /* check if hand collides already with any obstacle (like the table) */
      if (!handCollision()) {

#ifdef GRASPITDBG
        std::cout << "PL_OUT: move hand towards object" << std::endl;
#endif

        /* Now, move the hand in the specified direction */
        if (moveIt((*it_gr)->get_graspDirection(), render)) {

#ifdef GRASPITDBG
          std::cout << "PL_OUT: check contacts" << std::endl;
#endif
          /* Check if contact exists between hand and the right object */
          if (checkContactToHand((*it_gr)->get_graspableBody())) {

            /* Then close the fingers */
            my_hand->autoGrasp(render, 1);
            //  my_world->findAllContacts();
            my_world->updateGrasps();
            //  if (render) myViewer->render();


            /* Evaluate grasp */
            (*it_gr)->set_quality(my_grasp->getQM(whichQM)->evaluate());
#ifdef GRASPITDBG
            std::cout << "PL_OUT: !!!! whichQM: " << whichQM << " quality: " << (*it_gr)->get_quality() << std::endl;
#endif
            if (saveToFile) { saveGrasp((*it_gr)->get_quality()); }
            /* save final position to grasp class */
            if ((*it_gr)->get_quality() > QUALITY_MIN_THRESHOLD && (*it_gr)->get_quality() <= 1.0) {
              do_save = true;
            }
          }
          else {
            do_iteration = true;
          }

          /* iteration if:
             - grasp not stable
             - wrong contacts */
          if (do_iteration ||
              ((*it_gr)->get_quality() <= QUALITY_MIN_THRESHOLD)) {

            if (iteration(**it_gr)) {
              /* save final position to grasp class */
              do_save = true;
            }
          }
        }

#ifdef GRASPITDBG
        else { std::cout << "PL_OUT: MoveIt failed." << std::endl; }
#endif

      }
    }

#ifdef GRASPITDBG
    else {
      std::cout << "PL_OUT: putIt failed. Stepping to next grasp." << std::endl;
    }
#endif

    if (do_save) {

      /* change radius in vis window according to quality */
      (*it_gr)->get_graspRepresentation()->changeRadius((*it_gr)->get_quality());

      /* save final position to grasp class */
      savePosition(**it_gr);
    }
    else {
      (*it_gr)->remove_graspRepresentation();
    }

    /* reset color */
    //(*it_gr)->get_graspRepresentation()->resetColor();

    /* increment iterator for next step */
    if (it_gr != (*graspList).end()) {
      it_gr++;
    }
  }


  /* last grasp reached */
  else {

#ifdef GRASPITDBG
    std::cout << "PL_OUT: Last grasp reached" << std::endl;
#endif

    /* Order List and remove bad grasps */
    orderGraspListByQuality(*graspList);
    if (saveToFile) {graspFile.close(); saveToFile = false;}

    /* we are ready; kill idleSensor */
    if (idleSensor != NULL) {
      delete idleSensor;
    }
    idleSensor = NULL;

    if (render) {
      /* put the hand back to starting position */
      my_hand->setTran(origTran);
      my_hand->forceDOFVals(dofs);
    }

    PROF_STOP_TIMER(TOTAL_PLANNER);
    PROF_PRINT_ALL;
    Q_EMIT testingComplete();

  }
  if (idleSensor != NULL) {
    idleSensor->schedule();
  }

  if (!render) {
    /* put the hand back to starting position */
    my_hand->setTran(origTran);
    my_hand->forceDOFVals(dofs);
  }
}
Example #8
0
void setState(int tripodAState, int tripodBState){
	int not_a = 0, not_b = 0;
	//Define Tripod A State

	if(tripodAState == lowCenter){
		defineState(tripodA, verticalSup, lowPos);
		defineState(tripodA, verticalInf, lowPos);
		defineState(tripodA, horizontal, centerPos);
	} else if(tripodAState == highCenter){
		defineState(tripodA, verticalSup, highPos);
		defineState(tripodA, verticalInf, highPos);
		defineState(tripodA, horizontal, centerPos);
	} else if(tripodAState == lowRight){
		defineState(tripodA, verticalSup, lowPos);
		defineState(tripodA, verticalInf, lowPos);
		defineState(tripodA, horizontal, rightPos);
	} else if(tripodAState == lowLeft){
		defineState(tripodA, verticalSup, lowPos);
		defineState(tripodA, verticalInf, lowPos);
		defineState(tripodA, horizontal, leftPos);
	}  else if(tripodAState == lowFront){
		defineState(tripodA, verticalSup, frontPos);
		defineState(tripodA, verticalInf, frontPos);
		defineState(tripodA, horizontal, frontPos);
	}  else if(tripodAState == lowBack){
		defineState(tripodA, verticalSup, backPos);
		defineState(tripodA, verticalInf, backPos);
		defineState(tripodA, horizontal, backPos);
	} else not_a = 1;

	// Define Tripod B State

	if(tripodBState == lowCenter){
		defineState(tripodB, verticalSup, lowPos);
		defineState(tripodB, verticalInf, lowPos);
		defineState(tripodB, horizontal, centerPos);
	} else if(tripodBState == highCenter){
		defineState(tripodB, verticalSup, highPos);
		defineState(tripodB, verticalInf, highPos);
		defineState(tripodB, horizontal, centerPos);
	} else if(tripodBState == lowRight){
		defineState(tripodB, verticalSup, lowPos);
		defineState(tripodB, verticalInf, lowPos);
		defineState(tripodB, horizontal, rightPos);
	} else if(tripodBState == lowLeft){
		defineState(tripodB, verticalSup, lowPos);
		defineState(tripodB, verticalInf, lowPos);
		defineState(tripodB, horizontal, leftPos);
	}  else if(tripodBState == lowFront){
		defineState(tripodB, verticalSup, frontPos);
		defineState(tripodB, verticalInf, frontPos);
		defineState(tripodB, horizontal, frontPos);
	}  else if(tripodBState == lowBack){
		defineState(tripodB, verticalSup, backPos);
		defineState(tripodB, verticalInf, backPos);
		defineState(tripodB, horizontal, backPos);
	} else not_b = 1;

	if(!(not_a && not_b))
		moveIt();
}
Example #9
0
void setLowPos(){
	defineState(tripodA, verticalSup, lowPos);
	defineState(tripodB, verticalSup, lowPos);
	moveIt();
}