Main MRPT website > C++ reference for MRPT 1.9.9
CSickLaserSerial.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #ifndef CSickLaserSerial_H
10 #define CSickLaserSerial_H
11 
13 #include <mrpt/comms/CSerialPort.h>
15 
16 namespace mrpt
17 {
18 namespace hwdrivers
19 {
20 /** This "software driver" implements the communication protocol for interfacing
21  * a SICK LMS 2XX laser scanners through a standard RS232 serial port (or a
22  * USB2SERIAL converter).
23  * The serial port is opened upon the first call to "doProcess" or
24  * "initialize", so you must call "loadConfig" before
25  * this, or manually call "setSerialPort". Another alternative is to call the
26  * base class method C2DRangeFinderAbstract::bindIO,
27  * but the "setSerialPort" interface is probably much simpler to use.
28  *
29  * For an example of usage see the example in
30  * "samples/SICK_laser_serial_test".
31  * See also the example configuration file for rawlog-grabber in
32  * "share/mrpt/config_files/rawlog-grabber".
33  *
34  * \code
35  * PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS:
36  * -------------------------------------------------------
37  * [supplied_section_name]
38  * COM_port_WIN = COM1 // Serial port to connect to
39  * COM_port_LIN = ttyS0
40  *
41  * COM_baudRate = 38400 // Possible values: 9600 (default), 38400, 5000000
42  * mm_mode = 1/0 // 1: millimeter mode, 0:centimeter mode (Default=0)
43  * FOV = 180 // Field of view: 100 or 180 degrees (Default=180)
44  * resolution = 50 // Scanning resolution, in units of 1/100 degree.
45  * Valid values: 25,50,100 (Default=50)
46  * //skip_laser_config = true // (Default:false) If true, doesn't send the
47  * initialization commands to the laser and go straight to capturing
48  *
49  * pose_x=0.21 // Laser range scaner 3D position in the robot (meters)
50  * pose_y=0
51  * pose_z=0.34
52  * pose_yaw=0 // Angles in degrees
53  * pose_pitch=0
54  * pose_roll=0
55  *
56  * //preview = true // Enable GUI visualization of captured data
57  *
58  * // Optional: Exclusion zones to avoid the robot seeing itself:
59  * //exclusionZone1_x = 0.20 0.30 0.30 0.20
60  * //exclusionZone1_y = 0.20 0.30 0.30 0.20
61  *
62  * // Optional: Exclusion zones to avoid the robot seeing itself:
63  * //exclusionAngles1_ini = 20 // Deg
64  * //exclusionAngles1_end = 25 // Deg
65  * \endcode
66  *
67  * \sa C2DRangeFinderAbstract
68  * \ingroup mrpt_hwdrivers_grp
69  */
71 {
73 
74  private:
75  bool m_mm_mode;
76  /** 100 or 180 deg */
78  /** 1/100th of deg: 100, 50 or 25 */
80 
81  /** The sensor 6D pose: */
83 
84  static int CRC16_GEN_POL;
85 
86  /** Tries to open the com port and setup all the LMS protocol. Returns true
87  * if OK or already open. */
88  bool tryToOpenComms(std::string* err_msg = nullptr);
90  std::vector<float>& ranges, unsigned char& LMS_status,
91  bool& is_mm_mode);
92 
93  /** Assures laser is connected and operating at 38400, in its case returns
94  * true. */
95  bool LMS_setupSerialComms();
96  /** Send a command to change the LMS comms baudrate, return true if ACK is
97  * OK. baud can be: 9600, 19200, 38400, 500000 */
98  bool LMS_setupBaudrate(int baud);
99  /** Send a status query and wait for the answer. Return true on OK. */
100  bool LMS_statusQuery();
101  /** Returns false if timeout */
102  bool LMS_waitACK(uint16_t timeout_ms);
103  /** Returns false if timeout */
104  bool LMS_waitIncomingFrame(uint16_t timeout);
105  /** Returns false on error */
108  bool LMS_endContinuousMode();
109 
110  /** Send header+command-data+crc and waits for ACK. Return false on error.
111  */
112  bool SendCommandToSICK(const uint8_t* cmd, const uint16_t cmd_len);
113 
115 
116  /** If set to non-empty, the serial port will be attempted to be opened
117  * automatically when this class is first used to request data from the
118  * laser. */
120  /** Will be !=nullptr only if I created it, so I must destroy it at the end.
121  */
123  /** Baudrate: 9600, 38400, 500000 */
125  /** Default = 1 */
126  unsigned int m_nTries_connect;
127  unsigned int m_nTries_current;
128  /** If true, doesn't send the initialization commands to the laser and go
129  * straight to capturing */
131 
132  protected:
133  /** See the class documentation at the top for expected parameters */
135  const mrpt::config::CConfigFileBase& configSource,
136  const std::string& iniSection);
137 
138  public:
139  /** Constructor */
141 
142  /** Destructor */
143  virtual ~CSickLaserSerial();
144 
145  /** Changes the serial port to connect to (call prior to 'doProcess'), for
146  * example "COM1" or "ttyS0".
147  * This is not needed if the configuration is loaded with "loadConfig".
148  */
149  void setSerialPort(const std::string& port) { m_com_port = port; }
150  /** \sa setSerialPort */
152  /** Changes the serial port baud rate (call prior to 'doProcess'); valid
153  * values are 9600,38400 and 500000.
154  * This is not needed if the configuration is loaded with "loadConfig".
155  * \sa getBaudRate */
156  void setBaudRate(int baud) { m_com_baudRate = baud; }
157  /** \sa setBaudRate */
158  int getBaudRate() const { return m_com_baudRate; }
159  /** Enables/Disables the millimeter mode, with a greater accuracy but a
160  * shorter range (default=false)
161  * (call prior to 'doProcess') This is not needed if the configuration is
162  * loaded with "loadConfig".
163  */
164  void setMillimeterMode(bool mm_mode = true) { m_mm_mode = mm_mode; }
165  /** Set the scanning field of view - possible values are 100 or 180
166  * (default)
167  * (call prior to 'doProcess') This is not needed if the configuration is
168  * loaded with "loadConfig".
169  */
170  void setScanFOV(int fov_degrees) { m_scans_FOV = fov_degrees; }
171  int getScanFOV() const { return m_scans_FOV; }
172  /** Set the scanning resolution, in units of 1/100 degree - Possible values
173  * are 25, 50 and 100, for 0.25, 0.5 (default) and 1 deg.
174  * (call prior to 'doProcess') This is not needed if the configuration is
175  * loaded with "loadConfig".
176  */
177  void setScanResolution(int res_1_100th_degree)
178  {
179  m_scans_res = res_1_100th_degree;
180  }
181  int getScanResolution() const { return m_scans_res; }
182  /** If performing several tries in ::initialize(), this is the current try
183  * loop number. */
184  unsigned int getCurrentConnectTry() const { return m_nTries_current; }
185  /** Specific laser scanner "software drivers" must process here new data
186  * from the I/O stream, and, if a whole scan has arrived, return it.
187  * This method will be typically called in a different thread than other
188  * methods, and will be called in a timely fashion.
189  */
190  void doProcessSimple(
191  bool& outThereIsObservation,
192  mrpt::obs::CObservation2DRangeScan& outObservation,
193  bool& hardwareError);
194 
195  /** Set-up communication with the laser.
196  * Called automatically by rawlog-grabber.
197  * If used manually, call after "loadConfig" and before "doProcess".
198  *
199  * In this class this method does nothing, since the communications are
200  * setup at the first try from "doProcess" or "doProcessSimple".
201  */
202  void initialize();
203 
204  /** Enables the scanning mode (in this class this has no effect).
205  * \return If everything works "true", or "false" if there is any error.
206  */
207  bool turnOn();
208 
209  /** Disables the scanning mode (in this class this has no effect).
210  * \return If everything works "true", or "false" if there is any error.
211  */
212  bool turnOff();
213 
214 }; // End of class
215 
216 } // End of namespace
217 } // End of namespace
218 
219 #endif
mrpt::hwdrivers::CSickLaserSerial::CRC16_GEN_POL
static int CRC16_GEN_POL
Definition: CSickLaserSerial.h:84
mrpt::hwdrivers::CSickLaserSerial::getScanResolution
int getScanResolution() const
Definition: CSickLaserSerial.h:181
mrpt::hwdrivers::CSickLaserSerial::getCurrentConnectTry
unsigned int getCurrentConnectTry() const
If performing several tries in ::initialize(), this is the current try loop number.
Definition: CSickLaserSerial.h:184
uint16_t
unsigned __int16 uint16_t
Definition: rptypes.h:44
mrpt::hwdrivers::CSickLaserSerial::LMS_statusQuery
bool LMS_statusQuery()
Send a status query and wait for the answer.
Definition: CSickLaserSerial.cpp:526
mrpt::obs::CObservation2DRangeScan
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
Definition: CObservation2DRangeScan.h:56
mrpt::hwdrivers::CSickLaserSerial::setMillimeterMode
void setMillimeterMode(bool mm_mode=true)
Enables/Disables the millimeter mode, with a greater accuracy but a shorter range (default=false) (ca...
Definition: CSickLaserSerial.h:164
mrpt::hwdrivers::CSickLaserSerial::m_mm_mode
bool m_mm_mode
Definition: CSickLaserSerial.h:75
mrpt::hwdrivers::CSickLaserSerial::initialize
void initialize()
Set-up communication with the laser.
Definition: CSickLaserSerial.cpp:392
mrpt::hwdrivers::CSickLaserSerial::m_com_baudRate
int m_com_baudRate
Baudrate: 9600, 38400, 500000.
Definition: CSickLaserSerial.h:124
mrpt::hwdrivers::CSickLaserSerial::getSerialPort
std::string getSerialPort() const
Definition: CSickLaserSerial.h:151
CSerialPort.h
mrpt::hwdrivers::CSickLaserSerial::m_com_port
std::string m_com_port
If set to non-empty, the serial port will be attempted to be opened automatically when this class is ...
Definition: CSickLaserSerial.h:119
mrpt::comms::CSerialPort
A communications serial port built as an implementation of a utils::CStream.
Definition: CSerialPort.h:43
mrpt::hwdrivers::CSickLaserSerial::m_skip_laser_config
bool m_skip_laser_config
If true, doesn't send the initialization commands to the laser and go straight to capturing.
Definition: CSickLaserSerial.h:130
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::hwdrivers::CSickLaserSerial::LMS_setupBaudrate
bool LMS_setupBaudrate(int baud)
Send a command to change the LMS comms baudrate, return true if ACK is OK.
Definition: CSickLaserSerial.cpp:490
DEFINE_GENERIC_SENSOR
#define DEFINE_GENERIC_SENSOR(class_name)
This declaration must be inserted in all CGenericSensor classes definition, within the class declarat...
Definition: CGenericSensor.h:314
uint8_t
unsigned char uint8_t
Definition: rptypes.h:41
mrpt::hwdrivers::CSickLaserSerial::CSickLaserSerial
CSickLaserSerial()
Constructor
Definition: CSickLaserSerial.cpp:43
mrpt::hwdrivers::CSickLaserSerial::tryToOpenComms
bool tryToOpenComms(std::string *err_msg=nullptr)
Tries to open the com port and setup all the LMS protocol.
Definition: CSickLaserSerial.cpp:197
mrpt::hwdrivers::CSickLaserSerial::getBaudRate
int getBaudRate() const
Definition: CSickLaserSerial.h:158
mrpt::hwdrivers::CSickLaserSerial::m_sensorPose
mrpt::math::TPose3D m_sensorPose
The sensor 6D pose:
Definition: CSickLaserSerial.h:82
lightweight_geom_data.h
mrpt::hwdrivers::CSickLaserSerial::LMS_setupSerialComms
bool LMS_setupSerialComms()
Assures laser is connected and operating at 38400, in its case returns true.
Definition: CSickLaserSerial.cpp:407
mrpt::hwdrivers::C2DRangeFinderAbstract
This is the base, abstract class for "software drivers" interfaces to 2D scanners (laser range finder...
Definition: C2DRangeFinderAbstract.h:43
mrpt::hwdrivers::CSickLaserSerial::m_received_frame_buffer
uint8_t m_received_frame_buffer[2000]
Definition: CSickLaserSerial.h:114
mrpt::hwdrivers::CSickLaserSerial::~CSickLaserSerial
virtual ~CSickLaserSerial()
Destructor
Definition: CSickLaserSerial.cpp:61
mrpt::hwdrivers::CSickLaserSerial::setScanFOV
void setScanFOV(int fov_degrees)
Set the scanning field of view - possible values are 100 or 180 (default) (call prior to 'doProcess')...
Definition: CSickLaserSerial.h:170
mrpt::hwdrivers::CSickLaserSerial::SendCommandToSICK
bool SendCommandToSICK(const uint8_t *cmd, const uint16_t cmd_len)
Send header+command-data+crc and waits for ACK.
Definition: CSickLaserSerial.cpp:785
mrpt::config::CConfigFileBase
This class allows loading and storing values and vectors of different types from a configuration text...
Definition: config/CConfigFileBase.h:44
mrpt::hwdrivers::CSickLaserSerial::LMS_waitIncomingFrame
bool LMS_waitIncomingFrame(uint16_t timeout)
Returns false if timeout.
Definition: CSickLaserSerial.cpp:565
mrpt::hwdrivers::CSickLaserSerial::m_scans_res
int m_scans_res
1/100th of deg: 100, 50 or 25
Definition: CSickLaserSerial.h:79
mrpt::hwdrivers::CSickLaserSerial::m_nTries_current
unsigned int m_nTries_current
Definition: CSickLaserSerial.h:127
mrpt::hwdrivers::CSickLaserSerial::waitContinuousSampleFrame
bool waitContinuousSampleFrame(std::vector< float > &ranges, unsigned char &LMS_status, bool &is_mm_mode)
Definition: CSickLaserSerial.cpp:281
mrpt::math::TPose3D
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
Definition: lightweight_geom_data.h:603
mrpt::hwdrivers::CSickLaserSerial::loadConfig_sensorSpecific
void loadConfig_sensorSpecific(const mrpt::config::CConfigFileBase &configSource, const std::string &iniSection)
See the class documentation at the top for expected parameters.
Definition: CSickLaserSerial.cpp:148
mrpt::hwdrivers::CSickLaserSerial
This "software driver" implements the communication protocol for interfacing a SICK LMS 2XX laser sca...
Definition: CSickLaserSerial.h:70
mrpt::hwdrivers::CSickLaserSerial::setScanResolution
void setScanResolution(int res_1_100th_degree)
Set the scanning resolution, in units of 1/100 degree - Possible values are 25, 50 and 100,...
Definition: CSickLaserSerial.h:177
mrpt::hwdrivers::CSickLaserSerial::setBaudRate
void setBaudRate(int baud)
Changes the serial port baud rate (call prior to 'doProcess'); valid values are 9600,...
Definition: CSickLaserSerial.h:156
mrpt::hwdrivers::CSickLaserSerial::m_nTries_connect
unsigned int m_nTries_connect
Default = 1.
Definition: CSickLaserSerial.h:126
mrpt::hwdrivers::CSickLaserSerial::m_mySerialPort
mrpt::comms::CSerialPort * m_mySerialPort
Will be !=nullptr only if I created it, so I must destroy it at the end.
Definition: CSickLaserSerial.h:122
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::hwdrivers::CSickLaserSerial::turnOn
bool turnOn()
Enables the scanning mode (in this class this has no effect).
Definition: CSickLaserSerial.cpp:188
mrpt::hwdrivers::CSickLaserSerial::LMS_endContinuousMode
bool LMS_endContinuousMode()
Definition: CSickLaserSerial.cpp:770
mrpt::hwdrivers::CSickLaserSerial::LMS_sendMeasuringMode_cm_mm
bool LMS_sendMeasuringMode_cm_mm()
Returns false on error.
Definition: CSickLaserSerial.cpp:636
mrpt::hwdrivers::CSickLaserSerial::m_scans_FOV
int m_scans_FOV
100 or 180 deg
Definition: CSickLaserSerial.h:77
mrpt::hwdrivers::CSickLaserSerial::getScanFOV
int getScanFOV() const
Definition: CSickLaserSerial.h:171
mrpt::hwdrivers::CSickLaserSerial::setSerialPort
void setSerialPort(const std::string &port)
Changes the serial port to connect to (call prior to 'doProcess'), for example "COM1" or "ttyS0".
Definition: CSickLaserSerial.h:149
mrpt::hwdrivers::CSickLaserSerial::doProcessSimple
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,...
Definition: CSickLaserSerial.cpp:87
mrpt::hwdrivers::CSickLaserSerial::turnOff
bool turnOff()
Disables the scanning mode (in this class this has no effect).
Definition: CSickLaserSerial.cpp:192
mrpt::hwdrivers::CSickLaserSerial::LMS_startContinuousMode
bool LMS_startContinuousMode()
Definition: CSickLaserSerial.cpp:736
mrpt::hwdrivers::CSickLaserSerial::LMS_waitACK
bool LMS_waitACK(uint16_t timeout_ms)
Returns false if timeout.
Definition: CSickLaserSerial.cpp:539
C2DRangeFinderAbstract.h



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST