Spring from Prismatic

256 views
Skip to first unread message

indy2005

unread,
Aug 17, 2010, 3:25:10 PM8/17/10
to Mekanimo
Hi,

I am preparing myself to use prismatic joints as a spring effect with
mekanimo output, and have some samples I have seen like this:

-(void) update:(ccTime)dt
{
// Call super, because the base class needs to update it
[super update:dt];

spring1->SetMaxMotorForce( baseSpringForce + (40 * baseSpringForce *
powf(spring1->GetJointTranslation(), 2) ) );
spring1->SetMotorSpeed( -20 * spring1->GetJointTranslation() );

spring2->SetMaxMotorForce( baseSpringForce + (40 * baseSpringForce *
powf(spring2->GetJointTranslation(), 2) ) );
spring2->SetMotorSpeed( -20 * spring2->GetJointTranslation() );
}


where the baseSpringForce is calculated as 5 times the mass of the car
(these springs are axels on a sideways viewed car). How does this
work? What physics principle is this solution using (Hookes Law), and
what are the constants in here (40, -20) etc.

Any help appreciated...I assume that this is a similar method you
could uses as a compatibility mode for a pure Box2D implementation of
a spring?

Regards

i

Fahri

unread,
Aug 17, 2010, 9:39:18 PM8/17/10
to Mekanimo
Hi,

Box2D forum has a discussion about this at
http://www.box2d.org/forum/viewtopic.php?f=3&t=1056&hilit=spring+stiffness

Also, Box2D documentation says:

"The distance joint can also be made soft, like a spring-damper
connection. See the Web example in the testbed to see how this
behaves.

Softness is achieved by tuning two constants in the definition:
frequency and damping ratio. Think of the frequency as the frequency
of a harmonic oscillator (like a guitar string). The frequency is
specified in Hertz. Typically the frequency should be less than a half
the frequency of the time step. So if you are using a 60Hz time step,
the frequency of the distance joint should be less than 30Hz. The
reason is related to the Nyquist frequency.

The damping ratio is non-dimensional and is typically between 0 and 1,
but can be larger. At 1, the damping is critical (all oscillations
should vanish)."

Maybe you can ask this question at box2D forum and they may be able to
answer it.

Regards,

Fahri

indy2005

unread,
Aug 18, 2010, 5:21:19 AM8/18/10
to Mekanimo
in fact the "Web" Box2D sample simply uses

jd.frequencyHz = 4.0f;
jd.dampingRatio = 0.5f;

on all of its distance joints, so why the elaborate code? Is it
because they have chosen to use Prismatic joints to keep the rotation
fixed, and this achieves a similar effect to these properties?

Regards

i



On Aug 18, 2:39 am, Fahri <mangab...@gmail.com> wrote:
> Hi,
>
> Box2D forum has a discussion about this athttp://www.box2d.org/forum/viewtopic.php?f=3&t=1056&hilit=spring+stif...

indy2005

unread,
Aug 18, 2010, 5:17:09 AM8/18/10
to Mekanimo
THanks Fahri,

I will ask at Box2D. This is a prismatic joint rather than distance
joint, but I got the impression from reading about the damping and
frequency - that they are just properties could simply in, whereas
this code seems to represent an algorithm.

Regards

i



On Aug 18, 2:39 am, Fahri <mangab...@gmail.com> wrote:
> Hi,
>
> Box2D forum has a discussion about this athttp://www.box2d.org/forum/viewtopic.php?f=3&t=1056&hilit=spring+stif...
Reply all
Reply to author
Forward
0 new messages