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:
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
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.
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.
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.