Page 2 of 2

Re: Cannot set initial velocity though Matlab API

Posted: 09 May 2019, 12:47
by chenci
Hello, I have the same problem as you. I want to use Python API to control the Velocity of an object. But it doesn't work. I want to know how do you solve your problem? Thanks~

Re: Cannot set initial velocity though Matlab API

Posted: 09 May 2019, 13:29
by coppelia
Hello,

for instance, add a dynamically enabled sphere to the scene. Then attach a non-threaded child script to it with following content:

Code: Select all

function sysCall_init()
    h=sim.getObjectAssociatedWithScript(sim.handle_self)
    sim.setObjectFloatParameter(h,sim.shapefloatparam_init_ang_velocity_x,0.5)
end
from an external application, use a function in the same child script, e.g.:

Code: Select all

function setVelocity(inInts,inFloats,inStrings,inBuffer)
    local h=inInts[1]
    local vel=inFloats
    sim.resetDynamicObject(h)
    sim.setObjectFloatParameter(h,sim.shapefloatparam_init_ang_velocity_x,vel[1])
    sim.setObjectFloatParameter(h,sim.shapefloatparam_init_ang_velocity_y,vel[2])
    sim.setObjectFloatParameter(h,sim.shapefloatparam_init_ang_velocity_z,vel[3])
	return {},{},{},''
end
then correctly call above function with simxCallScriptFunction.

cheers