How can i get Position and Orientation of and Object

Typically: "How do I... ", "How can I... " questions
Post Reply
joseamair
Posts: 15
Joined: 15 Jun 2016, 01:33

How can i get Position and Orientation of and Object

Post by joseamair » 19 Oct 2016, 06:31

Hi Again, How are you?
Its been really helpfull your support since the begining. Im really Graetful for that.


I got a fully functional scene<At least what i want ^^> , comunicated trough matlab Via the API.

Im working with a model of a Hexapod.
Now i need to get the position and orientation of the Dummy_i Objects that i place on the certain points of my robot.

I need those values in reference of the Floor.
since im using matlab, im take these command lines to retrieve what i need, but no effect till now:

1st: I need the Position of the Floor on the Scene as the Base AXIS ¿no? , so i tried these lines

Code: Select all

[codigo_retorno,floor_visible_handle]=vrep.simxGetObjectHandle(clientID,'ResizableFloor_5_25_visibleElement',vrep.simx_opmode_blocking);
and this One:

Code: Select all

[codigo_retorno,floor_handle]=vrep.simxGetObjectHandle(clientID,'ResizableFloor_5_25',vrep.simx_opmode_blocking);
¿ ResizableFloor_5_25 & ResizableFloor_5_25_visibleElement Objects are the same?
Im getting differents ID <Integrers identificators from the Scene>

As it is named on the Scene my hexapod base i named as:

Code: Select all

[codigo_retorno,hexa_base_handle]=vrep.simxGetObjectHandle(clientID,'hexa_base',vrep.simx_opmode_blocking);
Then i named one of the end tip of the leg of my robot like Dummy_1:

Code: Select all

[codigo_retorno,dummy_1_handle]=vrep.simxGetObjectHandle(clientID,'Dummy_1',vrep.simx_opmode_blocking);
The thing is that now if i want to get the position of the Dummy_1 im getting (0,0,0), and that is now what is happening on the real Scene.

Im using this commands in matlab to get the position:
For the Base:

Code: Select all

[codigo_retorno,position_hexa_base] = vrep.simxGetObjectPosition(clientID,hexa_base_handle,floor_visible_handle,vrep.simx_opmode_streaming);
[codigo_retorno,angles_hexa_base] = vrep.simxGetObjectOrientation(clientID,hexa_base_handle,floor_visible_handle,vrep.simx_opmode_streaming);

With no results. Even when i tried to get the same parametres for the Dummys im getting (0,0,0).
Here is the Workspace on Matlab:
https://www.dropbox.com/s/m3k9islkdpumk ... s.jpg?dl=0

And here is the Scene, if you want to Check it Out. Maybe im doing something Wrong:
https://www.dropbox.com/s/1dxe6kt04zm8m ... l.ttt?dl=0

Hope you can help me with this thing.
Thanks & Cheers.

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

Re: How can i get Position and Orientation of and Object

Post by coppelia » 19 Oct 2016, 09:32

I do not understand your question or problem exactly.
First, it is normal that you receive different iDs (or handles) for different objects.
Then, if you need to get the position of objectA relative ti objectB's frame, then you would do:

Code: Select all

simGetObjectPosition(objectAHandle,objectBHandle)
In a child script. From a remote API client, you would do in a similar way:

Code: Select all

vrep.simxGetObjectPosition(clientID,objectAHandle,objectBHandle,vrep.simx_opmode_blocking);
Try first to use blocking calls, until things work as expected.

When you say: With no results. What does it mean?

Cheers

joseamair
Posts: 15
Joined: 15 Jun 2016, 01:33

Re: How can i get Position and Orientation of and Object

Post by joseamair » 19 Oct 2016, 14:27

Hi There!
When you say: With no results. What does it mean?
I Mean that im getting 0,0,0 but in the scene that is not the position of the object or the dummy that im trying to get the position or angles.

Im using the functions of this reference:
http://www.coppeliarobotics.com/helpFil ... Matlab.htm

and from there these functions:
simxGetObjectPosition (regular API equivalent: simGetObjectPosition)

Matlab synopsis:
"

Code: Select all

[number returnCode,array position]=simxGetObjectPosition(number clientID,number objectHandle,number relativeToObjectHandle,number operationMode)
Matlab parameters:
clientID: the client ID. refer to simxStart.
objectHandle: handle of the object
relativeToObjectHandle: indicates relative to which reference frame we want the position. Specify -1 to retrieve the absolute position, sim_handle_parent to retrieve the position relative to the object's parent, or an object handle relative to whose reference frame you want the position
operationMode: a remote API function operation mode. Recommended operation modes for this function are simx_opmode_streaming (the first call) and simx_opmode_buffer (the following calls) "

Where the parameters:
objectHandle and relativeToObjectHandle, are of interest if i want to get a specificied position refered to an other object no?


Btw, where i can find documentation of the function syntax that you mention:

Code: Select all

vrep.simxGetObjectPosition(clientID,objectAHandle,objectBHandle,vrep.simx_opmode_blocking);
Or it is the same of the other function syntax.
Btw with -1 in the relativeObject Parameter is working now.

But: When in the function documentation says:
Specify -1 to retrieve the absolute position, sim_handle_parent to retrieve the position relative to the object's parent, or an object handle relative to whose reference frame you want the position
.
How i can get the relative position of and relative object, for example if i want the position of a dummy object Dummy_1 (that references the end of a tip of leg_1) and the Hexa_base (That references the initial base axis of my hexapod)?
If the Dummy_1 has the Handle numer of 78, and the hexa_base 17 the function to recall the position of the Dummy_1 Should be:

vrep.simxGetObjectPosition(clientID,78,17,vrep.simx_opmode_blocking)

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

Re: How can i get Position and Orientation of and Object

Post by coppelia » 20 Oct 2016, 12:51

Your questions are too long and too varied, it is really difficult to answer correctly.

So, when you call

Code: Select all

vrep.simxGetObjectPosition(clientID,objectAHandle,objectBHande,vrep.simx_opmode_blocking)
it will return the position of objectA RELATIVE to the reference frame of objectB. If you need the ABSOLUTE position of objectA, then set the 3rd argument to -1.

Also, remember that object handles are not guaranteed to be the same from one scene load to another. It could change. For that reason it is important to retrieve the object handles at the beginning of a program.

Cheer

joseamair
Posts: 15
Joined: 15 Jun 2016, 01:33

Re: How can i get Position and Orientation of and Object

Post by joseamair » 20 Oct 2016, 19:51

Well it is now Working. It seems that i just have to use "vrep.simx_opmode_blocking". But is just working with reference to the World Scene Axis.

When you mention this:
it will return the position of objectA RELATIVE to the reference frame of objectB. If you need the ABSOLUTE position of objectA, then set the 3rd argument to -1.
in the code:

Code: Select all

vrep.simxGetObjectPosition(clientID,objectAHandle,objectBHande,vrep.simx_opmode_blocking)
Wich one is the 3rd Argument?

im using the same line of code as:

Code: Select all

vrep.simxGetObjectPosition(clientID,Dummy_1,-1,vrep.simx_opmode_blocking)


Is there other syntax or documentation of this Function?

Thnx again.
Cheers.

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

Re: How can i get Position and Orientation of and Object

Post by coppelia » 23 Oct 2016, 07:32

Sorry, I meant the 4th argument: the regular API function simSetObjectPosition doesn't have the exactl same arguments as the remote API function simxSetObjectPosition.

Cheers

mash2612
Posts: 8
Joined: 28 Jan 2018, 10:21

Re: How can i get Position and Orientation of and Object

Post by mash2612 » 02 Sep 2018, 18:41

Hi,

As you mentioned to determine the ObjectPosition the operation mode should be "blocking " in the following syntax:
returnCode, position=vrep.simxGetObjectPosition(clientID, objectHandle, relativeToObjectHandle, operationMode) in remote API for Python.
This works perfectly fine for me.
However, the suggested operation mode are as follows:
Recommended operation modes for this function are simx_opmode_streaming (the first call) and simx_opmode_buffer (the following calls)

This just returns me the value of 0's. Could you please help me to understand why it works like this?

Regards.

Post Reply