roslibjs: Problem with advertising a service

asked 2021-08-30 17:43:51 -0500

T_Stotz gravatar image

Hi everyone, I'm trying to advertise a service using roslibjs. I have written a standard ros node in c++ that's making a call to a service advertised by a web gui using roslibjs. To advertise the service, I did the following:

some_service.advertise(function(request, response){

console.log('Received service request on' + some_service.name + ':' + some_service.data);
// display popup
var popup = document.getElementById('popup_with_button');
popup.style.display = "block";
// find button and set onclick listener
var confirm_btn = document.getElementById('confirm_button');
confirm_btn.onclick = function()
   {
        response['success'] = 0;
        popup.style.display = "none";
        return true;

    };
});

This would display a popup window with a button inside whenever a call is made to the service. My goal is to send the response to this service request as soon as the button inside the popup is clicked. But when I click the button on the pop-up, the advertise function is already executed and the response object remains empty, leaving me with the error message:

service_response: Expected a result field but none was found.

I didn't find any options on how to avoid this, it does seem like i would need to this logic entirely, since I cannot freeze the UI. Does anyone have any idea?

edit retag flag offensive close merge delete