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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020