box2d for mechanical Engineers

Post about the Flash World Construction Kit and the Alchemy port of Box2D.
cmgautomation
Posts: 3
Joined: Sat Jun 29, 2013 11:19 pm

box2d for mechanical Engineers

Postby cmgautomation » Sat Jun 29, 2013 11:48 pm

Hi
I'm trying to use box2d (porting for dellphi) for kinematic and dynamic simulations of linkages, and it looks very powerful and nice to use.
I've to treat linkages smaller then 1 m, with bodies often smaller than 0.05m, and because of the limitation from 0.1 to 10 m, there are very big errors in collision and joint evaluation.
Is there a way for increasing the precision of the calculation for small objects, also accepting a very slow evaluation process?
thanks

irresistible force
Posts: 1991
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo
Contact:

Re: box2d for mechanical Engineers

Postby irresistible force » Sun Jun 30, 2013 4:37 am

You can use a smaller time step, and increase the number of iterations allowed in the solver, but you still might not get what you're hoping for. Keep in mind that Box2D was written for situations requiring fast (typically 60fps) but not necessarily very accurate physics.
To do this you would replace the typical values of 1/60 second for time step, and 8 and 3 for the vel/pos iterations:
world->Step( 1/60.0, 8, 3 );
...with maybe something like:
world->Step( 1/1000.0, 800, 300 );
It will be slow ;)

Reading your post again, I see you're thinking that the scale of things might be the problem. This should not be an issue for joint constraints, but there is a buffer of 0.005 units which is kept between contacting fixtures, which can be a significant distance when you are dealing with fixtures that are only 0.05 to begin with. At this point I would need to ask what kind of errors you're seeing with the collision. If the problem is that fixtures often penetrate a lot before being corrected, that should be alleviated a lot by the smaller time step mentioned above. If you're finding that fixtures which should be pressed exactly against each other actually have a small gap of space between them, that would be due to the buffer. The buffer size can be changed in b2Settings.h (b2_linearSlop) and there are a bunch of other things to tweak in there that you might find interesting. You could also try scaling up the world so that distances given to Box2D are larger.

cmgautomation
Posts: 3
Joined: Sat Jun 29, 2013 11:19 pm

Re: box2d for mechanical Engineers

Postby cmgautomation » Mon Jul 01, 2013 2:22 pm

thanks for your help,
probably the scale is the problem, because I'm looking for precisions <=0.001 mm.
I've tried to set
b2_linearSlop = 0.00001;
Now parts, when they stops, are in contact. Looks OK!
A big problem is that with such small parts, the joints are very loose and parts compenetrate very much. (and or me 2 mm are very much!)
for trying to have a compenetration less than 0.001 mm between parts and joints, I've tried to sett:
m_world.step(1/10000,800,300);
the animation is fast enough for my purpose, but do not change very much for compenetration;
also with m_world.step(1/100000,8000,3000); is the same.
I've tried to modify some parameters in b2Settings.h, but nothing changes!
Do you know which parameters I've to modify for reducing the compenetration at less then 0.001 mm?
thanks

irresistible force
Posts: 1991
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo
Contact:

Re: box2d for mechanical Engineers

Postby irresistible force » Mon Jul 01, 2013 10:46 pm

To help avoid compenetration you could set dynamic bodies to be bullet types.
I'm surprised that penetration would not change much with a 1/10000 step length, because the bodies will only be able to move for 0.0001 seconds before being corrected. Do you have light bodies being sandwiched/joined between heavier bodies?
In the real world, a large steel block can be placed on top of a very small block of the same density with no penetration and reach a stable equilibrium, but this is a notoriously hard thing for Box2D to do.
If that is a requirement, I have a feeling that this is not the physics engine you are looking for.

cmgautomation
Posts: 3
Joined: Sat Jun 29, 2013 11:19 pm

Re: box2d for mechanical Engineers

Postby cmgautomation » Tue Jul 02, 2013 1:48 pm

hi
Setting bodies as bullet is much better. Now, looking the animation, the compenetration between bodies seems almost zero. It's OK.
Now the only problem that I can see, is that the joints are loose, and they don't mantain the bodies in the correct position. Is there a way to increase the stiffness of the joints?
thanks for your help
Carlo

irresistible force
Posts: 1991
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo
Contact:

Re: box2d for mechanical Engineers

Postby irresistible force » Tue Jul 02, 2013 1:59 pm

Do you have light bodies being sandwiched/joined between heavier bodies?
The only way a structure of joints will hold together well is when they are in a 'hierarchy' where the central bodies are heavier, and bodies toward the outside are lighter. A good example is a ragdoll - if the torso is 20kg and each limb segment gets successively lighter until the hands are say, 2kg, that will work fine but not the other way around.


Return to “WCK”



Who is online

Users browsing this forum: No registered users and 2 guests