Main MRPT website > C++ reference
MRPT logo
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes

mrpt::hwdrivers::CSickLaserSerial Class Reference


Detailed Description

This "software driver" implements the communication protocol for interfacing a SICK LMS 2XX laser scanners through a standard RS232 serial port (or a USB2SERIAL converter).

The serial port is opened upon the first call to "doProcess" or "initialize", so you must call "loadConfig" before this, or manually call "setSerialPort". Another alternative is to call the base class method C2DRangeFinderAbstract::bindIO, but the "setSerialPort" interface is probably much simpler to use.

For an example of usage see the example in "samples/SICK_laser_serial_test". See also the example configuration file for rawlog-grabber in "share/mrpt/config_files/rawlog-grabber".

  PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS:
 -------------------------------------------------------
   [supplied_section_name]
   COM_port_WIN = COM1   // Serial port to connect to
   COM_port_LIN = ttyS0

   COM_baudRate = 38400 // Possible values: 9600 (default), 38400, 5000000
   mm_mode      = 1/0   // 1: millimeter mode, 0:centimeter mode (Default=0)
   FOV          = 180   // Field of view: 100 or 180 degrees (Default=180)
   resolution   =  50   // Scanning resolution, in units of 1/100 degree. Valid values: 25,50,100 (Default=50)


   pose_x=0.21  // Laser range scaner 3D position in the robot (meters)
   pose_y=0
   pose_z=0.34
   pose_yaw=0   // Angles in degrees
   pose_pitch=0
   pose_roll=0
See also:
C2DRangeFinderAbstract

Definition at line 69 of file CSickLaserSerial.h.

#include <mrpt/hwdrivers/CSickLaserSerial.h>

Inheritance diagram for mrpt::hwdrivers::CSickLaserSerial:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 CSickLaserSerial ()
 Constructor.
virtual ~CSickLaserSerial ()
 Destructor.
void setSerialPort (const std::string &port)
 Changes the serial port to connect to (call prior to 'doProcess'), for example "COM1" or "ttyS0".
std::string getSerialPort () const
void setBaudRate (int baud)
 Changes the serial port baud rate (call prior to 'doProcess'); valid values are 9600,38400 and 500000.
int getBaudRate () const
void setMillimeterMode (bool mm_mode=true)
 Enables/Disables the millimeter mode, with a greater accuracy but a shorter range (default=false) (call prior to 'doProcess') This is not needed if the configuration is loaded with "loadConfig".
void setScanFOV (int fov_degrees)
 Set the scanning field of view - possible values are 100 or 180 (default) (call prior to 'doProcess') This is not needed if the configuration is loaded with "loadConfig".
int getScanFOV () const
void setScanResolution (int res_1_100th_degree)
 Set the scanning resolution, in units of 1/100 degree - Possible values are 25, 50 and 100, for 0.25, 0.5 (default) and 1 deg.
int getScanResolution () const
unsigned int getCurrentConnectTry () const
 If performing several tries in ::initialize(), this is the current try loop number.
void doProcessSimple (bool &outThereIsObservation, mrpt::slam::CObservation2DRangeScan &outObservation, bool &hardwareError)
 Specific laser scanner "software drivers" must process here new data from the I/O stream, and, if a whole scan has arrived, return it.
void initialize ()
 Set-up communication with the laser.
bool turnOn ()
 Enables the scanning mode (in this class this has no effect).
bool turnOff ()
 Disables the scanning mode (in this class this has no effect).

Protected Member Functions

void loadConfig_sensorSpecific (const mrpt::utils::CConfigFileBase &configSource, const std::string &iniSection)
 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) See hwdrivers::CSickLaserSerial for the possible parameters.

Private Member Functions

bool tryToOpenComms (std::string *err_msg=NULL)
 Tries to open the com port and setup all the LMS protocol. Returns true if OK or already open.
bool waitContinuousSampleFrame (std::vector< float > &ranges, unsigned char &LMS_status, bool &is_mm_mode)
bool LMS_setupSerialComms ()
 Assures laser is connected and operating at 38400, in its case returns true.
bool LMS_setupBaudrate (int baud)
 Send a command to change the LMS comms baudrate, return true if ACK is OK. baud can be: 9600, 19200, 38400, 500000.
bool LMS_statusQuery ()
 Send a status query and wait for the answer. Return true on OK.
bool LMS_waitACK (uint16_t timeout_ms)
 Returns false if timeout.
bool LMS_waitIncomingFrame (uint16_t timeout)
 Returns false if timeout.
bool LMS_sendMeasuringMode_cm_mm ()
 Returns false on error.
bool LMS_startContinuousMode ()
bool LMS_endContinuousMode ()
bool SendCommandToSICK (const uint8_t *cmd, const uint16_t cmd_len)
 Send header+command-data+crc and waits for ACK. Return false on error.

Private Attributes

bool m_mm_mode
int m_scans_FOV
 100 or 180 deg
int m_scans_res
 1/100th of deg: 100, 50 or 25
poses::TPose3D m_sensorPose
 The sensor 6D pose:
uint8_t m_received_frame_buffer [2000]
std::string m_com_port
 If set to non-empty, the serial port will be attempted to be opened automatically when this class is first used to request data from the laser.
CSerialPortm_mySerialPort
 Will be !=NULL only if I created it, so I must destroy it at the end.
int m_com_baudRate
 Baudrate: 9600, 38400, 500000.
unsigned int m_nTries_connect
 Default = 1.
unsigned int m_nTries_current

Static Private Attributes

static int CRC16_GEN_POL

Constructor & Destructor Documentation

mrpt::hwdrivers::CSickLaserSerial::CSickLaserSerial ( )

Constructor.

virtual mrpt::hwdrivers::CSickLaserSerial::~CSickLaserSerial ( ) [virtual]

Destructor.


Member Function Documentation

void mrpt::hwdrivers::CSickLaserSerial::doProcessSimple ( bool &  outThereIsObservation,
mrpt::slam::CObservation2DRangeScan outObservation,
bool &  hardwareError 
) [virtual]

Specific laser scanner "software drivers" must process here new data from the I/O stream, and, if a whole scan has arrived, return it.

This method will be typically called in a different thread than other methods, and will be called in a timely fashion.

Implements mrpt::hwdrivers::C2DRangeFinderAbstract.

int mrpt::hwdrivers::CSickLaserSerial::getBaudRate ( ) const [inline]
See also:
setBaudRate

Definition at line 137 of file CSickLaserSerial.h.

unsigned int mrpt::hwdrivers::CSickLaserSerial::getCurrentConnectTry ( ) const [inline]

If performing several tries in ::initialize(), this is the current try loop number.

Definition at line 158 of file CSickLaserSerial.h.

int mrpt::hwdrivers::CSickLaserSerial::getScanFOV ( ) const [inline]

Definition at line 149 of file CSickLaserSerial.h.

int mrpt::hwdrivers::CSickLaserSerial::getScanResolution ( ) const [inline]

Definition at line 155 of file CSickLaserSerial.h.

std::string mrpt::hwdrivers::CSickLaserSerial::getSerialPort ( ) const [inline]
See also:
setSerialPort

Definition at line 128 of file CSickLaserSerial.h.

void mrpt::hwdrivers::CSickLaserSerial::initialize ( ) [virtual]

Set-up communication with the laser.

Called automatically by rawlog-grabber. If used manually, call after "loadConfig" and before "doProcess".

In this class this method does nothing, since the communications are setup at the first try from "doProcess" or "doProcessSimple".

Reimplemented from mrpt::hwdrivers::CGenericSensor.

bool mrpt::hwdrivers::CSickLaserSerial::LMS_endContinuousMode ( ) [private]
bool mrpt::hwdrivers::CSickLaserSerial::LMS_sendMeasuringMode_cm_mm ( ) [private]

Returns false on error.

bool mrpt::hwdrivers::CSickLaserSerial::LMS_setupBaudrate ( int  baud) [private]

Send a command to change the LMS comms baudrate, return true if ACK is OK. baud can be: 9600, 19200, 38400, 500000.

bool mrpt::hwdrivers::CSickLaserSerial::LMS_setupSerialComms ( ) [private]

Assures laser is connected and operating at 38400, in its case returns true.

bool mrpt::hwdrivers::CSickLaserSerial::LMS_startContinuousMode ( ) [private]
bool mrpt::hwdrivers::CSickLaserSerial::LMS_statusQuery ( ) [private]

Send a status query and wait for the answer. Return true on OK.

bool mrpt::hwdrivers::CSickLaserSerial::LMS_waitACK ( uint16_t  timeout_ms) [private]

Returns false if timeout.

bool mrpt::hwdrivers::CSickLaserSerial::LMS_waitIncomingFrame ( uint16_t  timeout) [private]

Returns false if timeout.

void mrpt::hwdrivers::CSickLaserSerial::loadConfig_sensorSpecific ( const mrpt::utils::CConfigFileBase configSource,
const std::string &  iniSection 
) [protected, virtual]

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) See hwdrivers::CSickLaserSerial for the possible parameters.

Implements mrpt::hwdrivers::CGenericSensor.

bool mrpt::hwdrivers::CSickLaserSerial::SendCommandToSICK ( const uint8_t *  cmd,
const uint16_t  cmd_len 
) [private]

Send header+command-data+crc and waits for ACK. Return false on error.

void mrpt::hwdrivers::CSickLaserSerial::setBaudRate ( int  baud) [inline]

Changes the serial port baud rate (call prior to 'doProcess'); valid values are 9600,38400 and 500000.

This is not needed if the configuration is loaded with "loadConfig".

See also:
getBaudRate

Definition at line 133 of file CSickLaserSerial.h.

void mrpt::hwdrivers::CSickLaserSerial::setMillimeterMode ( bool  mm_mode = true) [inline]

Enables/Disables the millimeter mode, with a greater accuracy but a shorter range (default=false) (call prior to 'doProcess') This is not needed if the configuration is loaded with "loadConfig".

Definition at line 143 of file CSickLaserSerial.h.

void mrpt::hwdrivers::CSickLaserSerial::setScanFOV ( int  fov_degrees) [inline]

Set the scanning field of view - possible values are 100 or 180 (default) (call prior to 'doProcess') This is not needed if the configuration is loaded with "loadConfig".

Definition at line 148 of file CSickLaserSerial.h.

void mrpt::hwdrivers::CSickLaserSerial::setScanResolution ( int  res_1_100th_degree) [inline]

Set the scanning resolution, in units of 1/100 degree - Possible values are 25, 50 and 100, for 0.25, 0.5 (default) and 1 deg.

(call prior to 'doProcess') This is not needed if the configuration is loaded with "loadConfig".

Definition at line 154 of file CSickLaserSerial.h.

void mrpt::hwdrivers::CSickLaserSerial::setSerialPort ( const std::string &  port) [inline]

Changes the serial port to connect to (call prior to 'doProcess'), for example "COM1" or "ttyS0".

This is not needed if the configuration is loaded with "loadConfig".

Definition at line 125 of file CSickLaserSerial.h.

bool mrpt::hwdrivers::CSickLaserSerial::tryToOpenComms ( std::string *  err_msg = NULL) [private]

Tries to open the com port and setup all the LMS protocol. Returns true if OK or already open.

bool mrpt::hwdrivers::CSickLaserSerial::turnOff ( ) [virtual]

Disables the scanning mode (in this class this has no effect).

Returns:
If everything works "true", or "false" if there is any error.

Implements mrpt::hwdrivers::C2DRangeFinderAbstract.

bool mrpt::hwdrivers::CSickLaserSerial::turnOn ( ) [virtual]

Enables the scanning mode (in this class this has no effect).

Returns:
If everything works "true", or "false" if there is any error.

Implements mrpt::hwdrivers::C2DRangeFinderAbstract.

bool mrpt::hwdrivers::CSickLaserSerial::waitContinuousSampleFrame ( std::vector< float > &  ranges,
unsigned char &  LMS_status,
bool &  is_mm_mode 
) [private]

Member Data Documentation

Definition at line 81 of file CSickLaserSerial.h.

Baudrate: 9600, 38400, 500000.

Definition at line 103 of file CSickLaserSerial.h.

If set to non-empty, the serial port will be attempted to be opened automatically when this class is first used to request data from the laser.

Definition at line 101 of file CSickLaserSerial.h.

Definition at line 74 of file CSickLaserSerial.h.

Will be !=NULL only if I created it, so I must destroy it at the end.

Definition at line 102 of file CSickLaserSerial.h.

Default = 1.

Definition at line 104 of file CSickLaserSerial.h.

Definition at line 105 of file CSickLaserSerial.h.

Definition at line 99 of file CSickLaserSerial.h.

100 or 180 deg

Definition at line 75 of file CSickLaserSerial.h.

1/100th of deg: 100, 50 or 25

Definition at line 76 of file CSickLaserSerial.h.

The sensor 6D pose:

Definition at line 79 of file CSickLaserSerial.h.




Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:16:28 UTC 2011