Page 1 of 1

energy spent for joint motor, difficulty 2.73 --> 2.74

Posted: Sun May 17, 2009 5:38 pm
by acx01b
Hi,

I would like to know how to get the total energy applied by motors to each hinge joint of my simulation,
I can get it like that in bullet 2.73 :

Code: Select all

// before the Step :
for (int = 0; i < nb_joint; i++)
{
   joint[i]->motorImpulseInThatStep = 0;
}

// modification of btHingeConstraint::solveConstraintObsolete
void	btHingeConstraint::solveConstraintObsolete(btSolverBody& bodyA,btSolverBody& bodyB,btScalar	timeStep)
{
        ....
    if (m_enableAngularMotor)
    {
        clippedMotorImpulse = ... ;
        motorImpulseInThatStep += clippedMotorImpulse;
    }
}

// after the Step
for (int = 0; i < nb_joint; i++)
{
    float imp = joint[i]->motorImpulseInThatStep;
    totalEnergy += imp*imp;
}
thanks

Re: energy spent for joint motor, difficulty 2.73 --> 2.74

Posted: Mon May 18, 2009 10:05 am
by acx01b
I find what value I had to sum / save to get total energy applied to hinge joints :

Code: Select all

btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlyIterations(...)
{
    float totalEnergy = 0;
    for ( iteration = 0;iteration<infoGlobal.m_numIterations;iteration++)
    {
         ....
         ///solve all joint constraints, using SIMD, if available
         for (j=0;j<m_tmpSolverNonContactConstraintPool.size();j++)
         {
             btSolverConstraint& constraint = m_tmpSolverNonContactConstraintPool[j];
             resolveSingleConstraintRowGenericSIMD(m_tmpSolverBodyPool[constraint.m_solverBodyIdA],m_tmpSolverBodyPool[constraint.m_solverBodyIdB],constraint);
         }
         ...
    }
    
    // at the end :
    // sum (squared) the appliedimpulse field of the 6th "row" (btSolverConstraint struct for limit and motor calculation) of each hinge joint 
    for (j=0;j<m_tmpSolverNonContactConstraintPool.size();j++)
    {
        if (j is the 6th row of a hingeJoint)
        {
            float imp = m_tmpSolverNonContactConstraintPool[i].m_appliedImpulse;
            totalEnergyOfTheStep += imp*imp;
        }
    }
}
but I don't know how to code that : if (j is the 6th row of a hingeJoint)

thank you for help and confirmation

Re: energy spent for joint motor, difficulty 2.73 --> 2.74

Posted: Mon May 18, 2009 10:27 am
by DannyChapman
Can't help with the Bullet-specific stuff, but

Units of impulse = mass * distance / time

Units of energy = mass * distance^2 / time^2

so your calculation (energy = impulse * impulse) must be wrong anyway...

Re: energy spent for joint motor, difficulty 2.73 --> 2.74

Posted: Mon May 18, 2009 11:12 am
by acx01b
yes, I agree with you but here I consider 1/ timeStep^2 as a constant

Re: energy spent for joint motor, difficulty 2.73 --> 2.74

Posted: Mon May 18, 2009 5:02 pm
by Dirk Gregorius
But you still have the (effective) mass^2 in you energy equation.

Why do you want the enery? Would't be the applied impulse sufficient?

Re: energy spent for joint motor, difficulty 2.73 --> 2.74

Posted: Tue May 19, 2009 12:27 pm
by acx01b
I need it as quality criterion for evolutionary algorithm

yes you are right, I am going to use "the sum of impulse" instead of "the sum of impulse^2"

so my problem is still there : how to get efficiently after each step the sum of [hingeJoint 6th row].appliedImpulse ?

tks