Cannot set initial velocity though Matlab API

Report crashes, strange behaviour, or apparent bugs
chenci
Posts: 1
Joined: 02 May 2019, 11:09

Re: Cannot set initial velocity though Matlab API

Post 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~

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

Re: Cannot set initial velocity though Matlab API

Post 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

Post Reply