24 #if MRPT_HAS_SWISSRANGE
25 #ifdef MRPT_OS_WINDOWS
26 #define WIN32_LEAN_AND_MEAN
30 #include <libMesaSR.h>
37 #include <linux/sockios.h>
38 #include <asm/ioctls.h>
39 #include <sys/select.h>
49 m_sensorPoseOnRobot (),
51 m_save_range_img(true),
52 m_save_intensity_img(true),
53 m_save_confidence(false),
55 m_enable_img_hist_equal(false),
56 m_enable_median_filter (true),
57 m_enable_mediancross_filter(false),
58 m_enable_conv_gray (false),
59 m_enable_denoise_anf (true),
61 m_open_from_usb (true),
63 m_ip_address (
"192.168.2.14"),
68 m_preview_window(false)
85 #if !MRPT_HAS_SWISSRANGE
86 THROW_EXCEPTION(
"MRPT was compiled without support for SwissRanger 3D cameras! Rebuild it.")
132 int mantissa = (sample >> (exponent + 3) ) & 0x1F;
133 return ((exponent << 5) | mantissa);
137 return (sample >> 4);
143 for (
unsigned int i=0;i<0x10000;i++)
164 bool thereIs, hwError;
166 CObservation3DRangeScanPtr newObs = CObservation3DRangeScan::Create();
194 configSource.
read_float(iniSection,
"pose_x",0),
195 configSource.
read_float(iniSection,
"pose_y",0),
196 configSource.
read_float(iniSection,
"pose_z",0),
226 catch(std::exception &)
236 #if MRPT_HAS_SWISSRANGE
251 return m_cam != NULL;
256 #if MRPT_HAS_SWISSRANGE
280 const ModulationFrq fr = SR_GetModulationFrequency(cam);
299 SR_SetTimeout(cam, 1000 );
311 #if MRPT_HAS_SWISSRANGE
313 SR_Close(SRCAM(
m_cam));
320 #if MRPT_HAS_SWISSRANGE
323 SR_SetMode(SRCAM(
m_cam),
345 bool &hardware_error )
348 hardware_error =
false;
349 #if MRPT_HAS_SWISSRANGE
351 int bytesRx = SR_Acquire( SRCAM(
m_cam) );
354 cerr <<
"[CSwissRanger3DCamera] Zero bytes read from the camera." << endl;
355 hardware_error =
true;
360 ImgEntry *imgEntryArray;
361 const int nImgs=SR_GetImageList( SRCAM(
m_cam),&imgEntryArray);
365 cerr <<
"[CSwissRanger3DCamera] Error: no images in image list." << endl;
366 hardware_error =
true;
378 for (
int i=0;i<nImgs;i++)
380 const ImgEntry *
img = imgEntryArray+i;
381 switch (
img->imgType)
384 case ImgEntry::IT_DISTANCE:
388 ASSERT_(img->dataType==ImgEntry::DT_USHORT)
394 const float K = obs.
maxRange / 0xFFFF;
399 for (
size_t y=0;
y<
img->height;
y++)
400 for (
size_t x=0;
x<
img->width;
x++)
406 ASSERT_(img->dataType==ImgEntry::DT_USHORT)
409 const size_t N =
img->height *
img->width;
419 SR_CoordTrfFlt(SRCAM(
m_cam),
423 sizeof(
float),
sizeof(
float),
sizeof(
float));
429 case ImgEntry::IT_AMPLITUDE:
433 ASSERT_(img->dataType==ImgEntry::DT_USHORT)
450 for (
size_t y=0;
y<
img->height;
y++)
453 for (
size_t x=0;
x<
img->width;
x++)
473 case ImgEntry::IT_CONF_MAP:
477 ASSERT_(img->dataType==ImgEntry::DT_USHORT)
483 for (
size_t y=0;
y<
img->height;
y++)
486 for (
size_t x=0;
x<
img->width;
x++)
487 (*
row++) = (*data_ptr++) >> 8;
517 static int decim = 0;
527 img.setFromMatrix(range2D);
533 static int decim = 0;
568 THROW_EXCEPTION_FMT(
"Error: Cannot create the directory for externally saved images: %s",directory.c_str() )
#define IMPLEMENTS_GENERIC_SENSOR(class_name, NameSpace)
This must be inserted in all CGenericSensor classes implementation files:
bool table_16u_to_8u_init
static char ALawCompressTable[128]
unsigned char LinearToALawSample(uint16_t sample)
uint8_t table_16u_to_8u[0x10000]
void do_init_table_16u_to_8u()
static CDisplayWindowPtr Create()
void appendObservation(const mrpt::utils::CSerializablePtr &obj)
Like appendObservations() but for just one observation.
std::string m_path_for_external_images
The path where to save off-rawlog images: empty means save images embedded in the rawlog.
std::string m_external_images_format
The extension ("jpg","gif","png",...) that determines the format of images saved externally.
std::string m_sensorLabel
See CGenericSensor.
unsigned int m_external_images_jpeg_quality
For JPEG images, the quality (default=95%).
A class for grabing "range images" from a MESA imaging SwissRanger 3D cameras (SR-2,...
bool m_open_from_usb
true: USB, false: ETH
bool m_save_range_img
Save the 2D range image (default: true)
mrpt::gui::CDisplayWindowPtr m_win_int
mrpt::gui::CDisplayWindowPtr m_win_range
void getNextObservation(mrpt::obs::CObservation3DRangeScan &out_obs, bool &there_is_obs, bool &hardware_error)
The main data retrieving function, to be called after calling loadConfig() and initialize().
bool m_enable_median_filter
virtual void doProcess()
To be called at a high rate (>XX Hz), this method populates the internal buffer of received observati...
bool m_enable_denoise_anf
bool m_enable_mediancross_filter
bool isOpen() const
whether the camera is open and comms work ok. To be called after initialize()
bool open()
return false on error - Called automatically from initialize(), no need normally for the user to call...
virtual void loadConfig_sensorSpecific(const mrpt::utils::CConfigFileBase &configSource, const std::string §ion)
See the class documentation at the top for expected parameters.
virtual void initialize()
Initializes the 3D camera - should be invoked after calling loadConfig()
bool m_enable_img_hist_equal
bool m_preview_window
Show preview window while grabbing.
bool getMesaLibVersion(std::string &out_version) const
Get the version of the MESA library.
void * m_cam
opaque handler to SRCAM. NULL means it's not open yet.
double m_maxRange
Max range, as deducted from the camera frequency.
bool m_save_intensity_img
Save the 2D intensity image (default: true)
~CSwissRanger3DCamera()
Default ctor.
CSwissRanger3DCamera()
Default ctor.
bool m_save_3d
Save the 3D point cloud (default: true)
void internal_resendParamsToCamera() const
size_t m_cols
Size of camera images, set on open()
unsigned int m_cam_serial_num
Serial number of the camera, set on open()
bool m_save_confidence
Save the estimated confidence 2D image (default: false)
virtual void setPathForExternalImages(const std::string &directory)
Set the path where to save off-rawlog image files (this class DOES take into account this path).
mrpt::utils::TCamera m_cameraParams
mrpt::poses::CPose3D m_sensorPoseOnRobot
A matrix of dynamic size.
Declares a class derived from "CObservation" that encapsules a 3D range scan measurement,...
float stdError
The "sigma" error of the device in meters, used while inserting the scan in an occupancy grid.
bool hasConfidenceImage
true means the field confidenceImage contains valid data
mrpt::utils::TCamera cameraParams
Projection parameters of the depth camera.
float maxRange
The maximum range allowed by the device, in meters (e.g. 8.0m, 5.0m,...)
bool hasIntensityImage
true means the field intensityImage contains valid data
void swap(CObservation3DRangeScan &o)
Very efficient method to swap the contents of two observations.
bool hasPoints3D
true means the field points3D contains valid data.
std::vector< float > points3D_x
mrpt::utils::CImage confidenceImage
If hasConfidenceImage=true, an image with the "confidence" value [range 0-255] as estimated by the ca...
std::vector< float > points3D_y
bool hasRangeImage
true means the field rangeImage contains valid data
std::vector< float > points3D_z
If hasPoints3D=true, the (X,Y,Z) coordinates of the 3D point cloud detected by the camera.
mrpt::math::CMatrix rangeImage
If hasRangeImage=true, a matrix of floats with the range data as captured by the camera (in meters)
mrpt::utils::CImage intensityImage
If hasIntensityImage=true, a color or gray-level intensity image of the same size than "rangeImage".
mrpt::poses::CPose3D sensorPose
The 6D pose of the sensor on the robot.
bool range_is_depth
true: Kinect-like ranges: entries of rangeImage are distances along the +X axis; false: Ranges in ran...
std::string sensorLabel
An arbitrary label that can be used to identify the sensor.
mrpt::system::TTimeStamp timestamp
The associated UTC time-stamp. Where available, this should contain the accurate satellite-based time...
void setFromValues(const double x0, const double y0, const double z0, const double yaw=0, const double pitch=0, const double roll=0)
Set the pose from a 3D position (meters) and yaw/pitch/roll angles (radians) - This method recomputes...
This class allows loading and storing values and vectors of different types from a configuration text...
bool read_bool(const std::string §ion, const std::string &name, bool defaultValue, bool failIfNotFound=false) const
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
uint64_t read_uint64_t(const std::string §ion, const std::string &name, uint64_t defaultValue, bool failIfNotFound=false) const
A class for storing images as grayscale or RGB bitmaps.
unsigned char * get_unsafe(unsigned int col, unsigned int row, unsigned int channel=0) const
Access to pixels without checking boundaries - Use normally the () operator better,...
void resize(unsigned int width, unsigned int height, TImageChannels nChannels, bool originTopLeft)
Changes the size of the image, erasing previous contents (does NOT scale its current content,...
void setExternalStorage(const std::string &fileName) MRPT_NO_THROWS
By using this method the image is marked as referenced to an external file, which will be loaded only...
bool saveToFile(const std::string &fileName, int jpeg_quality=95) const
Save the image to a file, whose format is determined from the extension (internally uses OpenCV).
void equalizeHistInPlace()
Equalize the image histogram, replacing the original image.
void loadFromConfigFile(const std::string §ion, const mrpt::utils::CConfigFileBase &cfg)
Load all the params from a config source, in the format used in saveToConfigFile(),...
uint32_t nrows
Camera resolution.
mrpt::math::CArrayDouble< 5 > dist
[k1 k2 t1 t2 k3] -> k_i: parameters of radial distortion, t_i: parameters of tangential distortion (d...
void scaleToResolution(unsigned int new_ncols, unsigned int new_nrows)
Rescale all the parameters for a new camera resolution (it raises an exception if the aspect ratio is...
mrpt::math::CMatrixDouble33 intrinsicParams
Matrix of intrinsic parameters (containing the focal length and principal point coordinates)
GLenum GLenum GLvoid * row
GLsizei const GLchar ** string
bool BASE_IMPEXP createDirectory(const std::string &dirName)
Creates a directory.
std::string BASE_IMPEXP fileNameStripInvalidChars(const std::string &filename, const char replacement_to_invalid_chars='_')
Replace invalid filename chars by underscores ('_') or any other user-given char.
std::string BASE_IMPEXP trim(const std::string &str)
Removes leading and trailing spaces.
double BASE_IMPEXP timestampTotime_t(const mrpt::system::TTimeStamp t)
Transform from TTimeStamp to standard "time_t" (actually a double number, it can contain fractions of...
#define THROW_EXCEPTION(msg)
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
Contains classes for various device interfaces.
This namespace contains representation of robot actions and observations.
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
double DEG2RAD(const double x)
Degrees to radians.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
unsigned __int16 uint16_t