19 #ifdef MRPT_OS_WINDOWS
36 CSickLaserUSB::CSickLaserUSB() :
37 m_usbConnection( NULL ),
38 m_serialNumber (
"LASER001" ),
60 bool &outThereIsObservation,
64 outThereIsObservation =
false;
65 hardwareError =
false;
74 unsigned char LMS_stat;
107 outObservation.
maxRange = is_mm_mode ? 32.7 : 81.0;
113 for (
size_t i=0;i<ranges.size();i++) {
124 outThereIsObservation =
true;
136 configSource.
read_float(iniSection,
"pose_x",0),
137 configSource.
read_float(iniSection,
"pose_y",0),
138 configSource.
read_float(iniSection,
"pose_z",0),
186 catch(std::exception &e)
197 vector<float> &out_ranges_meters,
198 unsigned char &LMS_status,
202 size_t nRead,nBytesToRead;
203 size_t nFrameBytes = 0;
205 unsigned char buf[2000];
208 while ( nFrameBytes < (lenghtField=( 6 + (buf[2] | (buf[3] << 8))) ) + 5 )
220 nBytesToRead = (5 + lenghtField) - nFrameBytes;
226 catch (std::exception &e)
229 MRPT_LOG_ERROR_FMT(
"[CSickLaserUSB::waitContinuousSampleFrame] Disconnecting due to comms error: %s\n", e.what());
235 if ( nRead == 0 && nFrameBytes==0 )
242 if (nFrameBytes>1 || (!nFrameBytes && buf[0]==0x02) || (nFrameBytes==1 && buf[1]==0x80))
259 if ( buf[4]!=0xB0 )
return false;
262 int info = buf[5] | (buf[6] << 8);
263 int n_points =
info & 0x01FF;
264 is_mm_mode = 0 != ((
info & 0xC000) >> 14);
266 out_ranges_meters.resize(n_points);
269 short mask = is_mm_mode ? 0x7FFF : 0x1FFF;
270 float meters_scale = is_mm_mode ? 0.001f : 0.01f;
272 for (
int i=0;i<n_points;i++)
273 out_ranges_meters[i] = ( (buf[7+i*2] | (buf[8+i*2] << 8)) &
mask ) * meters_scale;
276 LMS_status = buf[lenghtField-3];
279 if (buf[nFrameBytes-1]!=0x55)
282 #ifdef MRPT_OS_WINDOWS
283 OutputDebugStringA(
"[CSickLaserUSB::waitContinuousSampleFrame] bad end flag\n");
290 const uint16_t CRC_packet = buf[lenghtField-2] | ( buf[lenghtField-1] << 8);
293 const string s =
format(
"[CSickLaserUSB::waitContinuousSampleFrame] bad CRC len=%u nptns=%u: %i != %i\n",
unsigned(lenghtField),
unsigned(n_points), CRC_packet, CRC);
295 #ifdef MRPT_OS_WINDOWS
296 OutputDebugStringA(
s.c_str());
302 out_board_timestamp =
303 (
uint32_t(buf[nFrameBytes-5]) << 24) |
304 (
uint32_t(buf[nFrameBytes-4]) << 16) |
305 (
uint32_t(buf[nFrameBytes-3]) << 8) |
#define IMPLEMENTS_GENERIC_SENSOR(class_name, NameSpace)
This must be inserted in all CGenericSensor classes implementation files:
#define MRPT_LOG_INFO_FMT(_FMT_STRING,...)
#define MRPT_LOG_ERROR_FMT(_FMT_STRING,...)
void processPreview(const mrpt::obs::CObservation2DRangeScan &obs)
Must be called inside the capture method to allow optional GUI preview of scans.
void loadCommonParams(const mrpt::utils::CConfigFileBase &configSource, const std::string &iniSection)
Should be call by derived classes at "loadConfig" (loads exclusion areas AND exclusion angles).
void filterByExclusionAngles(mrpt::obs::CObservation2DRangeScan &obs) const
Mark as invalid those ranges in a set of forbiden angle ranges.
void filterByExclusionAreas(mrpt::obs::CObservation2DRangeScan &obs) const
Mark as invalid those points which (x,y) coordinates fall within the exclusion polygons.
std::string m_sensorLabel
See CGenericSensor.
A definition of a CStream actually representing a USB connection to a FTDI chip.
bool isOpen()
Checks whether the chip has been successfully open.
void SetLatencyTimer(unsigned char latency_ms)
Change the latency timer (in milliseconds) implemented on the FTDI chip: for a few ms,...
void OpenBySerialNumber(const std::string &serialNumber)
Open by device serial number.
void SetTimeouts(unsigned long dwReadTimeout_ms, unsigned long dwWriteTimeout_ms)
Change read & write timeouts, in milliseconds.
void ResetDevice()
Reset the USB device.
void Close()
Close the USB device.
size_t ReadSync(void *Buffer, size_t Count)
Tries to read, raising no exception if not all the bytes are available, but raising one if there is s...
This "software driver" implements the communication protocol for interfacing a SICK LMS2XX laser scan...
std::string m_serialNumber
bool turnOff()
Disables the scanning mode (in this class this has no effect).
bool checkControllerIsConnected()
poses::CPose3D m_sensorPose
The sensor 6D pose:
void doProcessSimple(bool &outThereIsObservation, mrpt::obs::CObservation2DRangeScan &outObservation, bool &hardwareError)
Specific laser scanner "software drivers" must process here new data from the I/O stream,...
bool turnOn()
Enables the scanning mode (in this class this has no effect).
bool waitContinuousSampleFrame(std::vector< float > &ranges, unsigned char &LMS_status, uint32_t &out_board_timestamp, bool &is_mm_mode)
virtual ~CSickLaserUSB()
Destructor.
uint32_t m_timeStartUI
Time of the first data packet, for synchronization purposes.
mrpt::system::TTimeStamp m_timeStartTT
void loadConfig_sensorSpecific(const mrpt::utils::CConfigFileBase &configSource, const std::string &iniSection)
See the class documentation at the top for expected parameters.
CInterfaceFTDI * m_usbConnection
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
float maxRange
The maximum range allowed by the device, in meters (e.g. 80m, 50m,...)
float aperture
The "aperture" or field-of-view of the range finder, in radians (typically M_PI = 180 degrees).
mrpt::poses::CPose3D sensorPose
The 6D pose of the sensor on the robot at the moment of starting the scan.
bool rightToLeft
The scanning direction: true=counterclockwise; false=clockwise.
void resizeScan(const size_t len)
Resizes all data vectors to allocate a given number of scan rays.
void setScanRangeValidity(const size_t i, const bool val)
float stdError
The "sigma" error of the device in meters, used while inserting the scan in an occupancy grid.
void setScanRange(const size_t i, const float val)
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...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
This class allows loading and storing values and vectors of different types from a configuration text...
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
GLsizei const GLchar ** string
uint16_t BASE_IMPEXP compute_CRC16(const std::vector< uint8_t > &data, const uint16_t gen_pol=0x8005)
Computes the CRC16 checksum of a block of data.
void BASE_IMPEXP sleep(int time_ms) MRPT_NO_THROWS
An OS-independent method for sending the current thread to "sleep" for a given period of time.
mrpt::system::TTimeStamp BASE_IMPEXP secondsToTimestamp(const double nSeconds)
Transform a time interval (in seconds) into TTimeStamp (e.g.
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1,...
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
Contains classes for various device interfaces.
This namespace contains representation of robot actions and observations.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values,...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
unsigned __int16 uint16_t
unsigned __int32 uint32_t