1 #ifndef FREENECT_DEVICE_T01IELX0 2 #define FREENECT_DEVICE_T01IELX0 4 #include <boost/shared_ptr.hpp> 5 #include <boost/noncopyable.hpp> 6 #include <boost/thread/mutex.hpp> 7 #include <boost/date_time/posix_time/ptime.hpp> 10 #include <libfreenect/libfreenect.h> 11 #include <libfreenect/libfreenect_registration.h> 69 ROS_INFO(
"Starting a 3s RGB and Depth stream flush.");
74 throw std::runtime_error(
"[ERROR] Unable to open specified kinect");
106 return PRODUCT_NAME.c_str();
138 throw std::runtime_error(
"[ERROR] The kinect does not support hardware synchronization");
151 void (T::*callback)(
const ImageBuffer& image,
void* cookie),
152 T& instance,
void* cookie = NULL) {
153 image_callback_ = boost::bind(callback, boost::ref(instance), _1, cookie);
157 void (T::*callback)(
const ImageBuffer& depth_image,
void* cookie),
158 T& instance,
void* cookie = NULL) {
159 depth_callback_ = boost::bind(callback, boost::ref(instance), _1, cookie);
163 void (T::*callback)(
const ImageBuffer& ir_image,
void* cookie),
164 T& instance,
void* cookie = NULL) {
165 ir_callback_ = boost::bind(callback, boost::ref(instance), _1, cookie);
175 boost::lock_guard<boost::recursive_mutex> lock(
m_settings_);
180 boost::lock_guard<boost::recursive_mutex> lock(
m_settings_);
195 compatible_mode = mode;
200 boost::lock_guard<boost::recursive_mutex> lock(
m_settings_);
207 boost::lock_guard<boost::recursive_mutex> lock(
m_settings_);
214 boost::lock_guard<boost::recursive_mutex> lock(
m_settings_);
219 boost::lock_guard<boost::recursive_mutex> lock(
m_settings_);
225 boost::lock_guard<boost::recursive_mutex> lock(
m_settings_);
231 boost::lock_guard<boost::recursive_mutex> lock(
m_settings_);
238 boost::lock_guard<boost::recursive_mutex> lock(
m_settings_);
243 boost::lock_guard<boost::recursive_mutex> lock(
m_settings_);
258 compatible_mode = mode;
263 boost::lock_guard<boost::recursive_mutex> lock(
m_settings_);
268 boost::lock_guard<boost::recursive_mutex> lock(
m_settings_);
274 boost::lock_guard<boost::recursive_mutex> lock(
m_settings_);
279 boost::lock_guard<boost::recursive_mutex> lock(
m_settings_);
284 boost::lock_guard<boost::recursive_mutex> lock(
m_settings_);
340 boost::lock_guard<boost::recursive_mutex> lock(m_settings_);
343 bool stop_device_flush =
false;
345 if (device_flush_enabled_) {
347 boost::posix_time::ptime current_time =
348 boost::posix_time::microsec_clock::local_time();
349 if ((current_time - device_flush_start_time_).total_milliseconds() > 3000) {
350 device_flush_enabled_ =
false;
351 stop_device_flush =
true;
352 ROS_INFO(
"Stopping device RGB and Depth stream flush.");
356 bool change_video_settings =
360 device_flush_enabled_ && !streaming_video_ ||
363 if (change_video_settings) {
366 if (streaming_video_) {
369 streaming_video_ =
false;
377 new_video_resolution_, registration_);
378 }
catch (std::runtime_error& e) {
379 printf(
"[ERROR] Unsupported video format/resolution provided. %s\n",
381 printf(
"[INFO] Setting default settings (RGB/VGA)\n");
391 if (should_stream_video_ || device_flush_enabled_) {
394 streaming_video_ =
true;
401 bool change_depth_settings =
405 device_flush_enabled_ && !streaming_depth_ ||
408 if (change_depth_settings) {
411 if (streaming_depth_) {
414 streaming_depth_ =
false;
422 new_depth_resolution_, registration_);
423 }
catch (std::runtime_error& e) {
424 printf(
"[ERROR] Unsupported depth format/resolution provided. %s\n",
426 printf(
"[INFO] Setting default settings (depth registered/VGA)\n");
436 if (should_stream_depth_ || device_flush_enabled_) {
439 streaming_depth_ =
true;
446 boost::lock_guard<boost::recursive_mutex> lock(m_settings_);
451 boost::lock_guard<boost::mutex> buffer_lock(depth_buffer_.
mutex);
453 if (publishers_ready_) {
459 boost::lock_guard<boost::mutex> buffer_lock(video_buffer_.
mutex);
461 if (publishers_ready_) {
void allocateBufferDepth(ImageBuffer &buffer, const freenect_depth_format &format, const freenect_resolution &resolution, const freenect_registration ®istration)
std::string device_serial_
bool isSynchronized() const
FREENECTAPI int freenect_destroy_registration(freenect_registration *reg)
int freenect_set_depth_buffer(freenect_device *dev, void *buf)
void allocateBufferVideo(ImageBuffer &buffer, const freenect_video_format &format, const freenect_resolution &resolution, const freenect_registration ®istration)
float getBaseline() const
unsigned getAddress() const
freenect_zero_plane_info zero_plane_info
static const unsigned PRODUCT_ID
void flushDeviceStreams()
FreenectDevice(freenect_context *driver, std::string serial)
FREENECT_RESOLUTION_DUMMY
void freenect_set_video_callback(freenect_device *dev, freenect_video_cb cb)
bool isDepthRegistrationSupported() const
freenect_resolution new_video_resolution_
int freenect_start_video(freenect_device *dev)
bool hasImageStream() const
freenect_context * driver_
boost::posix_time::ptime device_flush_start_time_
OutputMode getImageOutputMode()
freenect_video_format new_video_format_
freenect_device * device_
bool device_flush_enabled_
freenect_resolution new_depth_resolution_
bool isImageStreamRunning()
int freenect_stop_video(freenect_device *dev)
void openDevice(freenect_context *driver, std::string serial)
const char * getProductName() const
void depthCallback(void *depth)
bool hasDepthStream() const
void setDepthOutputMode(OutputMode mode)
void registerImageCallback(void(T::*callback)(const ImageBuffer &image, void *cookie), T &instance, void *cookie=NULL)
const char * getSerialNumber() const
Holds an image buffer with all the metadata required to transmit the image over ROS channels...
int freenect_set_depth_mode(freenect_device *dev, const freenect_frame_mode mode)
int freenect_set_video_mode(freenect_device *dev, const freenect_frame_mode mode)
static const unsigned VENDOR_ID
bool setSynchronization(bool on_off) const
freenect_frame_mode freenect_find_video_mode(freenect_resolution res, freenect_video_format fmt)
boost::function< void(const ImageBuffer &)> ir_callback_
ImageBuffer video_buffer_
freenect_resolution OutputMode
void setImageOutputMode(OutputMode mode)
bool findCompatibleImageMode(const OutputMode &mode, OutputMode &compatible_mode) const
FREENECTAPI freenect_registration freenect_copy_registration(freenect_device *dev)
FREENECTAPI int freenect_open_device_by_camera_serial(freenect_context *ctx, freenect_device **dev, const char *camera_serial)
int freenect_set_video_buffer(freenect_device *dev, void *buf)
FREENECTAPI freenect_device_flags freenect_enabled_subdevices(freenect_context *ctx)
void videoCallback(void *video)
boost::recursive_mutex m_settings_
freenect_depth_format new_depth_format_
OutputMode getDefaultDepthMode() const
MyFreenectDevice * device
bool should_stream_video_
void setDepthRegistration(bool enable)
bool isDepthStreamRunning()
freenect_frame_mode freenect_find_depth_mode(freenect_resolution res, freenect_depth_format fmt)
bool should_stream_depth_
bool findCompatibleDepthMode(const OutputMode &mode, OutputMode &compatible_mode) const
boost::shared_array< unsigned char > image_buffer
static const std::string PRODUCT_NAME
void registerDepthCallback(void(T::*callback)(const ImageBuffer &depth_image, void *cookie), T &instance, void *cookie=NULL)
FREENECTAPI void * freenect_get_user(freenect_device *dev)
ImageBuffer depth_buffer_
bool isImageMode(const ImageBuffer &buffer)
void registerIRCallback(void(T::*callback)(const ImageBuffer &ir_image, void *cookie), T &instance, void *cookie=NULL)
freenect_registration registration_
freenect_frame_mode metadata
int freenect_start_depth(freenect_device *dev)
FREENECT_RESOLUTION_MEDIUM
OutputMode getDepthOutputMode()
boost::function< void(const ImageBuffer &)> depth_callback_
bool isSynchronizationSupported() const
OutputMode getDefaultImageMode() const
int freenect_stop_depth(freenect_device *dev)
static void freenectVideoCallback(freenect_device *dev, void *video, uint32_t timestamp)
boost::function< void(const ImageBuffer &)> image_callback_
FREENECTAPI void freenect_set_user(freenect_device *dev, void *user)
freenect_resolution resolution
void publishersAreReady()
freenect_depth_format depth_format
FREENECT_DEPTH_REGISTERED
static void freenectDepthCallback(freenect_device *dev, void *depth, uint32_t timestamp)
void freenect_set_depth_callback(freenect_device *dev, freenect_depth_cb cb)
FREENECTAPI int freenect_close_device(freenect_device *dev)
bool _isImageModeEnabled()
freenect_video_format video_format
static const std::string VENDOR_NAME