Code: Select all
disp('Program started');
clc
close all
clear all
load('data.mat');
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);
vrep.simxPauseSimulation(clientID, vrep.simx_opmode_oneshot);
if (clientID>-1)
disp('Connected to remote API server');
[returnCode,agent(1)]=vrep.simxGetObjectHandle(clientID,'Manta', vrep.simx_opmode_oneshot_wait);
[returnCode,agent(2)]=vrep.simxGetObjectHandle(clientID,'Manta#0', vrep.simx_opmode_blocking);
[returnCode,agent(3)]=vrep.simxGetObjectHandle(clientID,'Manta#1', vrep.simx_opmode_blocking);
for i=1:tspan(1,2)/0.05
vrep.simxPauseSimulation(clientID, vrep.simx_opmode_oneshot);
instant=0.05*i;
[minimum, j]= min(abs(t-instant));
vrep.simxSetObjectPosition(clientID, agent(1), -1, [q(j, 1), q(j, 2), 0.1922]', vrep.simx_opmode_oneshot);
vrep.simxSetObjectPosition(clientID, agent(2), -1, [q(j, 8), q(j, 9), 0.1922]', vrep.simx_opmode_oneshot);
vrep.simxSetObjectPosition(clientID, agent(3), -1, [q(j, 15), q(j, 16), 0.1922]', vrep.simx_opmode_oneshot);
vrep.simxStartSimulation(clientID,vrep.simx_opmode_blocking);
end
vrep.simxFinish(-1);
end
vrep.delete();
disp('Program Ended');