I coded a climbing gait of a quadruped robot using IK chain and simRMLMoveToPosition in a threaded script. I am trying to remotely call the created climbing gait as a function from MATLAB.
I understand simxCallScriptFunction can only be used to Call non-threaded scripts, and I found simSetThreadIsFree can be used to declare a non-blocking section in a threaded script. I assume this means we can change functions in threaded scripts to performing as non-threaded ones by using simSetThreadIsFree.
My code structure on V-rep side is:
Code: Select all
simExtRemoteApiStart(19999,1300,false,true)
simSetThreadIsFree(1)
rearBodyClimbing=function(inInts,inFloats,inStrings,inBuffer)
if #inInts>=1 then
--Climbing gait--
return {},{},{'Rear body climbing finished'},' '
end
end
simSetThreadIsFree(0)
Code: Select all
function rearBodyClibming()
disp('Program started');
% vrep=remApi('remoteApi','extApi.h'); % using the header (requires a compiler)
vrep=remApi('remoteApi'); % using the prototype file (remoteApiProto.m)
vrep.simxFinish(-1); % just in case, close all opened connections
clientID=vrep.simxStart('127.0.0.1',19999,true,true,5000,5);
if (clientID>-1)
disp('Connected to remote API server');
% 1. First send a command to display a specific message in a dialog box:
[res retInts retFloats retStrings retBuffer]=vrep.simxCallScriptFunction(clientID,'cricketBodyDynamics',vrep.sim_scripttype_childscript,'rearBodyClimbing',[1 2 3],[],'',[],vrep.simx_opmode_blocking);
if (res==vrep.simx_return_ok)
fprintf('Returned message: %s\n',retStrings);
else
fprintf('Remote function call failed\n');
end
% Now close the connection to V-REP:
% vrep.simxFinish(clientID);
else
disp('Failed connecting to remote API server');
end
% vrep.delete(); % call the destructor!
% disp('Program ended');
end
I was wondering is it possible I can remotely call functions in threaded scripts by this method? If so, could you help me to fix my problem? Thank you very much.
Regards,
Jay