If I try to remotely control the robot from Matlab (R2013b x64) using Remote API (remoteApi.so for 64-bits) connection is successfully stablished and handles to the joints return a valid number, even I can start and stop the simulation properly in synchronous mode. However, I am having troubles with simxSetJointTargetPostion function, because the simulation ignores it and the joint doesn't change its target position. I have also tried non-synchronous modes, a simulation witout dynamic contens (joints configured in passive mode) and the funcion simxSetJointPosition instead of simxSetJointTargetPosition, but the result is the same, the call is simply ignored. The return error code is 1, which I think is normal if a call the functions with simx_opmode_oneshot.
I post here my code:
-------------------------------------------------
Code: Select all
vrep=remApi('remoteApi');
vrep.simxFinish(-1); % just in case, close all opened connections
clientID=vrep.simxStart('127.0.0.1',19997,true,true,5000,5);
try
if (clientID>-1)
vrep.simxSynchronous(clientID,1); %%Enables synchronous mode
vrep.simxStartSimulation(clientID,vrep.simx_opmode_oneshot);
disp('Connected to remote API server');
qLID=zeros(12,1);
for i=1:6
str=sprintf('%s%d','joint',i);
[~,qLID(i)]=vrep.simxGetObjectHandle(clientID,str,vrep.simx_opmode_oneshot_wait);
end
for i=1:6
str=sprintf('%s%d','joint',13-i);
[~,qLID(i+6)]=vrep.simxGetObjectHandle(clientID,str,vrep.simx_opmode_oneshot_wait);
end
qL=zeros(12,1);
for i=1:12
qL(i)=30*pi/180;
end
%Now run the simulation a given number of iterations
for k=1:30
vrep.simxPauseCommunication(clientID,1);
for i=1:length(qL)
ret=vrep.simxSetJointTargetPosition(clientID,qLID(i),qL(i),vrep.simx_opmode_oneshot);
end
vrep.simxPauseCommunication(clientID,0);
vrep.simxSynchronousTrigger(clientID);
end
vrep.simxStopSimulation(clientID,vrep.simx_opmode_oneshot);
pause(1);
vrep.simxFinish(clientID);
else
disp('Failed connecting to remote API server');
end
vrep.delete(); % call the destructor!
catch err
vrep.simxFinish(clientID); % close the line if still open
vrep.delete(); % call the destructor!
end;
disp('Program ended');
The output I get is:
Running Matlab glnxa64
make sure you use the corresponding remoteApi library
(i.e. 32bit Matlab will not work with 64bit remoteApi, and vice-versa)
Connected to remote API server
Program ended
Variable qLID is:
qLID =
56
57
58
59
60
61
67
66
65
64
63
62