ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ROSLIBJS - Call service - No Respone

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

Tomer Azran gravatar image

Hello,

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

Comments

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 image Jari  ( 2019-10-14 15:47:03 -0500 )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 image Tomer Azran  ( 2019-10-15 01:02:24 -0500 )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 image Jari  ( 2019-10-15 12:04:53 -0500 )edit

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

Tomer Azran gravatar image Tomer Azran  ( 2019-10-16 15:12:45 -0500 )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 (https://discord.gg/RuKPjN) and we can try to find a time to do some live debugging.

Jari gravatar image Jari  ( 2019-10-16 17:29:47 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2020-09-17 08:12:27 -0500

Hi, I was facing exactly the same issue with ros2-eloquent. The reason for me was that I was using my custom interfaces for my services and compiling ros-web-bridge (i.e. npm install) without sourcing my own ros2-package, that contains my custom interfaces.

You have to source your own setup.sh from your ros2 build twice: for build the ros-web-bridge and for running it:

git clone https://github.com/RobotWebTools/ros2-web-bridge  && . ros2_ws/install/setup.sh && cd ros2-web-bridge && npm install
. ros2_ws/install/setup.sh && cd ros2-web-bridge && node bin/rosbridge.js
edit flag offensive delete link more
0

answered 2021-03-15 16:30:01 -0500

ewindes gravatar image

Late suggestion that might help others: set the DEBUG environment variable before starting the ros2-web-bridge to get additional clues to why the service call is failing...

export DEBUG=ros2-web-bridge:*
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-10-13 18:14:29 -0500

Seen: 1,607 times

Last updated: Oct 13 '19