ROSLIBJS - Call service - No Respone
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.
Asked by Tomer Azran on 2019-10-13 18:14:29 UTC
Answers
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
Asked by c.braquet on 2020-09-17 08:12:27 UTC
Comments
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:*
Asked by ewindes on 2021-03-15 16:30:01 UTC
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
(orconsole.error
) is not firing, yes?Asked by Jari on 2019-10-14 15:47:03 UTC
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.
Asked by Tomer Azran on 2019-10-15 01:02:24 UTC
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?
Asked by Jari on 2019-10-15 12:04:53 UTC
I tried to call the same code on global scope - the results are the same.
Asked by Tomer Azran on 2019-10-16 15:12:45 UTC
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.
Asked by Jari on 2019-10-16 17:29:47 UTC