Page 1 of 1

Setting object position in V-REP

Posted: 10 Sep 2013, 01:49
by trabias
Hi!

I have arrays of values calculated in MATLAB for the x, y, and z position and I'm trying to find the best way to send that information to V-REP. My initial idea is to use simSetObjectPosition within a for loop in a child script so that it runs through the all of the values and changes the position in real time. I'm not fluent in C programming, is there a good example that I can follow along?

Thanks!
Sarah

Re: Setting object position in V-REP

Posted: 10 Sep 2013, 10:22
by coppelia
Hello Sarah,

if you are using Matlab, use the function simxSetObjectPosition:

Code: Select all

vrep.simxSetObjectPosition(clientID,objectHandle,-1,objectPosition,vrep.simx_opmode_oneshot);
Cheers

Re: Setting object position in V-REP

Posted: 11 Sep 2013, 00:55
by trabias
Thanks for the quick reply! I received this error and was wondering if you had any ideas what is the issue? I tried to adjusting the input for the position array different ways and I keep getting the same error.

No appropriate method, property, or field simxSetObjects for class remApi.
Error in startvrep (line 15)
[errorCode]=vrep.simxSetObjects(clientID,0,-1,[x(100) y(100) z(100)],vrep.simx_opmode_oneshot);
Error in quadrotor_sim (line 8)

Thanks!
Sarah

Re: Setting object position in V-REP

Posted: 11 Sep 2013, 01:12
by coppelia
Oops, I made a typo, the function is not simxSetObjects, but simxSetObjectPosition.

Cheers

Re: Setting object position in V-REP

Posted: 11 Sep 2013, 01:54
by trabias
Ohh ok! Thanks! I ran the program now and it gives no issues, but the quadricopter doesn't move.... is there something missing from my code (included below) or should I add something to the child script to read the information given?

Thanks!
Sarah

Code: Select all

function startvrep(xyz)
x=xyz(:,1);
y=xyz(:,2);
z=xyz(:,3);
disp('Program started')
vrep=remApi('remoteApi','extApi.h');
clientID=vrep.simxStart('127.0.0.1',19999,true,true,5000,5);
if (clientID>-1)
    disp('Connected to remote API server');
    [errorCode]=vrep.simxStartSimulation(clientID,vrep.simx_opmode_oneshot_wait);
    [res,objs]=vrep.simxGetObjects(clientID,vrep.sim_handle_all,vrep.simx_opmode_oneshot_wait);
    [errorCode,handle]=vrep.simxGetObjectHandle(clientID,'Quadricopter',vrep.simx_opmode_oneshot)
    disp('Controlling the xyz position')
    for i=1:1601
        [errorCode]=vrep.simxSetObjectPosition(clientID,handle,-1,[x(i) y(i) z(i)],vrep.simx_opmode_oneshot);
    end
    if (res==vrep.simx_error_noerror)
        fprintf('Number of objects in the scene: %d\n',length(objs));
    else
        fprintf('Remote API function call returned with error code: %d\n',res);
    end
    vrep.simxFinish(clientID);
else
    disp('Failed connecting to remote API server');
end
        vrep.delete();
disp('Program ended');
end

Re: Setting object position in V-REP

Posted: 11 Sep 2013, 09:54
by coppelia
You have 3 problems in your code:
  • when retrieving the handle of the object, use a blocking mode operation, i.e. vrep.simx_opmode_oneshot_wait, otherwise you won't retrieve the handle. Make sure you have understood how the remote API operates.
  • you should control the position of Quadricopter_target, not Quadricopter!
  • when sending positions, put some wait commands, otherwise everything is sent and arrives more or less at the same time.
Cheers

Re: Setting object position in V-REP

Posted: 16 Sep 2020, 16:43
by cpscps
Hi Sarah!

I want to use a quadricopter in the same way and I have the same problems so I would like to know if you finally could make your project work.

Thanks in advance!

Re: Setting object position in V-REP

Posted: 18 Sep 2020, 08:22
by coppelia
Hello,

first you need to determine how you want to connect CoppeliaSim to Matlab. Then, there are several options to transmit data from one to the other.

Cheers