Main MRPT website > C++ reference
MRPT logo
CSwissRanger3DCamera.h
Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                       http://www.mrpt.org/                                |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 #ifndef CSwissRanger3DCamera_H
00029 #define CSwissRanger3DCamera_H
00030 
00031 #include <mrpt/hwdrivers/CGenericSensor.h>
00032 #include <mrpt/slam/CObservationImage.h>
00033 #include <mrpt/slam/CObservation3DRangeScan.h>
00034 
00035 #include <mrpt/gui/CDisplayWindow.h>
00036 
00037 #include <mrpt/hwdrivers/link_pragmas.h>
00038 
00039 namespace mrpt
00040 {
00041         namespace hwdrivers
00042         {
00043                 /** A class for grabing "range images" from a MESA imaging SwissRanger 3D cameras (SR-2, SR-3000, SR-4k).
00044                   * 
00045                   * NOTES:
00046                   *             - 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
00047                   *             - 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.
00048                   *
00049                   * As with any other CGenericSensor class, the normal sequence of methods to be called is:
00050                   *   - loadConfig() - Or calls to the individual setXXX() to configure the camera parameters.
00051                   *   - initialize() - to init the comms with the camera
00052                   *   - call getNextObservation() for getting the frames.
00053                   *
00054                   *  This sensor can be also used from within rawlog-grabber.
00055                   *
00056                   *  \code
00057                   *  PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS:
00058                   * -------------------------------------------------------
00059                   *   [supplied_section_name]
00060                   *    sensorLabel  = CAM3D         // A text description
00061                   *    preview_window  = true       // Show a window with a preview of the grabbed data in real-time
00062                   *
00063                   *    open_USB     = true          // false means ethernet (default: true)
00064                   *    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).
00065                   *    IP_address   = 192.168.2.14  // only for open_USB=false. The IP of the camera.
00066                   *
00067                   *    // Options for the data to save in each CObservation3DRangeScan
00068                   *    save_3d            = true                        // Save the 3D point cloud (default: true)
00069                   *    save_range_img     = true                        // Save the 2D range image (default: true)
00070                   *    save_intensity_img = true                        // Save the 2D intensity image (default: true)
00071                   *    save_confidence    = true                        // Save the estimated confidence 2D image (default: false)
00072                   *
00073                   *    enable_img_hist_equal = false            // Enable intensity image histogram equalization (default: false)
00074                   *    enable_median_filter  = true                     // Enable median filter in range data (default: true)
00075                   *    enable_mediancross_filter = false        // Enable median cross-filter (default: false)
00076                   *    enable_conv_gray      = false            // Enable intensity image scale with range (default: false)
00077                   *    enable_denoise_anf    = true                     // Enable this noise filter (default: true)
00078                   *
00079                   *    // Camera calibration parameters: See mrpt::utils::TCamera
00080                   *    //  If not provided, a set of default parameters for a SR4000 camera will be loaded.
00081                   *    resolution = [176 144]
00082                   *    cx         = 87.99958
00083                   *    cy         = 68.99957
00084                   *    fx         = 262.9201
00085                   *    fy         = 262.9218
00086                   *    dist       = [-8.258543e-01 6.561022e-01 2.699818e-06 -3.263559e-05 0]
00087                   *
00088                   *    // For externaly stored images, the format of image files (default=jpg)
00089                   *    //external_images_format  = jpg
00090                   *    // (Only when external_images_format=jpg): Optional parameter to set the JPEG compression quality:
00091                   *    //external_images_jpeg_quality = 95    // [1-100]. Default: 95
00092                   *
00093                   *    pose_x=0.21      // Camera position in the robot (meters)
00094                   *    pose_y=0
00095                   *    pose_z=0.34
00096                   *    pose_yaw=0       // Angles in degrees
00097                   *    pose_pitch=0
00098                   *    pose_roll=0
00099                   *
00100                   *  \endcode
00101                   * \ingroup mrpt_hwdrivers_grp
00102                   */
00103                 class HWDRIVERS_IMPEXP  CSwissRanger3DCamera : public mrpt::hwdrivers::CGenericSensor
00104                 {
00105                         DEFINE_GENERIC_SENSOR(CSwissRanger3DCamera)
00106 
00107                 public:
00108                         CSwissRanger3DCamera();  //!< Default ctor
00109                         ~CSwissRanger3DCamera();         //!< Default ctor
00110 
00111                         /** Initializes the 3D camera - should be invoked after calling loadConfig()
00112                           *  \exception This method must throw an exception with a descriptive message if some critical error is found.
00113                           */
00114                         virtual void initialize();
00115 
00116                         /** To be called  at a high rate (>XX Hz), this method populates the internal buffer of received observations.
00117                           *  This method is mainly intended for usage within rawlog-grabber or similar programs.
00118                           *  For an alternative, see getNextObservation()
00119                           *  \exception This method must throw an exception with a descriptive message if some critical error is found.
00120                           * \sa getNextObservation
00121                           */
00122                         virtual void doProcess();
00123 
00124                         /** The main data retrieving function, to be called after calling loadConfig() and initialize().
00125                           *  \param out_obs The output retrieved observation (only if there_is_obs=true).
00126                           *  \param there_is_obs If set to false, there was no new observation.
00127                           *  \param hardware_error True on hardware/comms error.
00128                           *
00129                           * \sa doProcess
00130                           */
00131                         void getNextObservation( mrpt::slam::CObservation3DRangeScan &out_obs, bool &there_is_obs, bool &hardware_error );
00132 
00133 
00134                         bool open(); //!< return false on error - Called automatically from initialize(), no need normally for the user to call this.
00135                         void close();
00136 
00137                         bool isOpen() const; //!< whether the camera is open and comms work ok. To be called after initialize()
00138 
00139                         /** Get the row count in the camera images, loaded automatically upon camera open(). */
00140                         size_t getRowCount() const { return m_rows; }
00141                         /** Get the col count in the camera images, loaded automatically upon camera open(). */
00142                         size_t getColCount() const { return m_cols; }
00143 
00144                         /** Get the camera serial number, loaded automatically upon camera open(). */
00145                         unsigned int getCameraSerialNumber() const { return m_cam_serial_num; }
00146 
00147                         /** Returns the maximum camera range, as deduced from its operating frequency. */
00148                         double  getMaxRange() const { return m_maxRange; }
00149 
00150                         /**  Set the path where to save off-rawlog image files (this class DOES take into account this path).
00151                           *  An  empty string (the default value at construction) means to save images embedded in the rawlog, instead of on separate files.
00152                           * \exception std::exception If the directory doesn't exists and cannot be created.
00153                           */
00154                         virtual void setPathForExternalImages( const std::string &directory );
00155 
00156                         /** @name Capture configuration methods (apart from loadConfig)
00157                             @{ */
00158 
00159                         /** true: open from USB, false: open from ethernet. */
00160                         inline void setOpenFromUSB(bool USB) { m_open_from_usb = USB; }
00161                         inline bool getOpenFromUSBMode() const { return m_open_from_usb; }
00162 
00163                         inline void setOpenIPAddress(const std::string &IP)  { m_ip_address = IP; }
00164                         inline std::string getOpenIPAddress() const  { return m_ip_address; }
00165 
00166                         inline void setSave3D(bool save) { m_save_3d = save; }
00167                         inline void setSaveRangeImage(bool save) { m_save_range_img = save; }
00168                         inline void setSaveIntensityImage(bool save) { m_save_intensity_img = save; }
00169                         inline void setSaveConfidenceImage(bool save) { m_save_confidence = save; }
00170 
00171                         inline void enableImageHistEqualization(bool enable) { m_enable_img_hist_equal = enable; }
00172                         inline bool isEnabledImageHistEqualization() const { return m_enable_img_hist_equal; }
00173 
00174                         inline void enableMedianFilter(bool enable) { m_enable_median_filter = enable; internal_resendParamsToCamera(); }
00175                         inline bool isEnabledMedianFilter() const { return m_enable_median_filter;   }
00176 
00177                         inline void enableMedianCrossFilter(bool enable) { m_enable_mediancross_filter = enable; internal_resendParamsToCamera(); }
00178                         inline bool isEnabledMedianCrossFilter() const { return m_enable_mediancross_filter; }
00179 
00180                         inline void enableConvGray(bool enable) { m_enable_conv_gray = enable; internal_resendParamsToCamera(); }
00181                         inline bool isEnabledConvGray() const { return m_enable_conv_gray;  }
00182 
00183                         inline void enableDenoiseANF(bool enable) { m_enable_denoise_anf = enable; internal_resendParamsToCamera(); }
00184                         inline bool isEnabledDenoiseANF() const { return m_enable_denoise_anf;  }
00185 
00186                         inline void enablePreviewWindow(bool enable=true) { m_preview_window = enable; }
00187                         inline bool isEnabledPreviewWindow() const { return m_preview_window; }
00188 
00189                         /** @} */
00190 
00191 
00192                         // List of small functions to be implemented differently in Win/Lin.
00193 
00194                         /** Get the version of the MESA library.
00195                           * \return false on error
00196                           */
00197                         bool getMesaLibVersion(std::string &out_version) const;
00198 
00199 
00200                 protected:
00201                         /** 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)
00202                           *  \exception This method must throw an exception with a descriptive message if some critical parameter is missing or has an invalid value.
00203                           */
00204                         virtual void  loadConfig_sensorSpecific(
00205                                 const mrpt::utils::CConfigFileBase &configSource,
00206                                 const std::string                       &section );
00207 
00208                         void internal_resendParamsToCamera() const;
00209 
00210                         mrpt::poses::CPose3D    m_sensorPoseOnRobot;
00211 
00212                         bool m_save_3d;                 //!< Save the 3D point cloud (default: true)
00213                         bool m_save_range_img;  //!< Save the 2D range image (default: true)
00214                         bool m_save_intensity_img; //!< Save the 2D intensity image (default: true)
00215                         bool m_save_confidence; //!< Save the estimated confidence 2D image (default: false)
00216 
00217                         bool m_enable_img_hist_equal;
00218                         bool m_enable_median_filter;
00219                         bool m_enable_mediancross_filter;
00220                         bool m_enable_conv_gray;
00221                         bool m_enable_denoise_anf;
00222 
00223 
00224                         bool    m_open_from_usb; //!< true: USB, false: ETH
00225                         size_t  m_usb_serial;
00226                         std::string  m_ip_address;
00227 
00228                         size_t  m_rows, m_cols; //!< Size of camera images, set on open()
00229                         unsigned int m_cam_serial_num; //!< Serial number of the camera, set on open()
00230                         double          m_maxRange;     //!< Max range, as deducted from the camera frequency.
00231 
00232                         bool            m_preview_window; //!< Show preview window while grabbing
00233                         mrpt::gui::CDisplayWindowPtr  m_win_range, m_win_int;
00234 
00235                         void *m_cam;  //!< opaque handler to SRCAM. NULL means it's not open yet.
00236                         
00237                         mrpt::utils::TCamera    m_cameraParams; 
00238 
00239                 private:
00240 
00241                 };      // End of class
00242 
00243         } // End of NS
00244 } // End of NS
00245 
00246 
00247 #endif



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011