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.
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?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.
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?
I tried to call the same code on global scope - the results are the same.
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.