/*****************************************************************************
** Includes
*****************************************************************************/
#include <nodelet/nodelet.h>
#include <pluginlib/class_list_macros.h>
#include <ecl/threads/thread.hpp>
#include "kobuki_node/kobuki_ros.hpp"
namespace kobuki
{
class KobukiNodelet : public nodelet::Nodelet
{
public:
KobukiNodelet() : shutdown_requested_(false) {};
~KobukiNodelet()
{
NODELET_DEBUG_STREAM("Kobuki : waiting for update thread to finish.");
shutdown_requested_ = true;
update_thread_.join();
}
virtual void onInit()
{
NODELET_DEBUG_STREAM("Kobuki : initialising nodelet...");
std::string nodelet_name = this->getName();
kobuki_.reset(new KobukiRos(nodelet_name));
// if there are latency issues with callbacks, we might want to move to process callbacks in multiple threads (use MTPrivateNodeHandle)
if (kobuki_->init(this->getPrivateNodeHandle(), this->getNodeHandle()))
{
update_thread_.start(&KobukiNodelet::update, *this);
NODELET_INFO_STREAM("Kobuki : initialised.");
}
else
{
NODELET_ERROR_STREAM("Kobuki : could not initialise! Please restart.");
}
}
private:
void update()
{
ros::Rate spin_rate(10);
while (!shutdown_requested_ && ros::ok() && kobuki_->update())
{
spin_rate.sleep();
}
}
boost::shared_ptr<KobukiRos> kobuki_;
ecl::Thread update_thread_;
bool shutdown_requested_;
};
} // namespace kobuki
PLUGINLIB_EXPORT_CLASS(kobuki::KobukiNodelet, nodelet::Nodelet);
Kuboki nodelet
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.