void ForwardDynamicsABM::calcMotionWithEulerMethod() { calcABMLastHalf(); if(!sensorHelper.forceSensors().empty()){ updateForceSensors(); } DyLink* root = body->rootLink(); if(!root->isFixedJoint()){ root->dv() = root->dvo() - root->p().cross(root->dw()) + root->w().cross(root->vo() + root->w().cross(root->p())); Position T; SE3exp(T, root->T(), root->w(), root->vo(), timeStep); root->T() = T; root->vo() += root->dvo() * timeStep; root->w() += root->dw() * timeStep; } int n = body->numLinks(); for(int i=1; i < n; ++i){ DyLink* link = body->link(i); link->q() += link->dq() * timeStep; link->dq() += link->ddq() * timeStep; } }
void ForwardDynamicsABM::calcMotionWithRungeKuttaMethod() { DyLink* root = body->rootLink(); if(!root->isFixedJoint()){ T0 = root->T(); vo0 = root->vo(); w0 = root->w(); } vo.setZero(); w.setZero(); dvo.setZero(); dw.setZero(); int n = body->numLinks(); for(int i=1; i < n; ++i){ DyLink* link = body->link(i); q0[i] = link->q(); dq0[i] = link->dq(); dq[i] = 0.0; ddq[i] = 0.0; } calcABMLastHalf(); if(!sensorHelper.forceSensors().empty()){ updateForceSensors(); } integrateRungeKuttaOneStep(1.0 / 6.0, timeStep / 2.0); calcABMPhase1(); calcABMPhase2(); calcABMPhase3(); integrateRungeKuttaOneStep(2.0 / 6.0, timeStep / 2.0); calcABMPhase1(); calcABMPhase2(); calcABMPhase3(); integrateRungeKuttaOneStep(2.0 / 6.0, timeStep); calcABMPhase1(); calcABMPhase2(); calcABMPhase3(); if(!root->isFixedJoint()){ SE3exp(root->T(), T0, w0, vo0, timeStep); root->vo() = vo0 + (dvo + root->dvo() / 6.0) * timeStep; root->w() = w0 + (dw + root->dw() / 6.0) * timeStep; } for(int i=1; i < n; ++i){ DyLink* link = body->link(i); link->q() = q0[i] + ( dq[i] + link->dq() / 6.0) * timeStep; link->dq() = dq0[i] + (ddq[i] + link->ddq() / 6.0) * timeStep; } }
void ForwardDynamicsABM::integrateRungeKuttaOneStep(double r, double dt) { DyLink* root = body->rootLink(); if(!root->isFixedJoint()){ SE3exp(root->T(), T0, root->w(), root->vo(), dt); root->vo().noalias() = vo0 + root->dvo() * dt; root->w().noalias() = w0 + root->dw() * dt; vo += r * root->vo(); w += r * root->w(); dvo += r * root->dvo(); dw += r * root->dw(); } int n = body->numLinks(); for(int i=1; i < n; ++i){ DyLink* link = body->link(i); link->q() = q0[i] + dt * link->dq(); link->dq() = dq0[i] + dt * link->ddq(); dq[i] += r * link->dq(); ddq[i] += r * link->ddq(); } }