class mrpt::hwdrivers::CCANBusReader

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)


  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

See also:

C2DRangeFinderAbstract

#include <mrpt/hwdrivers/CCANBusReader.h>

class CCANBusReader:
    public mrpt::system::COutputLogger,
    public mrpt::hwdrivers::CGenericSensor
{
public:
    //
methods

    void setSerialPort(const std::string& port);
    std::string getSerialPort() const;
    void setBaudRate(int baud);
    int getBaudRate() const;
    void setCANReaderTimeStamping(bool setTimestamp = false);
    bool getCANReaderTimeStamping();
    void setCANReaderSpeed(const unsigned int speed);
    unsigned int getCANReaderSpeed();
    unsigned int getCurrentConnectTry() const;
    void doProcessSimple(bool& outThereIsObservation, mrpt::obs::CObservationCANBusJ1939& outObservation, bool& hardwareError);
    virtual void initialize();
    virtual void doProcess();
};

Inherited Members

public:
    // structs

    struct TMsg;

    //
methods

    CGenericSensor& operator = (const CGenericSensor&);
    virtual void doProcess() = 0;

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:

setSerialPort

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:

getBaudRate

int getBaudRate() const

See also:

setBaudRate

void setCANReaderTimeStamping(bool setTimestamp = false)

Enables/Disables the addition of a timestamp according to the arrival time to the converter (default=false) (call prior to ‘doProcess’) This is not needed if the configuration is loaded with “loadConfig”.

void setCANReaderSpeed(const unsigned int speed)

Sets the CAN reader speed when connecting to the CAN Bus.

unsigned int getCurrentConnectTry() const

If performing several tries in initialize(), this is the current try loop number.

void doProcessSimple(
    bool& outThereIsObservation,
    mrpt::obs::CObservationCANBusJ1939& 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 void doProcess()

This method will be invoked at a minimum rate of “process_rate” (Hz)

Parameters:

This

method must throw an exception with a descriptive message if some critical error is found.