Skip to content

Commit

Permalink
more zmp
Browse files Browse the repository at this point in the history
  • Loading branch information
Julio Jerez committed Dec 14, 2023
1 parent 7272946 commit ec8f5fb
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions newton-4.00/applications/ndSandbox/demos/ndQuadrupedTest_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1649,11 +1649,13 @@ namespace ndQuadruped_1
}


ndVector CalculateZeroMomentPoint(const ndVector& centerOfPresure) const
ndVector CalculateZeroMomentPoint() const
{
ndFixSizeArray<ndVector, 32> r;
ndFixSizeArray<const ndBodyKinematic*, 32> bodies;

//ndVector centerOfPresure;

ndVector com(ndVector::m_zero);
ndFloat32 totalMass = ndFloat32(0.0f);
for (ndModelArticulation::ndNode* node = GetRoot()->GetFirstIterator(); node; node = node->GetNextIterator())
Expand Down Expand Up @@ -1682,7 +1684,7 @@ namespace ndQuadruped_1
//const ndVector centerOfMass (matrix.TransformVector(body->GetCentreOfMass()));

//const ndVector& centerOfMass = r[i];
const ndVector& centerOfMass = r[i] - com;
const ndVector centerOfMass (r[i] - com);
const ndMatrix bodyInertia(body->CalculateInertiaMatrix());
const ndVector bodyForce((body->GetAccel() - gravity).Scale (body->GetMassMatrix().m_w));

Expand All @@ -1691,7 +1693,8 @@ namespace ndQuadruped_1
torque += bodyInertia.RotateVector(body->GetAlpha());
}

return centerOfPresure;
//return centerOfPresure;
return com;
}

void Debug(ndConstraintDebugCallback& context) const
Expand Down Expand Up @@ -1848,8 +1851,13 @@ namespace ndQuadruped_1
context.DrawPoint(centerOfPresure, ndVector(0.0f, 1.0f, 0.0f, 1.0f), 5);
//context.DrawPoint(ndVector(p1Out), ndVector(0.0f, 1.0f, 0.0f, 1.0f), 3);

ndVector zmp(CalculateZeroMomentPoint(centerOfPresure));
context.DrawPoint(zmp, ndVector(1.0f, 0.0f, 0.0f, 1.0f), 5);
ndVector zmp(CalculateZeroMomentPoint());
ray_p0 = zmp;
ray_p1 = zmp;
ray_p1.m_y -= ndFloat32(0.5f);
ndRayToPolygonDistance(ray_p0, ray_p1, bigPolygon, supportCount, p0Out, p1Out);
const ndVector zmpSupport(p0Out);
context.DrawPoint(zmpSupport, ndVector(1.0f, 0.0f, 0.0f, 1.0f), 5);
}
else if (desiredSupportPoint.GetCount() == 2)
{
Expand Down

0 comments on commit ec8f5fb

Please sign in to comment.