class mrpt::hwdrivers::CSickLaserSerial
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) //skip_laser_config = true // (Default:false) If true, doesn't send the initialization commands to the laser and go straight to capturing 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 //preview = true // Enable GUI visualization of captured data // Optional: Exclusion zones to avoid the robot seeing itself: //exclusionZone1_x = 0.20 0.30 0.30 0.20 //exclusionZone1_y = 0.20 0.30 0.30 0.20 // Optional: Exclusion zones to avoid the robot seeing itself: //exclusionAngles1_ini = 20 // Deg //exclusionAngles1_end = 25 // Deg
See also:
#include <mrpt/hwdrivers/CSickLaserSerial.h> class CSickLaserSerial: public mrpt::hwdrivers::C2DRangeFinderAbstract { public: // construction CSickLaserSerial(); // methods void setSerialPort(const std::string& port); std::string getSerialPort() const; void setBaudRate(int baud); int getBaudRate() const; void setMillimeterMode(bool mm_mode = true); void setScanFOV(int fov_degrees); int getScanFOV() const; void setScanResolution(int res_1_100th_degree); int getScanResolution() const; unsigned int getCurrentConnectTry() const; virtual void doProcessSimple( bool& outThereIsObservation, mrpt::obs::CObservation2DRangeScan& outObservation, bool& hardwareError ); virtual void initialize(); virtual bool turnOn(); virtual bool turnOff(); };
Inherited Members
public: // enums enum TSensorState; // structs struct TMsg; // fields bool logging_enable_console_output {true}; bool logging_enable_keep_record {false}; // methods CGenericSensor& operator = (const CGenericSensor&); virtual void doProcess() = 0; void logStr(const VerbosityLevel level, std::string_view msg_str) const; void logFmt(const VerbosityLevel level, const char* fmt, ...) const; void void logCond(const VerbosityLevel level, bool cond, const std::string& msg_str) const; void setLoggerName(const std::string& name); std::string getLoggerName() const; void setVerbosityLevel(const VerbosityLevel level); void setVerbosityLevelForCallbacks(const VerbosityLevel level); void setMinLoggingLevel(const VerbosityLevel level); VerbosityLevel getMinLoggingLevel() const; VerbosityLevel getMinLoggingLevelForCallbacks() const; void getLogAsString(std::string& log_contents) const; std::string getLogAsString() const; void writeLogToFile(const std::optional<std::string> fname_in = std::nullopt) const; void dumpLogToConsole() const; std::string getLoggerLastMsg() const; void getLoggerLastMsg(std::string& msg_str) const; void loggerReset(); bool logDeregisterCallback(output_logger_callback_t userFunc); void showPreview(bool enable = true); void bindIO(const std::shared_ptr<mrpt::io::CStream>& streamIO); void getObservation(bool& outThereIsObservation, mrpt::obs::CObservation2DRangeScan& outObservation, bool& hardwareError); virtual void doProcess(); virtual void doProcessSimple( bool& outThereIsObservation, mrpt::obs::CObservation2DRangeScan& outObservation, bool& hardwareError ) = 0; virtual bool turnOn() = 0; virtual bool turnOff() = 0; double getEstimatedScanPeriod() const; TSensorState getState() const; void enableVerbose(bool enabled = true); void loadConfig(const mrpt::config::CConfigFileBase& configSource, const std::string& section); virtual void initialize(); void getObservations(TListObservations& lstObjects); TListObservations getObservations(); virtual void setPathForExternalImages(] const std::string& directory); void setExternalImageFormat(const std::string& ext); void setExternalImageJPEGQuality(const unsigned int quality); static std::array<mrpt::system::ConsoleForegroundColor, NUMBER_OF_VERBOSITY_LEVELS>& logging_levels_to_colors(); static std::array<std::string, NUMBER_OF_VERBOSITY_LEVELS>& logging_levels_to_names(); static void registerClass(const TSensorClassId* pNewClass); static CGenericSensor* createSensor(const std::string& className); static Ptr createSensorPtr(const std::string& className);
Construction
CSickLaserSerial()
Constructor.
Methods
void setSerialPort(const std::string& port)
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”.
std::string getSerialPort() const
See also:
void setBaudRate(int baud)
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:
int getBaudRate() const
See also:
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”.
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.
(call prior to ‘doProcess’) This is not needed if the configuration is loaded with “loadConfig”.
unsigned int getCurrentConnectTry() const
If performing several tries in initialize(), this is the current try loop number.
virtual 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, 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.
virtual void initialize()
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”.
virtual bool turnOn()
Enables the scanning mode (in this class this has no effect).
Returns:
If everything works “true”, or “false” if there is any error.
virtual bool turnOff()
Disables the scanning mode (in this class this has no effect).
Returns:
If everything works “true”, or “false” if there is any error.