From 9386bc2299e96ef3556d5351f0a920c60a320f06 Mon Sep 17 00:00:00 2001 From: Sergi Hernandez Juan <shernand@iri.upc.edu> Date: Mon, 13 Jul 2020 12:32:47 +0200 Subject: [PATCH] Added a new spin function (nodelet_spin) to be used in nodelets where the ros::spin function is not required. --- .../iri_base_algorithm/iri_base_algorithm.h | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/include/iri_base_algorithm/iri_base_algorithm.h b/include/iri_base_algorithm/iri_base_algorithm.h index 2953659..b9f8be2 100644 --- a/include/iri_base_algorithm/iri_base_algorithm.h +++ b/include/iri_base_algorithm/iri_base_algorithm.h @@ -152,6 +152,8 @@ class IriBaseAlgorithm */ int spin(void); + int nodelet_spin(void); + private: /** * \brief ros spin thread @@ -380,6 +382,35 @@ int IriBaseAlgorithm<Algorithm>::spin(void) return 0; } +template <class Algorithm> +int IriBaseAlgorithm<Algorithm>::nodelet_spin(void) +{ + ROS_DEBUG("IriBaseAlgorithm::spin"); + + // initialize diagnostics + this->diagnostic_.setHardwareID("none"); + this->addDiagnostics(); + + // assign callback to dynamic reconfigure server + this->dsrv_.setCallback(boost::bind(&IriBaseAlgorithm<Algorithm>::reconfigureCallback, this, _1, _2)); + + // create the status thread + pthread_create(&this->thread,NULL,this->mainThread,this); + + while(ros::ok()) + { + // update diagnostics + this->diagnostic_.update(); + + ros::WallDuration(this->diagnostic_.getPeriod()).sleep(); + } + + // stop ros + ros::shutdown(); + + return 0; +} + // definition of the static Ctrl+C counter /** -- GitLab