Cannot set initial velocity though Matlab API

Report crashes, strange behaviour, or apparent bugs
tgurriet
Posts: 10
Joined: 14 Feb 2018, 14:23

Cannot set initial velocity though Matlab API

Post by tgurriet »

Hello,

I'm trying to set an initial for a body in a dynamics simulation.

The instructions from here work:
viewtopic.php?t=6028
However, when I try to do the same through the matlab API, the initial velocity isn't set.

The scene is just a dynamically enabled sphere in the air.
The matlab code is as follow:

Code: Select all

vrep=remApi('remoteApi');
vrep.simxFinish(-1);
clientID=vrep.simxStart('127.0.0.1',19997,true,true,5000,5);
[returnCode,handle] = vrep.simxGetObjectHandle(clientID, 'Sphere', vrep.simx_opmode_blocking);
returnCode = vrep.simxSetObjectFloatParameter(clientID,handle,vrep.sim_shapefloatparam_init_velocity_x,1.0,vrep.simx_opmode_blocking);
returnCode = vrep.simxStartSimulation(clientID,vrep.simx_opmode_blocking);
Everything return OK, but the sphere has no initial velocity when the simulation starts.

Thanks in advance.

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

Re: Cannot set initial velocity though Matlab API

Post by coppelia »

Hello,

can you tell me what V-REP version you are running?
Also, in the mean time and as a work-around, you can instead call a script function that will execute the code from within a script for you: simxCallScriptFunction. Just make sure to use a customization script for that, since you need the script to be running before simulation starts (you can't call a script function inside of a simulation script before simulation has started).

Cheers

tgurriet
Posts: 10
Joined: 14 Feb 2018, 14:23

Re: Cannot set initial velocity though Matlab API

Post by tgurriet »

I have tried with version 3.4 and 3.5. Same result for both.

I'll try with the customization script call, thanks.

tgurriet
Posts: 10
Joined: 14 Feb 2018, 14:23

Re: Cannot set initial velocity though Matlab API

Post by tgurriet »

Still doesn't work with customization scripts.

So far it only works if I set the initial velocity in the "sysCall_init" of a non-threaded child script.

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

Re: Cannot set initial velocity though Matlab API

Post by coppelia »

We'll have to look into this...

Cheers

tgurriet
Posts: 10
Joined: 14 Feb 2018, 14:23

Re: Cannot set initial velocity though Matlab API

Post by tgurriet »

Thanks.

Let us know if you find a workaround we can use in the meantime.

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

Re: Cannot set initial velocity though Matlab API

Post by coppelia »

Ok, there is indeed a problem. Thanks for mentioning it.
You can download correction libs. At some later point, we will release a new revision (V3.5.0 rev2+).

Cheers

tgurriet
Posts: 10
Joined: 14 Feb 2018, 14:23

Re: Cannot set initial velocity though Matlab API

Post by tgurriet »

Works fine now, thanks!

A little remark though, the initial velocity is not saved when restarting the simulation.
Not sure if it is the intended behavior but when you have a complex robot with lots of joints it takes forever to make all the calls to "simxSetObjectFloatParameter". It would be nice if these initial velocity parameters were to be saved between simulation runs.

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

Re: Cannot set initial velocity though Matlab API

Post by coppelia »

Yes, that behaviour was actually intended, since we don't want to have that initial velocity if a dynamically enabled shape is reset while simulation is running. At the same time, that initial velocity was not saved nor copied.

We have changed it again and now it works like following:
  • initial velocity is serialized and copied
  • The first time the physics engine makes use of it, it gets cleared
  • at simulation end, the initial velocity is restored to what it was just before simulation started.
above should be available in next revision. In the mean time, as a work around, you can handle that via a child script:
  • in the init phase of the child script, read the current value of the initial velocity
  • in the clean-up phase of the child script, write the read value back
Cheers

tgurriet
Posts: 10
Joined: 14 Feb 2018, 14:23

Re: Cannot set initial velocity though Matlab API

Post by tgurriet »

Great, thanks!

Post Reply