how to use simxCallScriptFunction in matlab to get the mass of a link on Franka

Typically: "How do I... ", "How can I... " questions
Post Reply
yanxj20
Posts: 11
Joined: 14 Jan 2021, 08:11

how to use simxCallScriptFunction in matlab to get the mass of a link on Franka

Post by yanxj20 »

Hi everyone,

I am trying to use simxCallScriptFunction in matlab to get the mass of a link on Franka . After I wrote my code in threaded child script(Franka) as follows:

Code: Select all

getMass_function = function(inInts,inFloats,inStrings,inBuffer)
    if #inInts>=1 then
        mass,inertiaMatrix,centerOfMass = sim.getShapeMassAndInertia(inInts[1],nil)
        return {},{mass},{},''
    end
end
I need to write code in matlab. According to the synopsis of function simxCallScriptFunction in helpFile:

Code: Select all

 array simxCallScriptFunction(string funcAtObjName, number/string scriptType, anyType funcArgs, string topic)
 
my code is:

Code: Select all

vrep.simxCallScriptFunction('getMass_function@Franka','sim.scripttype_childscript',linkHandle,[],[],[],vrep.simx_opmode_blocking);
but I get an error:

Code: Select all

Not enough input arguments.

Error in remApi/simxCallScriptFunction (line 2075)
            variousIntsIn_ =
            libpointer('int32Ptr',int32([clientID,options,numel(inInts),numel(inFloats),strCnt,numel(inBuffer),operationMode]));

Error in c20200122getMassFromVrep (line 43)
[resM, ~, retFloatsM, ~, ~] =
vrep.simxCallScriptFunction('getMass_function@Franka','sim.scripttype_childscript',[linkHandle],[],[],[],vrep.simx_opmode_blocking);
and then I try

Code: Select all

[resM, ~, retFloatsM, ~, ~] = vrep.simxCallScriptFunction(clientID,'getMass_function@Franka','sim.scripttype_childscript',[linkHandle],[],[],[],vrep.simx_opmode_blocking);
The error remains the same. why? thanks!

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

Re: how to use simxCallScriptFunction in matlab to get the mass of a link on Franka

Post by coppelia »

Hello,

try with following:

Code: Select all

[resM, retIntsM, retFloatsM, retStringsM, retBufferM] = vrep.simxCallScriptFunction(clientID,'Franka',vrep.sim_scripttype_childscript,'getMass_function',[linkHandle],[],'',[],vrep.simx_opmode_blocking);
Cheers

yanxj20
Posts: 11
Joined: 14 Jan 2021, 08:11

Re: how to use simxCallScriptFunction in matlab to get the mass of a link on Franka

Post by yanxj20 »

Thanks! that error is removed but there is still something wrong. the resM is false in MATLAB and in vrep i receive:
Error: [string -unknown location]:?: Call failed. (simCallScriptFunctionEx on getMass_function@Franka)

I have no idea where the problem could be this time.==
coppelia wrote:
22 Jan 2021, 11:12
Hello,

try with following:

Code: Select all

[resM, retIntsM, retFloatsM, retStringsM, retBufferM] = vrep.simxCallScriptFunction(clientID,'Franka',vrep.sim_scripttype_childscript,'getMass_function',[linkHandle],[],'',[],vrep.simx_opmode_blocking);
Cheers

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

Re: how to use simxCallScriptFunction in matlab to get the mass of a link on Franka

Post by coppelia »

Make sure that your function has exactly the same spalling: getMass_function
Make also sure the script the function is defined in is attached to the object Franka (also check the exact spelling).
Make sure that the script the function is defined in is a child script, and that it is (still) initialized at the time it is called.

Cheers

yanxj20
Posts: 11
Joined: 14 Jan 2021, 08:11

Re: how to use simxCallScriptFunction in matlab to get the mass of a link on Franka

Post by yanxj20 »

Thanks! The problem is solved! I find that the functions should be defined in a non-threaded child script, rather than threaded child script.

Post Reply