robot simulation parameter : num_iteration & timeStep

acx01b
Posts: 10
Joined: Thu Jan 15, 2009 12:42 pm

robot simulation parameter : num_iteration & timeStep

Post by acx01b »

Hello,

I made a very simple simulation of a robot (a dog) with 14 hinge joints,
each body is a cube, except the foots that are spheres (for the collision with the floor), the floor is a cube

I found that to get joints' error smaller ( < 0.001 radian) I had to set timeStep = 0.001, and the solver.num_iteration >= 50

the problem is that the simulation is quite slow (9 times the real rate, witch is not enough to perform a great number of simulation for genetic algorithm)

the joints are set to a specific angle like that :

Code: Select all

void SetJointToSpecificAngle(float desiredAngle, float maxVelocity, btHingeConstraint * joint, float timeStep)
{
        
        float velocity;
        float currentAngle = joint->getHingeAngle();
        float angError = desiredAngle - currentAngle;

        if (angError > 0) velocity = maxVelocity;
        else velocity = -maxVelocity;

        if (fabs(angError) <= maxVelocity * timeStep)
        {
            velocity *= fabs(angError)/(maxVelocity * timeStep);
        }
        // joint->setLimit(1,0);  <=> No Limit !

        joint->enableAngularMotor(true,velocity,100);  // 100 : max impulse
}
this is called every internal SubStep (very parameter timeStep = 0.001)

thanks
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: robot simulation parameter : num_iteration & timeStep

Post by Erwin Coumans »

  • What is the CPU speed, operating system and build system, you are using?
  • It is an optimized (release) build?
  • Did you disable collision detection between linked bodies, by passing 'false' as second argument in addConstraint?
Can you share the performance profiling output, using

Code: Select all

#include "LinearMath/btQuickprof.h"
[...]
float internalFixedStep = 0.001f;
dynamicsWorld->stepSimulation(internalFixedStep,0);
CProfileManager::dumpAll();
Thanks,
Erwin
acx01b
Posts: 10
Joined: Thu Jan 15, 2009 12:42 pm

Re: robot simulation parameter : num_iteration & timeStep

Post by acx01b »

thank you to have answered,

I have : core2 duo T5xxx, windows vista, bullet 2.74, release -O2, collision disabled between linked bodies

and the log I get :
Profiling: Root (total running time: 1251.426 ms) ---
0 -- internalSingleStepSimulation (0.08 %) :: 1.#IO ms / frame (1 calls)
Unaccounted: (99.920 %) :: 1250.419 ms
...----------------------------------
...Profiling: internalSingleStepSimulation (total running time: 1.007 ms) ---
...0 -- updateActivationState (0.50 %) :: 1.#IO ms / frame (1 calls)
...1 -- updateCharacters (0.10 %) :: 1.#IO ms / frame (1 calls)
...2 -- updateVehicles (0.20 %) :: 1.#IO ms / frame (1 calls)
...3 -- integrateTransforms (2.09 %) :: 1.#IO ms / frame (1 calls)
...4 -- solveConstraints (76.66 %) :: 1.#IO ms / frame (1 calls)
...5 -- calculateSimulationIslands (0.50 %) :: 1.#IO ms / frame (1 calls)
...6 -- performDiscreteCollisionDetection (15.39 %) :: 1.#IO ms / frame (1 calls)
...7 -- predictUnconstraintMotion (1.49 %) :: 1.#IO ms / frame (1 calls)
...Unaccounted: (3.078 %) :: 0.031 ms
......----------------------------------
......Profiling: solveConstraints (total running time: 0.772 ms) ---
......0 -- processIslands (96.76 %) :: 1.#IO ms / frame (1 calls)
......1 -- islandUnionFindAndQuickSort (0.78 %) :: 1.#IO ms / frame (1 calls)
......Unaccounted: (2.461 %) :: 0.019 ms
.........----------------------------------
.........Profiling: processIslands (total running time: 0.747 ms) ---
.........0 -- solveGroup (95.58 %) :: 1.#IO ms / frame (1 calls)
.........Unaccounted: (4.418 %) :: 0.033 ms
............----------------------------------
............Profiling: solveGroup (total running time: 0.714 ms) ---
............0 -- solveGroupCacheFriendlyIterations (88.38 %) :: 1.#IO ms / frame (1 calls)
............1 -- solveGroupCacheFriendlySetup (9.94 %) :: 1.#IO ms / frame (1 calls)
............Unaccounted: (1.681 %) :: 0.012 ms
......----------------------------------
......Profiling: performDiscreteCollisionDetection (total running time: 0.155 ms) ---
......0 -- dispatchAllCollisionPairs (47.10 %) :: 1.#IO ms / frame (1 calls)
......1 -- calculateOverlappingPairs (2.58 %) :: 1.#IO ms / frame (1 calls)
......2 -- updateAabbs (45.81 %) :: 1.#IO ms / frame (1 calls)
......Unaccounted: (4.516 %) :: 0.007 ms
I looked to my program again and I found that the simulation is 2 times the real rate (5 simulated seconds in 2 real seconds) when I disable all the graphic and event part
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: robot simulation parameter : num_iteration & timeStep

Post by Erwin Coumans »

It seems a huge amount of time (1250 ms) is spend outside of the simulation.

The timings are unreadable for some reason.

Can you edit the file Bullet/src/LinearMath/btQuickProf.cpp, and replace this line:

Code: Select all

 printf("%d -- %s (%.2f %%) :: %.3f ms / frame (%d calls)\n",i, profileIterator->Get_Current_Name(), fraction,(current_total_time / (double)frames_since_reset),profileIterator->Get_Current_Total_Calls());
removing the /(double)frames_since_reset, so it looks like:

Code: Select all

 printf("%d -- %s (%.2f %%) :: %.3f ms / frame (%d calls)\n",i, profileIterator->Get_Current_Name(), fraction,(current_total_time),profileIterator->Get_Current_Total_Calls());
And run the profiling again? If this is the very first frame, the timings might be distorted due to initialization. Can you run the timings for a few frames?

What arguments are you passing into 'stepSimulation'?
Thanks,
Erwin