Hello.
I created a simple car model in CoppeliaSim: a body and 4 wheels connected with the body by revolute joints. For the rear wheels, I set some target speed. After I start the model, the car accelerates. At the same time, in the child script, I control the speed of the rear wheels by sim.getJointVelocity function. I observe strange behavior: the car is driving, but the value returned by the function drops to zero. Has anyone encountered similar behavior?
Problem with sim.getJointVelocity function
Re: Problem with sim.getJointVelocity function
Hello,
not sure what is happening exactly. What engine are you using? Did you try with the MuJoCo engine?
With all other engines, the joint velocity is measured, and if the joint is turning too fast, sampling points are too few. In that case, try to reduce the dynamics dt, in the simulation dialog.
With the MuJoCo engine on the other hand, the joint velocity is tracked by the physics engine directly, and should display correct values also at higher speeds.
Cheers
not sure what is happening exactly. What engine are you using? Did you try with the MuJoCo engine?
With all other engines, the joint velocity is measured, and if the joint is turning too fast, sampling points are too few. In that case, try to reduce the dynamics dt, in the simulation dialog.
With the MuJoCo engine on the other hand, the joint velocity is tracked by the physics engine directly, and should display correct values also at higher speeds.
Cheers
Re: Problem with sim.getJointVelocity function
I use Bullet 2.78. It's very strange, but there is no problem with MoJoCo engine. Joint turning is about 50 deg/s and dt = 0.05 sec. Scene link: https://disk.yandex.ru/d/Dh1hTGrJcLt8Dw
Re: Problem with sim.getJointVelocity function
Correction: with the MuJoCo engine, the speed drop to zero also occurs, but not at the 17th second, but much later (130th).
Re: Problem with sim.getJointVelocity function
You are right, we introduced a bug in last CoppeliaSim release... (V4.4). You can use following function as a workaround:
Cheers
Code: Select all
function sim.getJointVelocity(handle)
local t=sim.getSimulationTime()
local p=sim.getJointPosition(handle)
if _velData==nil then
_velData={}
end
if _velData[handle]==nil then
_velData[handle]={lastPos=p,lastTime=t,lastVel=0}
end
if _velData[handle].lastTime~=t then
local dp=p-_velData[handle].lastPos
local cyclic=sim.getJointInterval(handle)
if cyclic then
local sin_da=math.sin(p)*math.cos(_velData[handle].lastPos)-math.cos(p)*math.sin(_velData[handle].lastPos)
local cos_da=math.cos(p)*math.cos(_velData[handle].lastPos)+math.sin(p)*math.sin(_velData[handle].lastPos)
dp=math.atan2(sin_da,cos_da)
end
_velData[handle].lastVel=dp/(t-_velData[handle].lastTime)
_velData[handle].lastPos=p
_velData[handle].lastTime=t
end
return _velData[handle].lastVel
endRe: Problem with sim.getJointVelocity function
Thank you for your answer. It works.
My question: why did you use trigonometry formulas for angle difference? Why did not you write:
sin_da=math.sin(p - _velData[handle].lastPos)
My question: why did you use trigonometry formulas for angle difference? Why did not you write:
sin_da=math.sin(p - _velData[handle].lastPos)
Re: Problem with sim.getJointVelocity function
with cyclic angles (i.e. angles that vary between -pi and +pi), you need to pick the smallest distance in one or the other direction.
Cheers
Cheers