Can't advertise service with roslibjs

asked 2023-04-21 02:31:43 -0500

Sam3456 gravatar image

I have been trying to implement a service server that fires a callback function once a service request is received, but it is not showing up after advertising, as in the service is not shown in the rosservice list, here is my code that is responsible for setting up the server:

var ros = new ROSLIB.Ros({ url: 'ws://localhost:9090' });

var sentence_client = new ROSLIB.Service({ ros: ros, name: '/robobreizh/sentence_gpsr', serviceType: 'std_msgs/String' });

sentence_client.advertise(function (request, response) { console.log('Received service request on ' + sentence_client.name + ': ' + request.data); response['success'] = true; response['message'] = 'Set successfully'; return true; });

It ran on my webpage without any errors or warnings, but the error "ERROR: Service [/sentence] is not available." showed up when I call the service with the command "rosservice call /sentence std_msgs/String "Test" " on my terminal, I tried adding console.log after each function and all them them worked properly, so I assume every line was executed properly, just that no service was advertised properly.

And I also want to ask about the callback function upon receiving a service request, can I include a callback function in the server side code? As I saw that in the sample service javascript code, there is only callback function on the client side but no callback function on the server side, but I would like to include a callback function to generate the service response.

I am using rosjslib min with plain javascript 1.7, on Netscape 5.0, Linux armv7l, thank you.

edit retag flag offensive close merge delete