From ae3a9a35ace33e7f8efa4c0091c479461038fcb5 Mon Sep 17 00:00:00 2001 From: Romain Reignier Date: Wed, 5 Sep 2018 11:42:37 +0200 Subject: [PATCH 1/4] Delete QtCreator file in LoopbackTest --- test/LoopbackTest/LoopbackTest.pro.user | 336 ------------------------ 1 file changed, 336 deletions(-) delete mode 100644 test/LoopbackTest/LoopbackTest.pro.user diff --git a/test/LoopbackTest/LoopbackTest.pro.user b/test/LoopbackTest/LoopbackTest.pro.user deleted file mode 100644 index 2f0b63e..0000000 --- a/test/LoopbackTest/LoopbackTest.pro.user +++ /dev/null @@ -1,336 +0,0 @@ - - - - - - EnvironmentId - {879e81b6-cba8-47ee-9e58-98b9c532cb3d} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - - - ProjectExplorer.Project.Target.0 - - Desktop - Desktop - {4dd4c15a-e3fc-4f28-ad62-08eacb8bfbf3} - 0 - 0 - 0 - - /home/robin/rosserial/ws/src/rosserial_qt/test/build-LoopbackTest-Desktop-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - /home/robin/rosserial/ws/src/rosserial_qt/test/build-LoopbackTest-Desktop-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - /home/robin/rosserial/ws/src/rosserial_qt/test/build-LoopbackTest-Desktop-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - LoopbackTest - - Qt4ProjectManager.Qt4RunConfiguration:/home/robin/rosserial/ws/src/rosserial_qt/test/LoopbackTest/LoopbackTest.pro - true - - LoopbackTest.pro - false - - /home/robin/rosserial/ws/src/rosserial_qt/test/build-LoopbackTest-Desktop-Debug - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 18 - - - Version - 18 - - From 2cb51daa27ed6e8cecf9ab54a704a801b97eb93f Mon Sep 17 00:00:00 2001 From: Romain Reignier Date: Wed, 5 Sep 2018 10:30:51 +0200 Subject: [PATCH 2/4] Handle the new service client call result values and add a new call method to get failed call reason --- src/ros_lib/ros/service_client.h | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/ros_lib/ros/service_client.h b/src/ros_lib/ros/service_client.h index b6169ee..b62c944 100644 --- a/src/ros_lib/ros/service_client.h +++ b/src/ros_lib/ros/service_client.h @@ -1,4 +1,4 @@ -/* +/* * Software License Agreement (BSD License) * * Copyright (c) 2011, Willow Garage, Inc. @@ -36,6 +36,7 @@ #define ROS_SERVICE_CLIENT_H_ #include +#include "rosserial_msgs/ServiceCallResult.h" #include "rosserial_msgs/TopicInfo.h" #include "ros/publisher.h" @@ -50,15 +51,16 @@ namespace ros { typedef typename MType::Request MReq; typedef typename MType::Response MRes; typedef std::function CallbackT; + typedef std::function CallbackWithResultT; - ServiceClient(const char* topic_name) : + ServiceClient(const char* topic_name) : pub(topic_name, rosserial_msgs::TopicInfo::ID_SERVICE_CLIENT + rosserial_msgs::TopicInfo::ID_PUBLISHER) { this->topic_ = topic_name; this->waiting = false; } - void call(const MReq & request, CallbackT callback) + void call(const MReq& request, CallbackT callback) { if(!pub.nh_->connected()) return; waiting = true; @@ -66,8 +68,16 @@ namespace ros { pub.publish(request); } - const std::string & getMsgType() override { return MRes::getType(); } - const std::string & getMsgMD5() override { return MRes::getMD5(); } + void call(const MReq& request, CallbackWithResultT callback) + { + if(!pub.nh_->connected()) return; + waiting = true; + cbWithResult_ = callback; + pub.publish(request); + } + + const std::string& getMsgType() override { return MRes::getType(); } + const std::string& getMsgMD5() override { return MRes::getMD5(); } int getEndpointType() override{ return rosserial_msgs::TopicInfo::ID_SERVICE_CLIENT + rosserial_msgs::TopicInfo::ID_SUBSCRIBER; } private: @@ -75,23 +85,33 @@ namespace ros { void callback(unsigned char *data) override{ MRes ret; // First byte give us the success status - bool success = data[0]; + const uint8_t callResult = data[0]; + const bool success = callResult == rosserial_msgs::ServiceCallResult::SUCCESS; if(success) { // Access from the second byte ret.deserialize(data+1); } + waiting = false; + if(cb_) { cb_(ret, success); } + else if(cbWithResult_) + { + cbWithResult_(ret, success, callResult); + } + cb_ = nullptr; + cbWithResult_ = nullptr; } bool waiting; CallbackT cb_; + CallbackWithResultT cbWithResult_; public: Publisher pub; From e9202fe2d8c016879436d5a8216dfdf357b5e43a Mon Sep 17 00:00:00 2001 From: Romain Reignier Date: Wed, 5 Sep 2018 11:43:13 +0200 Subject: [PATCH 3/4] Update Basic test to reflect service client API changes --- test/Basic/node.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/test/Basic/node.cpp b/test/Basic/node.cpp index bfb46a0..77a4a9c 100644 --- a/test/Basic/node.cpp +++ b/test/Basic/node.cpp @@ -1,5 +1,6 @@ #include "node.h" #include +#include Node::Node(): chatter("chatter"), @@ -43,9 +44,19 @@ void Node::onTimer() chatter.publish(str_msg); roscpp::GetLoggersRequest req; - serviceClient.call(req, [](const roscpp::GetLoggers::Response &loggers){ - std::cout << "loggers : " << QJsonDocument(loggers.serializeAsJson()).toJson(QJsonDocument::Indented).toStdString() << std::endl; - + serviceClient.call(req, [this](const roscpp::GetLoggers::Response &loggers, bool ok, uint8_t callResult){ + switch(callResult) + { + case rosserial_msgs::ServiceCallResult::NO_EXISTENCE: + std::cout << "Service " << serviceClient.topic_ << " does not exist" << std::endl; + break; + case rosserial_msgs::ServiceCallResult::CALL_FAILED: + std::cout << "Call to service " << serviceClient.topic_ << " failed" << std::endl; + break; + case rosserial_msgs::ServiceCallResult::SUCCESS: + std::cout << "loggers : " << QJsonDocument(loggers.serializeAsJson()).toJson(QJsonDocument::Indented).toStdString() << std::endl; + break; + } }); } From 5a2521275951d2f292e4dbfb16c13cb24e47c36a Mon Sep 17 00:00:00 2001 From: Romain Reignier Date: Wed, 7 Nov 2018 18:02:45 +0100 Subject: [PATCH 4/4] Modify Basic example to use both service call APIs --- test/Basic/node.cpp | 46 ++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/test/Basic/node.cpp b/test/Basic/node.cpp index 77a4a9c..05925ac 100644 --- a/test/Basic/node.cpp +++ b/test/Basic/node.cpp @@ -44,20 +44,40 @@ void Node::onTimer() chatter.publish(str_msg); roscpp::GetLoggersRequest req; - serviceClient.call(req, [this](const roscpp::GetLoggers::Response &loggers, bool ok, uint8_t callResult){ - switch(callResult) - { - case rosserial_msgs::ServiceCallResult::NO_EXISTENCE: - std::cout << "Service " << serviceClient.topic_ << " does not exist" << std::endl; - break; - case rosserial_msgs::ServiceCallResult::CALL_FAILED: - std::cout << "Call to service " << serviceClient.topic_ << " failed" << std::endl; + + if(i % 2 == 0) + { + std::cout << "Service client call with bool and uint8_t results API" << std::endl; + serviceClient.call(req, [this](const roscpp::GetLoggers::Response &loggers, bool ok, uint8_t callResult){ + (void)ok; + switch(callResult) + { + case rosserial_msgs::ServiceCallResult::NO_EXISTENCE: + std::cout << "Service " << serviceClient.topic_ << " does not exist" << std::endl; + break; + case rosserial_msgs::ServiceCallResult::CALL_FAILED: + std::cout << "Call to service " << serviceClient.topic_ << " failed" << std::endl; + break; + case rosserial_msgs::ServiceCallResult::SUCCESS: + std::cout << "loggers : " << QJsonDocument(loggers.serializeAsJson()).toJson(QJsonDocument::Indented).toStdString() << std::endl; break; - case rosserial_msgs::ServiceCallResult::SUCCESS: - std::cout << "loggers : " << QJsonDocument(loggers.serializeAsJson()).toJson(QJsonDocument::Indented).toStdString() << std::endl; - break; - } - }); + } + }); + } + else + { + std::cout << "Service client call with only bool result API" << std::endl; + serviceClient.call(req, [this](const roscpp::GetLoggers::Response &loggers, bool ok){ + if(ok) + { + std::cout << "loggers : " << QJsonDocument(loggers.serializeAsJson()).toJson(QJsonDocument::Indented).toStdString() << std::endl; + } + else + { + std::cout << "Call to service " << serviceClient.topic_ << " failed" << std::endl; + } + }); + } } void Node::addTwoInts(const roscpp_tutorials::TwoIntsRequest &req, roscpp_tutorials::TwoIntsResponse &res)