Last active
December 15, 2023 02:48
-
-
Save hamzamerzic/4704bbdc2e0cd46f70e6ebe188ab51ac to your computer and use it in GitHub Desktop.
Revisions
-
hamzamerzic renamed this gist
Mar 6, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
hamzamerzic renamed this gist
Mar 6, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
hamzamerzic revised this gist
Dec 29, 2016 . 1 changed file with 26 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,19 +1,21 @@ #include <ros/callback_queue.h> #include <ros/ros.h> #include <boost/thread.hpp> /* * @brief A spinner thread to force ros to spinOnce() and therefore ros services/callbacks to * get invoked etc. */ class Spinner { public: Spinner() : _run(true), _thread(boost::bind(&Spinner::spin, this)) { } ~Spinner() { _run = false; _thread.join(); } void spin() { ros::NodeHandle nh; ros::WallDuration timeout(0.1f); @@ -24,8 +26,26 @@ class Spinner { ros::spinOnce(); // For proper services cleanup. } private: bool _run; boost::thread _thread; }; /*----- Different way -----*/ #include <ros/ros.h> #include <boost/thread.hpp> void spinThread() { ros::spin(); } int main(int argc, char** argv) { boost::thread spin_thread(&spinThread); // Some work... ros::shutdown(); spin_thread.join(); return 0; } -
hamzamerzic revised this gist
Dec 29, 2016 . 1 changed file with 7 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,12 @@ class Spinner { public: Spinner() : _run(true), _thread(std::bind(&Spinner::spin, this)) { } ~Spinner() { _run = false; _thread.join(); } void spin() { ros::NodeHandle nh; ros::WallDuration timeout(0.1f); @@ -19,12 +24,7 @@ class Spinner { ros::spinOnce(); // For proper services cleanup. } private: bool _run; std::thread _thread; -
hamzamerzic revised this gist
Dec 29, 2016 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,26 +6,26 @@ */ class Spinner { public: Spinner() : _run(true), _thread(std::bind(&Spinner::spin, this)) { } void spin() { ros::NodeHandle nh; ros::WallDuration timeout(0.1f); ros::CallbackQueue* queue = ros::getGlobalCallbackQueue(); while (nh.ok() && _run) queue->callAvailable(timeout); ros::spinOnce(); // For proper services cleanup. } void terminate() { _run = false; _thread.join(); } private: bool _run; std::thread _thread; }; -
hamzamerzic revised this gist
Dec 29, 2016 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,8 @@ * @brief A spinner thread to force ros to spinOnce() and therefore ros services/callbacks to * get invoked etc. */ class Spinner { public: Spinner() : run(true), _thread(std::bind(&Spinner::spin, this)) { } -
hamzamerzic created this gist
Dec 29, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ #include <ros/callback_queue.h> /* * @brief A spinner thread to force ros to spinOnce() and therefore ros services/callbacks to * get invoked etc. */ struct Spinner { Spinner() : run(true), _thread(std::bind(&Spinner::spin, this)) { } void spin() { ros::NodeHandle nh; ros::WallDuration timeout(0.1f); ros::CallbackQueue* queue = ros::getGlobalCallbackQueue(); while (nh.ok() && run) queue->callAvailable(timeout); ros::spinOnce(); // For proper services cleanup. } void terminate() { run = false; _thread.join(); } private: bool run; std::thread _thread; };