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 "robotiq.h"
00031 #include "world.h"
00032 #include "debug.h"
00033
00034 int RobotIQ::loadFromXml(const TiXmlElement* root,QString rootPath)
00035 {
00036 int result = Robot::loadFromXml(root, rootPath);
00037 if (result != SUCCESS) return result;
00038 myWorld->toggleCollisions(false, base,chainVec[0]->getLink(1));
00039 myWorld->toggleCollisions(false, base,chainVec[1]->getLink(1));
00040 myWorld->toggleCollisions(false, base,chainVec[2]->getLink(1));
00041
00042 return result;
00043 }
00044
00045 void RobotIQ::cloneFrom(Hand *original)
00046 {
00047 Hand::cloneFrom(original);
00048 myWorld->toggleCollisions(false, base,chainVec[0]->getLink(1));
00049 myWorld->toggleCollisions(false, base,chainVec[1]->getLink(1));
00050 myWorld->toggleCollisions(false, base,chainVec[2]->getLink(1));
00051 }
00052
00053 bool
00054 RobotIQ::autoGrasp(bool renderIt, double speedFactor, bool stopAtContact)
00055 {
00056
00057 if (myWorld->dynamicsAreOn()) return Hand::autoGrasp(renderIt, speedFactor, stopAtContact);
00058
00059 if (numDOF != 11) {DBGA("Hard-coded autograsp does not match RobotIQ hand"); return false;}
00060
00061 std::vector<double> desiredVals(11, 0.0);
00062
00063 if (speedFactor < 0)
00064 {
00065 DBGA("Hand opening not yet implemented for RobotIQ hand; forcing it to open pose");
00066 desiredVals[3] = getDOF(3)->getVal();
00067 desiredVals[7] = getDOF(7)->getVal();
00068 forceDOFVals(&desiredVals[0]);
00069 return false;
00070 }
00071
00072 std::vector<double> desiredSteps(11, 0.0);
00073
00074 desiredVals[0] = desiredVals[4] = desiredVals[8] = dofVec[0]->getMax();
00075 desiredVals[2] = desiredVals[6] = desiredVals[10] = dofVec[2]->getMin();
00076
00077 desiredSteps[0] = desiredSteps[4] = desiredSteps[8] = speedFactor*AUTO_GRASP_TIME_STEP;
00078 desiredSteps[2] = desiredSteps[6] = desiredSteps[10] = -speedFactor*AUTO_GRASP_TIME_STEP;
00079
00080 int steps=0;
00081 while(1)
00082 {
00083 bool moved = moveDOFToContacts(&desiredVals[0], &desiredSteps[0], true, renderIt);
00084 std::vector<double> ref;
00085 ref.push_back(0); ref.push_back(4); ref.push_back(8);
00086 std::vector<double> links;
00087 links.push_back(0); links.push_back(1); links.push_back(1);
00088 for(size_t i=0; i<ref.size(); i++)
00089 {
00090 if (getChain(i)->getLink(links[i]+0)->getNumContacts() ||
00091 getChain(i)->getLink(links[i]+1)->getNumContacts() ||
00092 getDOF(ref[i]+0)->getVal() == getDOF(ref[i]+0)->getMax() )
00093 {
00094 desiredVals[ref[i]+0] = getDOF(ref[i]+0)->getVal();
00095 desiredSteps[ref[i]+0] = 0;
00096 if (!getChain(i)->getLink(links[i]+1)->getNumContacts())
00097 {
00098 desiredVals[ref[i]+1] = getDOF(ref[i]+1)->getMax();
00099 desiredSteps[ref[i]+1] = speedFactor*AUTO_GRASP_TIME_STEP;
00100 }
00101 else
00102 {
00103 desiredVals[ref[i]+1] = getDOF(ref[i]+1)->getVal();
00104 desiredSteps[ref[i]+1] = 0;
00105 }
00106 desiredVals[ref[i]+2] = getDOF(ref[i]+2)->getMax();
00107 desiredSteps[ref[i]+2] = speedFactor*AUTO_GRASP_TIME_STEP;
00108 }
00109 }
00110 if (!moved) break;
00111 if (++steps > 1000)
00112 {
00113 DBGA("RobotIQ hard-coded autograsp seems to be looping forever; escaping...");
00114 break;
00115 }
00116 }
00117
00118 return true;
00119 }