Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

XWalkParameters.cc

Go to the documentation of this file.
00001 #include "Shared/RobotInfo.h"
00002 #if defined(TGT_HAS_LEGS) && !defined(TGT_IS_AIBO)
00003 
00004 #include "XWalkParameters.h"
00005 #include "Motion/Kinematics.h"
00006 
00007 using namespace std; 
00008 
00009 const float XWalkParameters::EPSILON=1e-5f;
00010 
00011 float XWalkParameters::getMaxXVel() const {
00012   return strideLenX/minPeriod();
00013 }
00014 float XWalkParameters::getMaxYVel() const {
00015   return strideLenY/minPeriod();
00016 }
00017 float XWalkParameters::getMaxAVel() const {
00018   float maxStride=0;
00019   for(unsigned int leg=0; leg<NumLegs; ++leg) {
00020     fmat::Column<2> neutralPos = computeNeutralPos(leg);
00021     float radius = (neutralPos-fmat::pack(offsetX,offsetY)).norm();
00022     float hyp = neutralPos.norm();
00023     float len = (neutralPos[1]*strideLenX + neutralPos[0]*strideLenY)/hyp;
00024     float strideA = std::abs(len)/radius;
00025     if(strideA>maxStride)
00026       maxStride=strideA;
00027   }
00028   return maxStride/minPeriod();
00029 }
00030 
00031 float XWalkParameters::nominalPeriod() const {
00032   std::map<float,float> phases;
00033   for(unsigned int leg=0; leg<NumLegs; ++leg) {
00034     float t = legParams[leg].totalDuration() * 2 / 1000.f;
00035     if(t>phases[legParams[leg].flightPhase])
00036       phases[legParams[leg].flightPhase] = t;
00037   }
00038   float ph = 0;
00039   for(std::map<float,float>::iterator it=phases.begin(); it!=phases.end(); ++it)
00040     ph+=it->second;
00041   return ph;
00042 }
00043 
00044 float XWalkParameters::minPeriod() const {
00045   std::map<float,float> phases;
00046   for(unsigned int leg=0; leg<NumLegs; ++leg) {
00047     float t = (legParams[leg].flightDuration+legParams[leg].raiseDuration/2+legParams[leg].lowerDuration/2)/1000.f;
00048     if(t>phases[legParams[leg].flightPhase])
00049       phases[legParams[leg].flightPhase] = t;
00050   }
00051   float ph = 0;
00052   for(std::map<float,float>::iterator it=phases.begin(); it!=phases.end(); ++it)
00053     ph+=it->second;
00054   return ph;
00055 }
00056 
00057 fmat::Column<2> XWalkParameters::computeNeutralPos(unsigned int leg) const {
00058   LegParameters& legParam = legParams[leg];
00059   const KinematicJoint * legRoot = kine->getKinematicJoint(LegOffset+JointsPerLeg*leg);
00060   fmat::Column<3> fstPos = legRoot->getWorldPosition();
00061   fmat::Column<2> ans;
00062   ans[0] = fstPos[0] + legParam.strideBias;
00063   ans[1] = ((fstPos[1]<0) ? -*legParam.stanceWidth : *legParam.stanceWidth);
00064   return ans;
00065 } 
00066 
00067 void XWalkParameters::projectToGround(const fmat::Column<3>& groundNormal, float height, const fmat::Column<3>& gravity, fmat::Column<3>& tgt) {
00068   // find distance from target point to plane, so we can restate ground plane as if tgt is the origin
00069   //std::cout << "Pre-project: " << tgt << std::endl;
00070   float dist = height - fmat::dotProduct(tgt,groundNormal);
00071   // now treat tgt as the origin, to be projected along gravity vector to ground plane (specified by: ground · x = dist)
00072   // ( gravity * t ) · ground = dist, solve for t to get gravity*t to get intersection point
00073   /* intersect = gravity * t
00074    *  intersect = gravity * ( dist / (gravity · groundNormal) )  */
00075   float align = fmat::dotProduct(gravity,groundNormal);
00076   if(align<EPSILON && align>-EPSILON) // we're trying to walk up a perfectly vertical cliff...
00077     align = (align>=0) ? EPSILON : -EPSILON; //pretend it's near vertical
00078   //std::cout << dist << ' ' << align << ' ' << gravity << std::endl;
00079   tgt += gravity * (dist/align); // add this origin projected to ground plane back to original target point to be in body frame
00080   //std::cout << "Post-project: " << tgt << std::endl;
00081 }
00082 
00083 void XWalkParameters::packGroundGravity(const fmat::SubVector<3>& ground, const fmat::SubVector<3> gravity) const {
00084   ground[0]=groundPlane[0];
00085   ground[1]=groundPlane[1];
00086   ground[2]=groundPlane[2];
00087   gravity[0]=groundPlane[0] + gravityVector[0];
00088   gravity[1]=groundPlane[1] + gravityVector[1];
00089   gravity[2]=groundPlane[2] + gravityVector[2];
00090   
00091   float g = gravity.norm();
00092   if(g==0) // invalid gravity vector, doesn't point anywhere
00093     gravity=ground/ground.norm(); // assume it points into ground...
00094   else
00095     gravity/=g;
00096 }
00097 
00098 /*! @file
00099  * @brief Implements XWalkParameters, which provide configuration settings for XWalkMC
00100  * @author Ethan Tira-Thompson (ejt) (Creator)
00101  */
00102 
00103 #endif // TGT_HAS_LEGS

Tekkotsu v5.1CVS
Generated Fri Mar 16 05:26:55 2012 by Doxygen 1.6.3