00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 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 */ 00102 class HWDRIVERS_IMPEXP CSwissRanger3DCamera : public mrpt::hwdrivers::CGenericSensor 00103 { 00104 DEFINE_GENERIC_SENSOR(CSwissRanger3DCamera) 00105 00106 public: 00107 CSwissRanger3DCamera(); //!< Default ctor 00108 ~CSwissRanger3DCamera(); //!< Default ctor 00109 00110 /** Initializes the 3D camera - should be invoked after calling loadConfig() 00111 * \exception This method must throw an exception with a descriptive message if some critical error is found. 00112 */ 00113 virtual void initialize(); 00114 00115 /** To be called at a high rate (>XX Hz), this method populates the internal buffer of received observations. 00116 * This method is mainly intended for usage within rawlog-grabber or similar programs. 00117 * For an alternative, see getNextObservation() 00118 * \exception This method must throw an exception with a descriptive message if some critical error is found. 00119 * \sa getNextObservation 00120 */ 00121 virtual void doProcess(); 00122 00123 /** The main data retrieving function, to be called after calling loadConfig() and initialize(). 00124 * \param out_obs The output retrieved observation (only if there_is_obs=true). 00125 * \param there_is_obs If set to false, there was no new observation. 00126 * \param hardware_error True on hardware/comms error. 00127 * 00128 * \sa doProcess 00129 */ 00130 void getNextObservation( mrpt::slam::CObservation3DRangeScan &out_obs, bool &there_is_obs, bool &hardware_error ); 00131 00132 00133 bool open(); //!< return false on error - Called automatically from initialize(), no need normally for the user to call this. 00134 void close(); 00135 00136 bool isOpen() const; //!< whether the camera is open and comms work ok. To be called after initialize() 00137 00138 /** Get the row count in the camera images, loaded automatically upon camera open(). */ 00139 size_t getRowCount() const { return m_rows; } 00140 /** Get the col count in the camera images, loaded automatically upon camera open(). */ 00141 size_t getColCount() const { return m_cols; } 00142 00143 /** Get the camera serial number, loaded automatically upon camera open(). */ 00144 unsigned int getCameraSerialNumber() const { return m_cam_serial_num; } 00145 00146 /** Returns the maximum camera range, as deduced from its operating frequency. */ 00147 double getMaxRange() const { return m_maxRange; } 00148 00149 /** Set the path where to save off-rawlog image files (this class DOES take into account this path). 00150 * An empty string (the default value at construction) means to save images embedded in the rawlog, instead of on separate files. 00151 * \exception std::exception If the directory doesn't exists and cannot be created. 00152 */ 00153 virtual void setPathForExternalImages( const std::string &directory ); 00154 00155 /** @name Capture configuration methods (apart from loadConfig) 00156 @{ */ 00157 00158 /** true: open from USB, false: open from ethernet. */ 00159 inline void setOpenFromUSB(bool USB) { m_open_from_usb = USB; } 00160 inline bool getOpenFromUSBMode() const { return m_open_from_usb; } 00161 00162 inline void setOpenIPAddress(const std::string &IP) { m_ip_address = IP; } 00163 inline std::string getOpenIPAddress() const { return m_ip_address; } 00164 00165 inline void setSave3D(bool save) { m_save_3d = save; } 00166 inline void setSaveRangeImage(bool save) { m_save_range_img = save; } 00167 inline void setSaveIntensityImage(bool save) { m_save_intensity_img = save; } 00168 inline void setSaveConfidenceImage(bool save) { m_save_confidence = save; } 00169 00170 inline void enableImageHistEqualization(bool enable) { m_enable_img_hist_equal = enable; } 00171 inline bool isEnabledImageHistEqualization() const { return m_enable_img_hist_equal; } 00172 00173 inline void enableMedianFilter(bool enable) { m_enable_median_filter = enable; internal_resendParamsToCamera(); } 00174 inline bool isEnabledMedianFilter() const { return m_enable_median_filter; } 00175 00176 inline void enableMedianCrossFilter(bool enable) { m_enable_mediancross_filter = enable; internal_resendParamsToCamera(); } 00177 inline bool isEnabledMedianCrossFilter() const { return m_enable_mediancross_filter; } 00178 00179 inline void enableConvGray(bool enable) { m_enable_conv_gray = enable; internal_resendParamsToCamera(); } 00180 inline bool isEnabledConvGray() const { return m_enable_conv_gray; } 00181 00182 inline void enableDenoiseANF(bool enable) { m_enable_denoise_anf = enable; internal_resendParamsToCamera(); } 00183 inline bool isEnabledDenoiseANF() const { return m_enable_denoise_anf; } 00184 00185 inline void enablePreviewWindow(bool enable=true) { m_preview_window = enable; } 00186 inline bool isEnabledPreviewWindow() const { return m_preview_window; } 00187 00188 /** @} */ 00189 00190 00191 // List of small functions to be implemented differently in Win/Lin. 00192 00193 /** Get the version of the MESA library. 00194 * \return false on error 00195 */ 00196 bool getMesaLibVersion(std::string &out_version) const; 00197 00198 00199 protected: 00200 /** 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) 00201 * \exception This method must throw an exception with a descriptive message if some critical parameter is missing or has an invalid value. 00202 */ 00203 virtual void loadConfig_sensorSpecific( 00204 const mrpt::utils::CConfigFileBase &configSource, 00205 const std::string §ion ); 00206 00207 void internal_resendParamsToCamera() const; 00208 00209 mrpt::poses::CPose3D m_sensorPoseOnRobot; 00210 00211 bool m_save_3d; //!< Save the 3D point cloud (default: true) 00212 bool m_save_range_img; //!< Save the 2D range image (default: true) 00213 bool m_save_intensity_img; //!< Save the 2D intensity image (default: true) 00214 bool m_save_confidence; //!< Save the estimated confidence 2D image (default: false) 00215 00216 bool m_enable_img_hist_equal; 00217 bool m_enable_median_filter; 00218 bool m_enable_mediancross_filter; 00219 bool m_enable_conv_gray; 00220 bool m_enable_denoise_anf; 00221 00222 00223 bool m_open_from_usb; //!< true: USB, false: ETH 00224 size_t m_usb_serial; 00225 std::string m_ip_address; 00226 00227 size_t m_rows, m_cols; //!< Size of camera images, set on open() 00228 unsigned int m_cam_serial_num; //!< Serial number of the camera, set on open() 00229 double m_maxRange; //!< Max range, as deducted from the camera frequency. 00230 00231 bool m_preview_window; //!< Show preview window while grabbing 00232 mrpt::gui::CDisplayWindowPtr m_win_range, m_win_int; 00233 00234 void *m_cam; //!< opaque handler to SRCAM. NULL means it's not open yet. 00235 00236 mrpt::utils::TCamera m_cameraParams; 00237 00238 private: 00239 00240 }; // End of class 00241 00242 } // End of NS 00243 } // End of NS 00244 00245 00246 #endif
Page generated by Doxygen 1.7.1 for MRPT 0.9.4 SVN: at Mon Jan 10 23:33:19 UTC 2011 |