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



Page generated by Doxygen 1.9.1 for MRPT 1.4.0 SVN: at Sat Jan 30 21:34:41 UTC 2021