ROSLIBJS - Call service - No Respone

asked 2019-10-13 18:14:29 -0600

Tomer Azran gravatar image


I'm trying to call a service using ROSLIB.JS and rosbridge websockets. I can see that the service is being called, and do what it needs to do, but I'm not getting any response.

Here is my JS code:

function initEnginesPowerStateService() {
        console.log("Creating the service");
        var robotPowerStateClient = new ROSLIB.Service({
            ros: ros,
            name: '/get_robot_power_state',
            serviceType: 'my_robot/RobotPower'

        console.log("Creating the service request");
        var request = new ROSLIB.ServiceRequest({});

        console.log("calling the service");
        robotPowerStateClient.callService(request, function (response) {        
            console.log('Result for service call power_state = ' + response);
        }, function(error){
            console.error("Got an error while trying to call power state service");

What am I missing?

I'm using latest ROSLIBJS. My ROS version is melodic.

Thanks, Tomer.

edit retag flag offensive close merge delete


Just to clarify: you're calling the service from your JS code, the server is receiving that request and creating/sending a response without error, and then your console.log (or console.error) is not firing, yes?

Jari gravatar imageJari ( 2019-10-14 15:47:03 -0600 )edit

Correct. I'm calling the service, the server is receiving the call (I can see that in the service log), and do what it need to do. The service returns an answer, but I'm not seeing anything on the browser console.

Tomer Azran gravatar imageTomer Azran ( 2019-10-15 01:02:24 -0600 )edit

I'm unfamiliar with how JS works but it looks like you're initializing the client in this function but then not returning it to the caller. Is it possible it's going out of scope and getting garbage collected causing all the associated callbacks to also no longer exists?

Jari gravatar imageJari ( 2019-10-15 12:04:53 -0600 )edit

I tried to call the same code on global scope - the results are the same.

Tomer Azran gravatar imageTomer Azran ( 2019-10-16 15:12:45 -0600 )edit

I can't think of what else might be wrong without knowing more about your setup. Maybe you can come to the unofficial ROS discord ( and we can try to find a time to do some live debugging.

Jari gravatar imageJari ( 2019-10-16 17:29:47 -0600 )edit