freenect_driver.hpp
Go to the documentation of this file.
1 #ifndef FREENECT_DRIVER_K8EEAIBB
2 #define FREENECT_DRIVER_K8EEAIBB
3 
4 #include <libfreenect/libfreenect.h>
6 
8 
9  class FreenectDriver {
10 
11  public:
12 
13 
15  static FreenectDriver instance(subdevs);
16  return instance;
17  }
18 
20  static FreenectDriver instance;
21  return instance;
22  }
23  void shutdown() {
24  thread_running_ = false;
25  freenect_thread_->join();
26  if (device_)
27  device_->shutdown();
28  device_.reset();
30  }
31 
33  device_serials_.clear();
34  freenect_device_attributes* attr_list;
37  for (item = attr_list; item != NULL; item = item->next) {
38  device_serials_.push_back(std::string(item->camera_serial));
39  }
41  }
42 
43  unsigned getNumberDevices() {
44  return device_serials_.size();
45  }
46 
48  unsigned getBus(unsigned device_idx) {
49  return 0;
50  }
51 
53  unsigned getAddress(unsigned device_idx) {
54  return 0;
55  }
56 
57  const char* getProductName(unsigned device_idx) {
58  return PRODUCT_NAME.c_str();
59  }
60 
61  unsigned getProductID(unsigned device_idx) {
62  return PRODUCT_ID;
63  }
64 
65  const char* getVendorName(unsigned device_idx) {
66  return VENDOR_NAME.c_str();
67  }
68 
69  unsigned getVendorID(unsigned device_idx) {
70  return VENDOR_ID;
71  }
72 
73  const char* getSerialNumber(unsigned device_idx) {
74  if (device_idx < getNumberDevices())
75  return device_serials_[device_idx].c_str();
76  throw std::runtime_error("libfreenect: device idx out of range");
77  }
78 
80  return getDeviceBySerialNumber(std::string(getSerialNumber(device_idx)));
81  }
82 
84  device_.reset(new FreenectDevice(driver_, serial));
85  // start freenect thread now that we have device
86  thread_running_ = true;
87  freenect_thread_.reset(new boost::thread(boost::bind(&FreenectDriver::process, this)));
88  return device_;
89  }
90 
91  boost::shared_ptr<FreenectDevice> getDeviceByAddress(unsigned bus, unsigned address) {
92  throw std::runtime_error("[ERROR] libfreenect does not support searching for device by bus/address");
93  }
94 
95  void process() {
96  while (thread_running_) {
97  timeval t;
98  t.tv_sec = 0;
99  t.tv_usec = 10000;
101  throw std::runtime_error("freenect_process_events error");
102  if (device_)
103  device_->executeChanges();
104  }
105  }
106 
107  void enableDebug() {
109  }
110 
111  private:
113  freenect_init(&driver_, NULL); //init driver_ handle
114  freenect_set_log_level(driver_, FREENECT_LOG_FATAL); // Prevent's printing stuff to the screen
116  thread_running_ = false;
118  }
119  //add support for select subdevs such as motor or audio
121  freenect_init(&driver_, NULL); //init driver_ handle
122  freenect_set_log_level(driver_, FREENECT_LOG_FATAL); // Prevent's printing stuff to the screen
123  //open camera as default if not select any subdevs
125  {
126  ROS_INFO("Did not select any subdevs,open AUDIO as default.\n");
128  }
130  thread_running_ = false;
131  subdevs_=subdevs;
132  }
134  std::vector<std::string> device_serials_;
139  };
140 
141 }
142 
143 #endif /* end of include guard: FREENECT_DRIVER_K8EEAIBB */
FREENECTAPI void freenect_select_subdevices(freenect_context *ctx, freenect_device_flags subdevs)
FREENECT_LOG_FATAL
static const unsigned PRODUCT_ID
boost::shared_ptr< FreenectDevice > device_
boost::shared_ptr< FreenectDevice > getDeviceByAddress(unsigned bus, unsigned address)
boost::shared_ptr< boost::thread > freenect_thread_
FREENECT_LOG_SPEW
FREENECTAPI void freenect_set_log_level(freenect_context *ctx, freenect_loglevel level)
FREENECTAPI int freenect_process_events_timeout(freenect_context *ctx, struct timeval *timeout)
static const unsigned VENDOR_ID
std::vector< std::string > device_serials_
FREENECTAPI int freenect_init(freenect_context **ctx, freenect_usb_context *usb_ctx)
FREENECT_DEVICE_MOTOR
FreenectDriver(freenect_device_flags subdevs)
unsigned getVendorID(unsigned device_idx)
FREENECTAPI int freenect_shutdown(freenect_context *ctx)
boost::shared_ptr< FreenectDevice > getDeviceByIndex(unsigned device_idx)
#define ROS_INFO(...)
unsigned getBus(unsigned device_idx)
static FreenectDriver & getInstance(freenect_device_flags subdevs)
FREENECTAPI int freenect_list_device_attributes(freenect_context *ctx, struct freenect_device_attributes **attribute_list)
FREENECT_DEVICE_AUDIO
static const std::string PRODUCT_NAME
boost::shared_ptr< FreenectDevice > getDeviceBySerialNumber(std::string serial)
const char * getSerialNumber(unsigned device_idx)
struct freenect_device_attributes * next
FREENECT_DEVICE_CAMERA
FREENECTAPI void freenect_free_device_attributes(struct freenect_device_attributes *attribute_list)
const char * getProductName(unsigned device_idx)
unsigned getAddress(unsigned device_idx)
freenect_device_flags
const char * getVendorName(unsigned device_idx)
unsigned getProductID(unsigned device_idx)
static const std::string VENDOR_NAME


xiaoqiang_freenect_camera
Author(s): Patrick Mihelich, Suat Gedikli, Radu Bogdan Rusu (original openni_camera driver)., Piyush Khandelwal (libfreenect port).
autogenerated on Mon Jun 10 2019 15:53:18