Main MRPT website > C++ reference
MRPT logo
CSickLaserSerial.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef CSickLaserSerial_H
29 #define CSickLaserSerial_H
30 
33 
34 namespace mrpt
35 {
36  namespace hwdrivers
37  {
38  /** 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).
39  * The serial port is opened upon the first call to "doProcess" or "initialize", so you must call "loadConfig" before
40  * this, or manually call "setSerialPort". Another alternative is to call the base class method C2DRangeFinderAbstract::bindIO,
41  * but the "setSerialPort" interface is probably much simpler to use.
42  *
43  * For an example of usage see the example in "samples/SICK_laser_serial_test".
44  * See also the example configuration file for rawlog-grabber in "share/mrpt/config_files/rawlog-grabber".
45  *
46  * \code
47  * PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS:
48  * -------------------------------------------------------
49  * [supplied_section_name]
50  * COM_port_WIN = COM1 // Serial port to connect to
51  * COM_port_LIN = ttyS0
52  *
53  * COM_baudRate = 38400 // Possible values: 9600 (default), 38400, 5000000
54  * mm_mode = 1/0 // 1: millimeter mode, 0:centimeter mode (Default=0)
55  * FOV = 180 // Field of view: 100 or 180 degrees (Default=180)
56  * resolution = 50 // Scanning resolution, in units of 1/100 degree. Valid values: 25,50,100 (Default=50)
57  *
58  *
59  * pose_x=0.21 // Laser range scaner 3D position in the robot (meters)
60  * pose_y=0
61  * pose_z=0.34
62  * pose_yaw=0 // Angles in degrees
63  * pose_pitch=0
64  * pose_roll=0
65  * \endcode
66  *
67  * \sa C2DRangeFinderAbstract
68  * \ingroup mrpt_hwdrivers_grp
69  */
71  {
73 
74  private:
75  bool m_mm_mode;
76  int m_scans_FOV; //!< 100 or 180 deg
77  int m_scans_res; //!< 1/100th of deg: 100, 50 or 25
78 
79  /** The sensor 6D pose: */
80  poses::TPose3D m_sensorPose;
81 
82  static int CRC16_GEN_POL;
83 
84 
85  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.
86  bool waitContinuousSampleFrame( std::vector<float> &ranges, unsigned char &LMS_status, bool &is_mm_mode );
87 
88 
89  bool LMS_setupSerialComms(); //!< Assures laser is connected and operating at 38400, in its case returns true.
90  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
91  bool LMS_statusQuery(); //!< Send a status query and wait for the answer. Return true on OK.
92  bool LMS_waitACK(uint16_t timeout_ms); //!< Returns false if timeout
93  bool LMS_waitIncomingFrame(uint16_t timeout); //!< Returns false if timeout
94  bool LMS_sendMeasuringMode_cm_mm(); //!< Returns false on error
95  bool LMS_startContinuousMode();
96  bool LMS_endContinuousMode();
97 
98  bool SendCommandToSICK(const uint8_t *cmd,const uint16_t cmd_len); //!< Send header+command-data+crc and waits for ACK. Return false on error.
99 
100  uint8_t m_received_frame_buffer[2000];
101 
102  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.
103  CSerialPort *m_mySerialPort; //!< Will be !=NULL only if I created it, so I must destroy it at the end.
104  int m_com_baudRate; //!< Baudrate: 9600, 38400, 500000
105  unsigned int m_nTries_connect; //!< Default = 1
106  unsigned int m_nTries_current;
107 
108  protected:
109  /** 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)
110  * See hwdrivers::CSickLaserSerial for the possible parameters
111  */
112  void loadConfig_sensorSpecific(
113  const mrpt::utils::CConfigFileBase &configSource,
114  const std::string &iniSection );
115 
116  public:
117  /** Constructor */
119 
120  /** Destructor */
121  virtual ~CSickLaserSerial();
122 
123  /** Changes the serial port to connect to (call prior to 'doProcess'), for example "COM1" or "ttyS0".
124  * This is not needed if the configuration is loaded with "loadConfig".
125  */
126  void setSerialPort(const std::string &port) { m_com_port = port; }
127 
128  /** \sa setSerialPort */
129  std::string getSerialPort() const { return m_com_port; }
130 
131  /** Changes the serial port baud rate (call prior to 'doProcess'); valid values are 9600,38400 and 500000.
132  * This is not needed if the configuration is loaded with "loadConfig".
133  * \sa getBaudRate */
134  void setBaudRate(int baud) {
135  m_com_baudRate = baud;
136  }
137  /** \sa setBaudRate */
138  int getBaudRate() const { return m_com_baudRate; }
139 
140 
141  /** Enables/Disables the millimeter mode, with a greater accuracy but a shorter range (default=false)
142  * (call prior to 'doProcess') This is not needed if the configuration is loaded with "loadConfig".
143  */
144  void setMillimeterMode(bool mm_mode=true) { m_mm_mode = mm_mode; }
145 
146  /** Set the scanning field of view - possible values are 100 or 180 (default)
147  * (call prior to 'doProcess') This is not needed if the configuration is loaded with "loadConfig".
148  */
149  void setScanFOV(int fov_degrees) { m_scans_FOV = fov_degrees; }
150  int getScanFOV() const { return m_scans_FOV; }
151 
152  /** 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.
153  * (call prior to 'doProcess') This is not needed if the configuration is loaded with "loadConfig".
154  */
155  void setScanResolution(int res_1_100th_degree) { m_scans_res=res_1_100th_degree; }
156  int getScanResolution() const { return m_scans_res; }
157 
158  /** If performing several tries in ::initialize(), this is the current try loop number. */
159  unsigned int getCurrentConnectTry() const { return m_nTries_current; }
160 
161 
162  /** Specific laser scanner "software drivers" must process here new data from the I/O stream, and, if a whole scan has arrived, return it.
163  * This method will be typically called in a different thread than other methods, and will be called in a timely fashion.
164  */
165  void doProcessSimple(
166  bool &outThereIsObservation,
167  mrpt::slam::CObservation2DRangeScan &outObservation,
168  bool &hardwareError );
169 
170 
171  /** Set-up communication with the laser.
172  * Called automatically by rawlog-grabber.
173  * If used manually, call after "loadConfig" and before "doProcess".
174  *
175  * In this class this method does nothing, since the communications are setup at the first try from "doProcess" or "doProcessSimple".
176  */
177  void initialize();
178 
179  /** Enables the scanning mode (in this class this has no effect).
180  * \return If everything works "true", or "false" if there is any error.
181  */
182  bool turnOn();
183 
184  /** Disables the scanning mode (in this class this has no effect).
185  * \return If everything works "true", or "false" if there is any error.
186  */
187  bool turnOff();
188 
189  }; // End of class
190 
191  } // End of namespace
192 } // End of namespace
193 
194 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013