Rotate objects with remote API

Typically: "How do I... ", "How can I... " questions
Post Reply
gunny
Posts: 3
Joined: 13 Jun 2013, 15:47

Rotate objects with remote API

Post by gunny » 18 Jul 2013, 13:14

Hi all,

I create a small project with v-rep and an external app.
My app is connected with a stereovision system to acquire positions with a pen.
When I acquire a point I extract the coordinates and the euler angles.
Now, with external API I try to rotate the dummy object in the simulation and a robot connected to the object follow the point.
All works fine but I have some questions.


- to rotate/translate the point I use:

simxPauseCommunication(SimID,1);
simxSetObjectPosition(SimID, Target.TargetID, -1, coo, simx_opmode_oneshot);
simxSetObjectOrientation(SimID, Target.TargetID, Target.TargetID, angles, simx_opmode_oneshot);
simxPauseCommunication(SimID,0);

in the command simxSetObjectOrientation, the angles need to be calculated in incremental mode.
i.e. if I have to reach the agles [0,0,30] and I am at [0,0,29], I need to assign [0,0,1] to angles param.
It's possible to specify the final angles values?


- To avoid the previous queston I try this code:

simxPauseCommunication(SimID,1);
simxSetObjectPosition(SimID, Target.TargetID, -1, coo, simx_opmode_oneshot);
simxSetObjectOrientation(SimID, Target.TargetID, sim_handle_parent, Target.angles, simx_opmode_oneshot);
simxSetObjectOrientation(SimID, Target.TargetID, Target.TargetID, angles, simx_opmode_oneshot);
simxPauseCommunication(SimID,0);

The first simxSetObjectOrientation, move te point to the starting position, the second move the point to the new position but seems that the first simxSetObjectOrientation is not processed.


- Last question.
using the first method, i move the point many times, after that, I put my stereovision pen in the start position and the robot is not placed in the start position with the orientation of the starting pos.
Could be a problem related to the approximations? This is why I want to change my method...

Thanks

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

Re: Rotate objects with remote API

Post by coppelia » 18 Jul 2013, 13:36

Hello,

The remote API works like this:
  • Commands are received from the clients asynchronously. The reception or communication speed depends on various factors (network type, settings, etc.)
  • When a command is received by V-REP, it is not directly processed. It is buffered.
  • If another same command arrived, it will erase the old command in the buffer. There are exceptions to this behaviour (e.g. simxAddStatusbarMessage or similar)
  • All buffered commands are executed sequentially at the start of a new simulation loop or simulation step (i.e. at time t+dt)
  • Once those commands have been executed, the main script is executed again.
  • and so on.
The reason for this is to keep a coherent simulation behaviour, typically:
  • Action
  • Sensing
  • Display
If action happens while sensing is underway, sensing will be wrong. And even inside the action section, it is important to keep things ordered: if you move an object while the physics engine does its calculation, the result is not predictible.

In your case, if you want to execute a movement in a stepped fashion, e.g. at each simulation step move a bit more, then try to use a child script that will handle requests coming from the remote API client. Have a look at the combination of simxAppendStringSignal (client side) and simGetStringSignal (child script side)

Maybe also have a look at some parts of the code that can be found here.

Cheers

Post Reply