Robotics StackExchange | Archived questions

rosserial_windows packet loss while sending data to service server on ROS

Hi,

I have a question about rosserial windows.

I made a Windows application which has two buttons as below.

  1. Open connection
  2. Send data to Service Server - which is Service client

In constructor of the dialog, I assigned ServiceClient pointer to node handle.
When I click Button #1, it should init node handle by calling initNode function and call spinOnce function.
When I click Button #2, it should call Call function to send data to ServiceServer and receive response.


My test was as shown below.

  1. Compile
  2. Click Button #1
  3. Click Button #2
  4. Wait for a while (longer than 30 sec)
  5. Click Button #2

I put simplified version of my code.

// ROSHandler class
class ROSHandler {
    protected:
        ros::NodeHandle nodehandle;
    private:
       ros::ServiceClient* client;
    public:
        ROSHandler() {
            client = new ros::ServiceClient("TOPICNAME");
            nodehandle.serviceClient(*client);
        }
        ~ROSHandler();
        bool Connect() {
            nodehandle.initNode(MASTERIP);
            while (!nodehandle.connected())
            {
                nodehandle.spinOnce();
            }
            return (nodehandle_.spinOnce() == 0);
        }
        bool Send() {
            Request req;
            Response res;
            // set values in req

        if (!node_handle_.connected()) {
            Connect();
        }

        client_->call(request, response);
        node_handle_.spinOnce();
        return response_.result; // return boolean
    }

};

void OnClickButton1 {
    Connect(); // connect function above
}

void OnClickButton2 { Send(); // send function above }

Thanks! :D

Asked by _nobot.enter on 2017-10-16 11:56:33 UTC

Comments

Answers