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     // hack! fix it later
00060         #if defined(TGT_IS_MANTIS)
00061         static const int JointsPerLeg = 4;
00062         #endif
00063     const KinematicJoint * legRoot = kine->getKinematicJoint(LegOffset+JointsPerLeg*leg);
00064   fmat::Column<3> fstPos = legRoot->getWorldPosition();
00065   fmat::Column<2> ans;
00066   ans[0] = fstPos[0] + legParam.strideBias;
00067   ans[1] = ((fstPos[1]<0) ? -*legParam.stanceWidth : *legParam.stanceWidth);
00068   return ans;
00069 } 
00070 
00071 void XWalkParameters::projectToGround(const fmat::Column<3>& groundNormal, float height, const fmat::Column<3>& gravity, fmat::Column<3>& tgt) {
00072   // find distance from target point to plane, so we can restate ground plane as if tgt is the origin
00073   //std::cout << "Pre-project: " << tgt << std::endl;
00074   float dist = height - fmat::dotProduct(tgt,groundNormal);
00075   // now treat tgt as the origin, to be projected along gravity vector to ground plane (specified by: ground · x = dist)
00076   // ( gravity * t ) · ground = dist, solve for t to get gravity*t to get intersection point
00077   /* intersect = gravity * t
00078    *  intersect = gravity * ( dist / (gravity · groundNormal) )  */
00079   float align = fmat::dotProduct(gravity,groundNormal);
00080   if(align<EPSILON && align>-EPSILON) // we're trying to walk up a perfectly vertical cliff...
00081     align = (align>=0) ? EPSILON : -EPSILON; //pretend it's near vertical
00082   //std::cout << dist << ' ' << align << ' ' << gravity << std::endl;
00083   tgt += gravity * (dist/align); // add this origin projected to ground plane back to original target point to be in body frame
00084   //std::cout << "Post-project: " << tgt << std::endl;
00085 }
00086 
00087 void XWalkParameters::packGroundGravity(const fmat::SubVector<3>& ground, const fmat::SubVector<3> gravity) const {
00088   ground[0]=groundPlane[0];
00089   ground[1]=groundPlane[1];
00090   ground[2]=groundPlane[2];
00091   gravity[0]=groundPlane[0] + gravityVector[0];
00092   gravity[1]=groundPlane[1] + gravityVector[1];
00093   gravity[2]=groundPlane[2] + gravityVector[2];
00094   
00095   float g = gravity.norm();
00096   if(g==0) // invalid gravity vector, doesn't point anywhere
00097     gravity=ground/ground.norm(); // assume it points into ground...
00098   else
00099     gravity/=g;
00100 }
00101 
00102 /*! @file
00103  * @brief Implements XWalkParameters, which provide configuration settings for XWalkMC
00104  * @author Ethan Tira-Thompson (ejt) (Creator)
00105  */
00106 
00107 #endif // TGT_HAS_LEGS

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:53 2016 by Doxygen 1.6.3