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.
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 node_handle_; private: ros::ServiceClient* client_; public: ROSHandler() { client_ = new ros::ServiceClient ("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