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
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
00073
00074 float dist = height - fmat::dotProduct(tgt,groundNormal);
00075
00076
00077
00078
00079 float align = fmat::dotProduct(gravity,groundNormal);
00080 if(align<EPSILON && align>-EPSILON)
00081 align = (align>=0) ? EPSILON : -EPSILON;
00082
00083 tgt += gravity * (dist/align);
00084
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)
00097 gravity=ground/ground.norm();
00098 else
00099 gravity/=g;
00100 }
00101
00102
00103
00104
00105
00106
00107 #endif // TGT_HAS_LEGS