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.
- Open connection
- 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.
- Compile
- Click Button #1
- Click Button #2
- Wait for a while (longer than 30 sec)
- Click Button #2
I put simplified version of my code.
// ROSHandler class class ROSHandler { protected: ros::NodeHandle node_handle_; private: ros::ServiceClient<request, response="">* client_; public: ROSHandler() { client_ = new ros::ServiceClient<request, response="">("TOPIC_NAME"); node_handle_.serviceClient(*client_); } ~ROSHandler(); bool Connect() { node_handle_.initNode(MASTER_IP); while (!node_handle_.connected()) { node_handle_.spinOnce(); } return (node_handle_.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