How can I write a joint callback script that will act like a spring damper system?

Typically: "How do I... ", "How can I... " questions
Post Reply
NapsterIsReal
Posts: 4
Joined: 28 Mar 2017, 19:06

How can I write a joint callback script that will act like a spring damper system?

Post by NapsterIsReal »

Hi Everyone,

I am looking into joint callback scripts and I have a prismatic joint attached to 2 body masses. I want this prismatic joint to use the callback script to execute a spring-damper behavior. I know that V-Rep has a spring-damper mode built in but I will need to add other components to the controller once I make sure spring-damper is working.

So if you execute my scene it should give you an expected spring-damper system behavior with two masses. What I want to understand is what the maxVelocity return argument does. Because it is set by P*error value and capped by velocity limits and if I try to change what it is, everything stops working. Can you enlighten me about how that return argument works?

Link to scene:
goo.gl/NRwn96

This is what is running inside the joint control callback:

Code: Select all

maxVelocity=PID_P*errorValue/dynStepSize
if (maxVelocity>velUpperLimit) then
	maxVelocity=velUpperLimit
end
if (maxVelocity<-velUpperLimit) then
	maxVelocity=-velUpperLimit
end

k = 1
forceOrTorqueToApply = k*errorValue/dynStepSize
Thanks in advance!!

NapsterIsReal
Posts: 4
Joined: 28 Mar 2017, 19:06

Re: How can I write a joint callback script that will act like a spring damper system?

Post by NapsterIsReal »

I actually fixed the issue. If anyone wants to have a spring-damper system with two masses, here you go!

goo.gl/HilQeY

NapsterIsReal
Posts: 4
Joined: 28 Mar 2017, 19:06

Re: How can I write a joint callback script that will act like a spring damper system?

Post by NapsterIsReal »

I have just realized that maxVelocity argument is still causing some misbehavior in the system. Writing a spring damper in any simulator is pretty trivial. I don't understand what this maxVelocity parameter is achieving in the joint control callback script.

Can somebody please explain to me what it does?

coppelia
Site Admin
Posts: 10375
Joined: 14 Dec 2012, 00:25

Re: How can I write a joint callback script that will act like a spring damper system?

Post by coppelia »

With a physics engine you have more possibilities than in reality. So you can cheat in many different ways if you wish (which you can't in reality).
Also, most physics engines' force/torque mode allows to specify a maximum velocity, when reached, will have the force/torque drop to zero (basically not overshooting a given maximum velocity). That is the Target velocity.
So normally, if you set that value very high, then you have the desired behaviour. If you set it lower, then you can in some situations improve stability, etc.

Cheers

NapsterIsReal
Posts: 4
Joined: 28 Mar 2017, 19:06

Re: How can I write a joint callback script that will act like a spring damper system?

Post by NapsterIsReal »

Thanks! I think I solved my issue. I eventually ended up adding an if-else routine to set the target velocity high and ver low depending on the torque direction. It was a little complicated to get there. Maybe a tutorial or something would help people in the future.

I really like V-Rep by the way. Hope it gets even better in the future.

Post Reply