Using simExtRosInterface_advertiseService

Typically: "How do I... ", "How can I... " questions
Post Reply
silkjc
Posts: 4
Joined: 08 Mar 2017, 23:12

Using simExtRosInterface_advertiseService

Post by silkjc »

Hi VREP community,
Firstly thanks for some great software. I have a question regarding advertising a ROS service, there seems to be very little documentation or usage of simExtRosInterface_advertiseService on the forum.

I wish to set up two services to start and stop publishing a topic.
My question relates to the structure of the required callback function:

Code: Select all

stop_service_handle = simExtRosInterface_advertiseService(stopServiceName, 'std_srvs/Empty', 'stop_capture_callback')
function stop_capture_callback(req)
    --simExtROS_disablePublisher('/'..cameraImageTopicName)
    return {true} 
end
After calling the service I get the following:

Code: Select all

rosservice call /wrist_cam/stop_capture "{}"
ERROR: service [/wrist_cam/stop_capture] responded with an error: 
And from VREP console:

Code: Select all

Error: [string -unknown location]:?: ros_srv_callback__std_srvs__Empty: read__std_srvs__EmptyResponse: expected a table (stop_capture_callback)

Obviously it is expecting a table type as the return on the callback function. However I cannot seem to get the required structure for the return. Any help or examples would be awesome! I could not find any example projects that advertise a service.

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

Re: Using simExtRosInterface_advertiseService

Post by coppelia »

Hello,

normally you would prepare a service like this:

Code: Select all

simExtRosInterface_advertiseService('/testService','std_srvs/Trigger','service_callback')
and have your service routine like that:

Code: Select all

function service_callback(msg)
    local reply={}
    reply.success=true
    reply.message="Hello there!"
    return reply
end
But you are right, it seems there is a problem with the empty message. Even returning an empty table does not work.

Cheers

silkjc
Posts: 4
Joined: 08 Mar 2017, 23:12

Re: Using simExtRosInterface_advertiseService

Post by silkjc »

Thanks for the help, do you have any plans to release a patch or should I be delving into ROSinterfaces plug in code? Does the old ROS plug in have the ability to provide an empty service?

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

Re: Using simExtRosInterface_advertiseService

Post by coppelia »

Yes, the git repository will be patched in the next few days.

Cheers

Post Reply