camera_driver.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <libuvc/libuvc.h>
4 
5 #include <ros/ros.h>
8 #include <dynamic_reconfigure/server.h>
10 #include <boost/thread/mutex.hpp>
11 #include <sensor_msgs/CameraInfo.h>
12 #include <astra_camera/GetUVCExposure.h>
13 #include <astra_camera/SetUVCExposure.h>
14 #include <astra_camera/GetUVCGain.h>
15 #include <astra_camera/SetUVCGain.h>
16 #include <astra_camera/GetUVCWhiteBalance.h>
17 #include <astra_camera/SetUVCWhiteBalance.h>
19 #include <astra_camera/UVCCameraConfig.h>
20 
21 #include <string>
22 
23 namespace libuvc_camera {
24 
25 class CameraDriver {
26 public:
28  ~CameraDriver();
29 
30  bool Start();
31  void Stop();
32 
33 private:
34  enum State {
35  kInitial = 0,
36  kStopped = 1,
37  kRunning = 2,
38  };
39 
40  // Flags controlling whether the sensor needs to be stopped (or reopened) when changing settings
41  static const int kReconfigureClose = 3; // Need to close and reopen sensor to change this setting
42  static const int kReconfigureStop = 1; // Need to stop the stream before changing this setting
43  static const int kReconfigureRunning = 0; // We can change this setting without stopping the stream
44 
45  void OpenCamera(UVCCameraConfig &new_config);
46  void CloseCamera();
47 
48  // Accept a reconfigure request from a client
49  void ReconfigureCallback(UVCCameraConfig &config, uint32_t level);
50  enum uvc_frame_format GetVideoMode(std::string vmode);
51  // Accept changes in values of automatically updated controls
52  void AutoControlsCallback(enum uvc_status_class status_class,
53  int event,
54  int selector,
55  enum uvc_status_attribute status_attribute,
56  void *data, size_t data_len);
57  static void AutoControlsCallbackAdapter(enum uvc_status_class status_class,
58  int event,
59  int selector,
60  enum uvc_status_attribute status_attribute,
61  void *data, size_t data_len,
62  void *ptr);
63  // Accept a new image frame from the camera
64  void ImageCallback(uvc_frame_t *frame);
65  static void ImageCallbackAdapter(uvc_frame_t *frame, void *ptr);
66  bool getUVCExposureCb(astra_camera::GetUVCExposureRequest& req, astra_camera::GetUVCExposureResponse& res);
67  bool setUVCExposureCb(astra_camera::SetUVCExposureRequest& req, astra_camera::SetUVCExposureResponse& res);
68  bool getUVCGainCb(astra_camera::GetUVCGainRequest& req, astra_camera::GetUVCGainResponse& res);
69  bool setUVCGainCb(astra_camera::SetUVCGainRequest& req, astra_camera::SetUVCGainResponse& res);
70  bool getUVCWhiteBalanceCb(astra_camera::GetUVCWhiteBalanceRequest& req, astra_camera::GetUVCWhiteBalanceResponse& res);
71  bool setUVCWhiteBalanceCb(astra_camera::SetUVCWhiteBalanceRequest& req, astra_camera::SetUVCWhiteBalanceResponse& res);
72 
74 
76  boost::recursive_mutex mutex_;
77 
78  uvc_context_t *ctx_;
79  uvc_device_t *dev_;
80  uvc_device_handle_t *devh_;
81  uvc_frame_t *rgb_frame_;
82 
85 
86  dynamic_reconfigure::Server<UVCCameraConfig> config_server_;
87  UVCCameraConfig config_;
89 
91  std::string ns;
92  std::string ns_no_slash;
93 
100 
103 
106  std::string device_type_;
107  sensor_msgs::CameraInfo camera_info_;
111 };
112 
113 };
boost::recursive_mutex mutex_
Definition: camera_driver.h:76
ros::ServiceServer set_uvc_exposure_server
Definition: camera_driver.h:95
static void ImageCallbackAdapter(uvc_frame_t *frame, void *ptr)
enum uvc_frame_format GetVideoMode(std::string vmode)
static const int kReconfigureRunning
Definition: camera_driver.h:43
bool getUVCExposureCb(astra_camera::GetUVCExposureRequest &req, astra_camera::GetUVCExposureResponse &res)
ros::ServiceServer get_uvc_gain_server
Definition: camera_driver.h:96
bool setUVCGainCb(astra_camera::SetUVCGainRequest &req, astra_camera::SetUVCGainResponse &res)
ros::ServiceServer get_uvc_white_balance_server
Definition: camera_driver.h:98
bool setUVCExposureCb(astra_camera::SetUVCExposureRequest &req, astra_camera::SetUVCExposureResponse &res)
static void AutoControlsCallbackAdapter(enum uvc_status_class status_class, int event, int selector, enum uvc_status_attribute status_attribute, void *data, size_t data_len, void *ptr)
ros::ServiceClient camera_info_client
static const int kReconfigureStop
Definition: camera_driver.h:42
image_transport::ImageTransport it_
Definition: camera_driver.h:83
ros::ServiceServer set_uvc_white_balance_server
Definition: camera_driver.h:99
sensor_msgs::CameraInfo camera_info_
dynamic_reconfigure::Server< UVCCameraConfig > config_server_
Definition: camera_driver.h:86
ros::ServiceServer get_uvc_exposure_server
Definition: camera_driver.h:94
void ReconfigureCallback(UVCCameraConfig &config, uint32_t level)
void ImageCallback(uvc_frame_t *frame)
bool getUVCGainCb(astra_camera::GetUVCGainRequest &req, astra_camera::GetUVCGainResponse &res)
bool setUVCWhiteBalanceCb(astra_camera::SetUVCWhiteBalanceRequest &req, astra_camera::SetUVCWhiteBalanceResponse &res)
OB_DEVICE_NO
ros::ServiceClient device_type_client
bool getUVCWhiteBalanceCb(astra_camera::GetUVCWhiteBalanceRequest &req, astra_camera::GetUVCWhiteBalanceResponse &res)
void OpenCamera(UVCCameraConfig &new_config)
image_transport::CameraPublisher cam_pub_
Definition: camera_driver.h:84
camera_info_manager::CameraInfoManager cinfo_manager_
Definition: camera_driver.h:90
void AutoControlsCallback(enum uvc_status_class status_class, int event, int selector, enum uvc_status_attribute status_attribute, void *data, size_t data_len)
unsigned int uint32_t
ros::ServiceServer set_uvc_gain_server
Definition: camera_driver.h:97
static const int kReconfigureClose
Definition: camera_driver.h:41
CameraDriver(ros::NodeHandle nh, ros::NodeHandle priv_nh)
uvc_device_handle_t * devh_
Definition: camera_driver.h:80


astra_camera
Author(s): Tim Liu
autogenerated on Wed Dec 16 2020 03:54:34