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
00030 #include "pr2Gripper.h"
00031 #include "world.h"
00032 #include "collisionInterface.h"
00033 #include "graspitGUI.h"
00034 #include "mainWindow.h"
00035 #include "contact.h"
00036
00037
00038 #include "debug.h"
00039
00040 #define PROF_ENABLED
00041 #include "profiling.h"
00042
00043 PROF_DECLARE(REACTIVE_GRASP_TIMER);
00044
00045 using std::string;
00046
00047 const string Pr2Gripper2010::l_gripper_tip_name = "_chain0_link1";
00048 const string Pr2Gripper2010::r_gripper_tip_name = "_chain1_link1";
00049
00050 int
00051 Pr2Gripper::loadFromXml(const TiXmlElement* root,QString rootPath)
00052 {
00053 int result = Robot::loadFromXml(root, rootPath);
00054 if (result != SUCCESS) return result;
00055 myWorld->toggleCollisions(false, chainVec[0]->getLink(0), chainVec[1]->getLink(0));
00056
00057 return result;
00058 }
00059
00060 void
00061 Pr2Gripper::cloneFrom(Hand *original)
00062 {
00063 Hand::cloneFrom(original);
00064 myWorld->toggleCollisions(false, chainVec[0]->getLink(0), chainVec[1]->getLink(0));
00065 }
00066
00067
00068 void Pr2Gripper2010::setJointValuesAndUpdate(const double* jointVals)
00069 {
00070 if (mCompliance == NONE) {
00071 Robot::setJointValuesAndUpdate(jointVals);
00072 return;
00073 }
00074
00075 transf initial_fingertip_tran = chainVec[mCompliance]->getLink(1)->getTran();
00076 Robot::setJointValuesAndUpdate(jointVals);
00077 transf final_fingertip_tran = chainVec[mCompliance]->getLink(1)->getTran();
00078 transf relative_tran = initial_fingertip_tran * final_fingertip_tran.inverse();
00079 setTran( relative_tran * getTran() );
00080 }
00081
00082 void Pr2Gripper2010::compliantClose()
00083 {
00084
00085 DBGP("Reactive grasp started.");
00086 PROF_TIMER_FUNC(REACTIVE_GRASP_TIMER);
00087
00088
00089 if (!myWorld->noCollision(this)) {
00090 DBGA("Compliant Close error: the hand currently has collisions");
00091 return;
00092 }
00093
00094
00095 autoGrasp(false, 1.0);
00096
00097
00098 ComplianceType compliance;
00099 if ( chainVec[0]->getLink(1)->getNumContacts()) {
00100 if (chainVec[1]->getLink(1)->getNumContacts()) {
00101 DBGA("Reactive grasp: both fingertips are in contact; aborting");
00102 return;
00103 } else {
00104 DBGA("Setting compliance around FINGER0.");
00105 compliance = FINGER0;
00106 }
00107 } else {
00108 if (!chainVec[1]->getLink(1)->getNumContacts()) {
00109 DBGA("Reactive grasp: no fingertips are in contact; aborting");
00110 return;
00111 } else {
00112 DBGA("Setting compliance around FINGER1.");
00113 compliance = FINGER1;
00114 }
00115 }
00116 setCompliance(compliance);
00117
00118
00119
00120 chainVec[compliance]->getLink(1)->breakContacts();
00121 myWorld->toggleCollisions(false, chainVec[compliance]->getLink(1) );
00122
00123
00124 autoGrasp(false, 1.0);
00125
00126 DBGA("Autograsp complete; re-enabling collisions");
00127
00128 myWorld->toggleCollisions(true, chainVec[compliance]->getLink(1) );
00129 myWorld->findContacts(chainVec[compliance]->getLink(1));
00130
00131
00132 setCompliance(NONE);
00133
00134 }
00135