Main MRPT website > C++ reference
MRPT logo
CSwissRanger3DCamera.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef CSwissRanger3DCamera_H
29 #define CSwissRanger3DCamera_H
30 
34 
36 
38 
39 namespace mrpt
40 {
41  namespace hwdrivers
42  {
43  /** A class for grabing "range images" from a MESA imaging SwissRanger 3D cameras (SR-2, SR-3000, SR-4k).
44  *
45  * NOTES:
46  * - This class requires a vendor specific driver installed in the system in order to build MRPT with support for this sensor. Download and install the driver from: http://www.mesa-imaging.ch/drivers.php
47  * - The intensity channel (grayscale image) is converted from 16bit to standard 8bit-per-pixel using a logarithmic, modified A-law compression. This allows exploiting the full dynamic range of the sensor and provides quite good results.
48  *
49  * As with any other CGenericSensor class, the normal sequence of methods to be called is:
50  * - loadConfig() - Or calls to the individual setXXX() to configure the camera parameters.
51  * - initialize() - to init the comms with the camera
52  * - call getNextObservation() for getting the frames.
53  *
54  * This sensor can be also used from within rawlog-grabber.
55  *
56  * \code
57  * PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS:
58  * -------------------------------------------------------
59  * [supplied_section_name]
60  * sensorLabel = CAM3D // A text description
61  * preview_window = true // Show a window with a preview of the grabbed data in real-time
62  *
63  * open_USB = true // false means ethernet (default: true)
64  * USB_serial = 0x4000002f // only for open_USB=true. If not set, the first camera will be open. Serial is the last part of S/N (e.g. for the camera SN: 00-00-40-00-00-2F).
65  * IP_address = 192.168.2.14 // only for open_USB=false. The IP of the camera.
66  *
67  * // Options for the data to save in each CObservation3DRangeScan
68  * save_3d = true // Save the 3D point cloud (default: true)
69  * save_range_img = true // Save the 2D range image (default: true)
70  * save_intensity_img = true // Save the 2D intensity image (default: true)
71  * save_confidence = true // Save the estimated confidence 2D image (default: false)
72  *
73  * enable_img_hist_equal = false // Enable intensity image histogram equalization (default: false)
74  * enable_median_filter = true // Enable median filter in range data (default: true)
75  * enable_mediancross_filter = false // Enable median cross-filter (default: false)
76  * enable_conv_gray = false // Enable intensity image scale with range (default: false)
77  * enable_denoise_anf = true // Enable this noise filter (default: true)
78  *
79  * // Camera calibration parameters: See mrpt::utils::TCamera
80  * // If not provided, a set of default parameters for a SR4000 camera will be loaded.
81  * resolution = [176 144]
82  * cx = 87.99958
83  * cy = 68.99957
84  * fx = 262.9201
85  * fy = 262.9218
86  * dist = [-8.258543e-01 6.561022e-01 2.699818e-06 -3.263559e-05 0]
87  *
88  * // For externaly stored images, the format of image files (default=jpg)
89  * //external_images_format = jpg
90  * // (Only when external_images_format=jpg): Optional parameter to set the JPEG compression quality:
91  * //external_images_jpeg_quality = 95 // [1-100]. Default: 95
92  *
93  * pose_x=0.21 // Camera position in the robot (meters)
94  * pose_y=0
95  * pose_z=0.34
96  * pose_yaw=0 // Angles in degrees
97  * pose_pitch=0
98  * pose_roll=0
99  *
100  * \endcode
101  * \ingroup mrpt_hwdrivers_grp
102  */
104  {
106 
107  public:
108  CSwissRanger3DCamera(); //!< Default ctor
109  ~CSwissRanger3DCamera(); //!< Default ctor
110 
111  /** Initializes the 3D camera - should be invoked after calling loadConfig()
112  * \exception This method must throw an exception with a descriptive message if some critical error is found.
113  */
114  virtual void initialize();
115 
116  /** To be called at a high rate (>XX Hz), this method populates the internal buffer of received observations.
117  * This method is mainly intended for usage within rawlog-grabber or similar programs.
118  * For an alternative, see getNextObservation()
119  * \exception This method must throw an exception with a descriptive message if some critical error is found.
120  * \sa getNextObservation
121  */
122  virtual void doProcess();
123 
124  /** The main data retrieving function, to be called after calling loadConfig() and initialize().
125  * \param out_obs The output retrieved observation (only if there_is_obs=true).
126  * \param there_is_obs If set to false, there was no new observation.
127  * \param hardware_error True on hardware/comms error.
128  *
129  * \sa doProcess
130  */
131  void getNextObservation( mrpt::slam::CObservation3DRangeScan &out_obs, bool &there_is_obs, bool &hardware_error );
132 
133 
134  bool open(); //!< return false on error - Called automatically from initialize(), no need normally for the user to call this.
135  void close();
136 
137  bool isOpen() const; //!< whether the camera is open and comms work ok. To be called after initialize()
138 
139  /** Get the row count in the camera images, loaded automatically upon camera open(). */
140  size_t getRowCount() const { return m_rows; }
141  /** Get the col count in the camera images, loaded automatically upon camera open(). */
142  size_t getColCount() const { return m_cols; }
143 
144  /** Get the camera serial number, loaded automatically upon camera open(). */
145  unsigned int getCameraSerialNumber() const { return m_cam_serial_num; }
146 
147  /** Returns the maximum camera range, as deduced from its operating frequency. */
148  double getMaxRange() const { return m_maxRange; }
149 
150  /** Set the path where to save off-rawlog image files (this class DOES take into account this path).
151  * An empty string (the default value at construction) means to save images embedded in the rawlog, instead of on separate files.
152  * \exception std::exception If the directory doesn't exists and cannot be created.
153  */
154  virtual void setPathForExternalImages( const std::string &directory );
155 
156  /** @name Capture configuration methods (apart from loadConfig)
157  @{ */
158 
159  /** true: open from USB, false: open from ethernet. */
160  inline void setOpenFromUSB(bool USB) { m_open_from_usb = USB; }
161  inline bool getOpenFromUSBMode() const { return m_open_from_usb; }
162 
163  inline void setOpenIPAddress(const std::string &IP) { m_ip_address = IP; }
164  inline std::string getOpenIPAddress() const { return m_ip_address; }
165 
166  inline void setSave3D(bool save) { m_save_3d = save; }
167  inline void setSaveRangeImage(bool save) { m_save_range_img = save; }
168  inline void setSaveIntensityImage(bool save) { m_save_intensity_img = save; }
169  inline void setSaveConfidenceImage(bool save) { m_save_confidence = save; }
170 
171  inline void enableImageHistEqualization(bool enable) { m_enable_img_hist_equal = enable; }
172  inline bool isEnabledImageHistEqualization() const { return m_enable_img_hist_equal; }
173 
174  inline void enableMedianFilter(bool enable) { m_enable_median_filter = enable; internal_resendParamsToCamera(); }
175  inline bool isEnabledMedianFilter() const { return m_enable_median_filter; }
176 
177  inline void enableMedianCrossFilter(bool enable) { m_enable_mediancross_filter = enable; internal_resendParamsToCamera(); }
178  inline bool isEnabledMedianCrossFilter() const { return m_enable_mediancross_filter; }
179 
180  inline void enableConvGray(bool enable) { m_enable_conv_gray = enable; internal_resendParamsToCamera(); }
181  inline bool isEnabledConvGray() const { return m_enable_conv_gray; }
182 
183  inline void enableDenoiseANF(bool enable) { m_enable_denoise_anf = enable; internal_resendParamsToCamera(); }
184  inline bool isEnabledDenoiseANF() const { return m_enable_denoise_anf; }
185 
186  inline void enablePreviewWindow(bool enable=true) { m_preview_window = enable; }
187  inline bool isEnabledPreviewWindow() const { return m_preview_window; }
188 
189  /** @} */
190 
191 
192  // List of small functions to be implemented differently in Win/Lin.
193 
194  /** Get the version of the MESA library.
195  * \return false on error
196  */
197  bool getMesaLibVersion(std::string &out_version) const;
198 
199 
200  protected:
201  /** Loads specific configuration for the device from a given source of configuration parameters, for example, an ".ini" file, loading from the section "[iniSection]" (see utils::CConfigFileBase and derived classes)
202  * \exception This method must throw an exception with a descriptive message if some critical parameter is missing or has an invalid value.
203  */
204  virtual void loadConfig_sensorSpecific(
205  const mrpt::utils::CConfigFileBase &configSource,
206  const std::string &section );
207 
208  void internal_resendParamsToCamera() const;
209 
211 
212  bool m_save_3d; //!< Save the 3D point cloud (default: true)
213  bool m_save_range_img; //!< Save the 2D range image (default: true)
214  bool m_save_intensity_img; //!< Save the 2D intensity image (default: true)
215  bool m_save_confidence; //!< Save the estimated confidence 2D image (default: false)
216 
222 
223 
224  bool m_open_from_usb; //!< true: USB, false: ETH
225  size_t m_usb_serial;
226  std::string m_ip_address;
227 
228  size_t m_rows, m_cols; //!< Size of camera images, set on open()
229  unsigned int m_cam_serial_num; //!< Serial number of the camera, set on open()
230  double m_maxRange; //!< Max range, as deducted from the camera frequency.
231 
232  bool m_preview_window; //!< Show preview window while grabbing
234 
235  void *m_cam; //!< opaque handler to SRCAM. NULL means it's not open yet.
236 
238 
239  private:
240 
241  }; // End of class
242 
243  } // End of NS
244 } // End of NS
245 
246 
247 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013