ros getobjecthandle

Typically: "How do I... ", "How can I... " questions
Post Reply
btz
Posts: 2
Joined: 28 Oct 2013, 14:58

ros getobjecthandle

Post by btz » 05 Nov 2013, 14:16

Hi,
I have a little trouble understanding in the API how i have to write the code to get an objecthandle by name.
Could anyone provide me with a little code example how to get an object named "sensor" or so?

Thank you in advance.

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

Re: ros getobjecthandle

Post by coppelia » 06 Nov 2013, 14:08

Hello,

to retrieve the handle of an object, you can do:
  • From a child script, an add-on, or a plugin:

    Code: Select all

    handle=simGetObjectHandle("objectName")
  • From a remote API client (e.g. C/C++):

    Code: Select all

    int handle;
    int errorCode=simxGetObjectHandle(clientId,"objectName",&handle,simx_opmode_oneshot_wait); 
  • From a ROS node:

    Code: Select all

    ros::ServiceClient client_getObjectHandle=node.serviceClient<vrep_common::simRosGetObjectHandle>("/vrep/simRosGetObjectHandle");
    vrep_common::simRosGetObjectHandle srv_getObjectHandle;
    srv_getObjectHandle.request.objectName="objectName";
    if ( client_getObjectHandle.call(srv_getObjectHandle))
    {
    	int handle=srv_getObjectHandle.handle;
    }
Cheers

omar khalfaoui
Posts: 16
Joined: 18 Nov 2013, 14:32

Re: ros getobjecthandle

Post by omar khalfaoui » 13 Mar 2014, 11:53

Hi,

I just would like to add a quesiton:
for instence, I would like to create a ROS node that allows me to control the posotion of a dummy in the simulation.
if I'm not wrong,

First: I need to create the comunication using

Code: Select all

ros::ServiceClient client_enableSubscriber=n.serviceClient<vrep_common::simRosEnableSubscriber>("/vrep/simRosEnableSubscriber");
vrep_common::simRosEnableSubscriber srv_enableSubscriber;
srv_enableSubscriber.request.topicName="creaDummy"; // the topic name
srv_enableSubscriber.request.queueSize=1; // the subscriber queue size (on V-REP side)
Second: I need to retrieve the handle of the object:

Code: Select all

vrep_common::simRosGetObjectHandle srv_getObjectHandle;
srv_getObjectHandle.request.objectName="objectName";
Third: check if the service call was ok, and the subscriber was succesfully started on V-REP side.

Code: Select all

if (client_enableSubscriber.call(srv_enableSubscriber)&&(srv_enableSubscriber.response.subscriberID!=-1))
{...
             if ( client_getObjectHandle.call(srv_getObjectHandle))
              {...
Now, inside the seconde if, i need to use the handle. Let's say I want to change the x-value of the dummy. can I use a command similar to the followint?:

Code: Select all

...
[i]int handle=srv_getObjectHandle.position.x [/i]
...
The thing is that i would like to use only a ROS node to handle everything in VREP. I don't know if it's possible or not.

PS: in my case, is it better to use a threaded or a non-thereaded childscript?

Thank you very much for the Help.
have a nice day

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

Re: ros getobjecthandle

Post by coppelia » 13 Mar 2014, 16:31

See your other post/my other reply

Cheers

Post Reply