Skip to content

Instantly share code, notes, and snippets.

@universax
Last active February 2, 2019 09:47
Show Gist options
  • Save universax/3f61dc0f95f32b9e2b8729ffe0a1221a to your computer and use it in GitHub Desktop.
Save universax/3f61dc0f95f32b9e2b8729ffe0a1221a to your computer and use it in GitHub Desktop.
Start VLP16 grabber example
// VLP16.h
// Grabber Instance
boost::shared_ptr<pcl::VLPGrabber> mVlpGrabber;
// Connection instance for open and close
boost::signals2::connection mConnection;
// Save point cloud data into this pointer
pcl::PointCloud<PointType>::ConstPtr mCloud;
// Mutex
boost::mutex mVLPMutex;
// VLP16.cpp
void VLP16::Start(string ipAddress, unsigned short port){
// New grabber
mVlpGrabber = boost::shared_ptr<pcl::VLPGrabber>(new pcl::VLPGrabber(boost::asio::ip::address::from_string(ipAddress), boost::lexical_cast<unsigned short>(port)));
// Set callback and connection
boost::function<void(const pcl::PointCloud<PointType>::ConstPtr&)> cb = boost::bind(&VLP16::vlpCallback, this, _1);
mConnection = mVlpGrabber->registerCallback(cb);
// Start :)
mVlpGrabber->start();
}
//Callback
void VLP16::vlpCallback(const pcl::PointCloud<PointType>::ConstPtr& cloudPtr)
{
// Lock and Copy
boost::mutex::scoped_lock lock(mVLPMutex);
mCloud = cloudPtr;
}
void VLP16::Close()
{
mVlpGrabber->stop();
mConnection.disconnect();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment