Main MRPT website > C++ reference for MRPT 1.4.0
CCANBusReader.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 CCANBusReader_H
10 #define CCANBusReader_H
11 
16 
17 namespace mrpt
18 {
19  namespace hwdrivers
20  {
21  /** 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).
22  * The serial port is opened upon the first call to "doProcess" or "initialize", so you must call "loadConfig" before
23  * this, or manually call "setSerialPort". Another alternative is to call the base class method C2DRangeFinderAbstract::bindIO,
24  * but the "setSerialPort" interface is probably much simpler to use.
25  *
26  * For an example of usage see the example in "samples/SICK_laser_serial_test".
27  * See also the example configuration file for rawlog-grabber in "share/mrpt/config_files/rawlog-grabber".
28  *
29  * \code
30  * PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS:
31  * -------------------------------------------------------
32  * [supplied_section_name]
33  * COM_port_WIN = COM1 // Serial port to connect to
34  * COM_port_LIN = ttyS0
35  *
36  * COM_baudRate = 38400 // Possible values: 9600 (default), 38400, 5000000
37  * mm_mode = 1/0 // 1: millimeter mode, 0:centimeter mode (Default=0)
38  * FOV = 180 // Field of view: 100 or 180 degrees (Default=180)
39  * resolution = 50 // Scanning resolution, in units of 1/100 degree. Valid values: 25,50,100 (Default=50)
40  *
41  *
42  * pose_x=0.21 // Laser range scaner 3D position in the robot (meters)
43  * pose_y=0
44  * pose_z=0.34
45  * pose_yaw=0 // Angles in degrees
46  * pose_pitch=0
47  * pose_roll=0
48  * \endcode
49  *
50  * \sa C2DRangeFinderAbstract
51  * \ingroup mrpt_hwdrivers_grp
52  */
54  {
56 
57  private:
58 
59  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.
61  uint8_t &out_prio,
62  uint8_t &out_pdu_format,
63  uint8_t &out_pdu_spec,
64  uint8_t &out_src_address,
65  uint8_t &out_data_length,
66  uint16_t &out_pgn,
67  std::vector<uint8_t> &out_data,
68  std::vector<char> &out_raw_frame);
69 
70  bool sendCANBusReaderSpeed(); //!< Sends the specified speed to the CAN Converter.
71  bool CANBusOpenChannel(); //!< Opens the CAN Channel
72  bool CANBusCloseChannel(); //!< Closes the CAN Channel
74  bool CANBusPoll();
75  bool CANBusX1();
77  bool queryVersion(bool printOutVersion = false);
78  bool waitACK(uint16_t timeout_ms);
79  bool waitForVersion(uint16_t timeout, bool printOutVersion = false);
80  bool waitIncomingFrame(uint16_t timeout);
81 
82  bool sendCommandToCANReader(const uint8_t *cmd, const uint16_t cmd_len, bool wait = true);
83 
84  uint8_t m_received_frame_buffer[2000];
85 
86  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.
87  CSerialPort *m_mySerialPort; //!< Will be !=NULL only if I created it, so I must destroy it at the end.
88  int m_com_baudRate; //!< Baudrate: 9600, 38400, 500000
89  unsigned int m_nTries_connect; //!< Default = 1
90  unsigned int m_nTries_current;
92  bool m_canreader_timestamp; // for future work
93  bool m_CANBusChannel_isOpen; // if the can bus channel is open or not
94 
95  protected:
96  /** See the class documentation at the top for expected parameters */
98  const mrpt::utils::CConfigFileBase &configSource,
99  const std::string &iniSection );
100 
101  public:
102  /** Constructor */
104 
105  /** Destructor */
106  virtual ~CCANBusReader();
107 
108  /** Changes the serial port to connect to (call prior to 'doProcess'), for example "COM1" or "ttyS0".
109  * This is not needed if the configuration is loaded with "loadConfig".
110  */
111  void setSerialPort(const std::string &port) { m_com_port = port; }
112 
113  /** \sa setSerialPort */
114  std::string getSerialPort() const { return m_com_port; }
115 
116  /** Changes the serial port baud rate (call prior to 'doProcess'); valid values are 9600,38400 and 500000.
117  * This is not needed if the configuration is loaded with "loadConfig".
118  * \sa getBaudRate */
119  void setBaudRate(int baud) { m_com_baudRate = baud; }
120  /** \sa setBaudRate */
121  int getBaudRate() const { return m_com_baudRate; }
122 
123  /** Enables/Disables the addition of a timestamp according to the arrival time to the converter (default=false)
124  * (call prior to 'doProcess') This is not needed if the configuration is loaded with "loadConfig".
125  */
126  void setCANReaderTimeStamping( bool setTimestamp = false ) { m_canreader_timestamp = setTimestamp; }
127  bool getCANReaderTimeStamping( ) { return m_canreader_timestamp; }
128 
129  /** Sets the CAN reader speed when connecting to the CAN Bus
130  */
131  void setCANReaderSpeed( const unsigned int speed ) { m_canbus_speed = speed; }
132  unsigned int getCANReaderSpeed( ) { return m_canbus_speed; }
133 
134  /** If performing several tries in ::initialize(), this is the current try loop number. */
135  unsigned int getCurrentConnectTry() const { return m_nTries_current; }
136 
137  /** Specific laser scanner "software drivers" must process here new data from the I/O stream, and, if a whole scan has arrived, return it.
138  * This method will be typically called in a different thread than other methods, and will be called in a timely fashion.
139  */
141  bool &outThereIsObservation,
142  mrpt::obs::CObservationCANBusJ1939 &outObservation,
143  bool &hardwareError );
144 
145  /** Set-up communication with the laser.
146  * Called automatically by rawlog-grabber.
147  * If used manually, call after "loadConfig" and before "doProcess".
148  *
149  * In this class this method does nothing, since the communications are setup at the first try from "doProcess" or "doProcessSimple".
150  */
151  void initialize();
152 
153  void doProcess();
154 
155  }; // End of class
156 
157  } // End of namespace
158 } // End of namespace
159 
160 #endif
mrpt::hwdrivers::CCANBusReader::m_nTries_current
unsigned int m_nTries_current
Definition: CCANBusReader.h:90
mrpt::hwdrivers::CCANBusReader::getCANReaderTimeStamping
bool getCANReaderTimeStamping()
Definition: CCANBusReader.h:127
mrpt::utils::CDebugOutputCapable
This base class provides a common printf-like method to send debug information to std::cout,...
Definition: CDebugOutputCapable.h:32
mrpt::hwdrivers::CCANBusReader::waitForVersion
bool waitForVersion(uint16_t timeout, bool printOutVersion=false)
mrpt::hwdrivers::CCANBusReader::doProcessSimple
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,...
CDebugOutputCapable.h
mrpt::hwdrivers::CCANBusReader::~CCANBusReader
virtual ~CCANBusReader()
Destructor
mrpt::hwdrivers::CCANBusReader::setCANReaderSpeed
void setCANReaderSpeed(const unsigned int speed)
Sets the CAN reader speed when connecting to the CAN Bus.
Definition: CCANBusReader.h:131
mrpt::hwdrivers::CCANBusReader::initialize
void initialize()
Set-up communication with the laser.
mrpt::hwdrivers::CCANBusReader::CANBusOpenChannel
bool CANBusOpenChannel()
Opens the CAN Channel.
mrpt::hwdrivers::CCANBusReader::CANBusPoll
bool CANBusPoll()
mrpt::hwdrivers::CCANBusReader::CANBusX1
bool CANBusX1()
CObservationCANBusJ1939.h
mrpt::hwdrivers::CCANBusReader::setSerialPort
void setSerialPort(const std::string &port)
Changes the serial port to connect to (call prior to 'doProcess'), for example "COM1" or "ttyS0".
Definition: CCANBusReader.h:111
CSerialPort.h
mrpt::hwdrivers::CCANBusReader::getCurrentConnectTry
unsigned int getCurrentConnectTry() const
If performing several tries in ::initialize(), this is the current try loop number.
Definition: CCANBusReader.h:135
mrpt::hwdrivers::CCANBusReader::doProcess
void doProcess()
This method will be invoked at a minimum rate of "process_rate" (Hz)
mrpt::hwdrivers::CCANBusReader::setupSerialComms
bool setupSerialComms()
mrpt::hwdrivers::CCANBusReader::m_com_port
std::string m_com_port
If set to non-empty, the serial port will be attempted to be opened automatically when this class is ...
Definition: CCANBusReader.h:86
mrpt::hwdrivers::CCANBusReader::sendCANBusReaderSpeed
bool sendCANBusReaderSpeed()
Sends the specified speed to the CAN Converter.
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CParticleFilter.h:17
DEFINE_GENERIC_SENSOR
#define DEFINE_GENERIC_SENSOR(class_name)
This declaration must be inserted in all CGenericSensor classes definition, within the class declarat...
Definition: CGenericSensor.h:251
mrpt::hwdrivers::CCANBusReader::CANBusCloseChannel
bool CANBusCloseChannel()
Closes the CAN Channel.
mrpt::hwdrivers::CCANBusReader::m_CANBusChannel_isOpen
bool m_CANBusChannel_isOpen
Definition: CCANBusReader.h:93
mrpt::hwdrivers::CCANBusReader::m_nTries_connect
unsigned int m_nTries_connect
Default = 1.
Definition: CCANBusReader.h:89
mrpt::hwdrivers::CCANBusReader::m_com_baudRate
int m_com_baudRate
Baudrate: 9600, 38400, 500000.
Definition: CCANBusReader.h:88
mrpt::hwdrivers::CCANBusReader::getCANReaderSpeed
unsigned int getCANReaderSpeed()
Definition: CCANBusReader.h:132
mrpt::hwdrivers::CCANBusReader::setCANReaderTimeStamping
void setCANReaderTimeStamping(bool setTimestamp=false)
Enables/Disables the addition of a timestamp according to the arrival time to the converter (default=...
Definition: CCANBusReader.h:126
mrpt::hwdrivers::CCANBusReader::m_canreader_timestamp
bool m_canreader_timestamp
Definition: CCANBusReader.h:92
mrpt::hwdrivers::CCANBusReader::tryToOpenComms
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.
mrpt::hwdrivers::CCANBusReader::waitACK
bool waitACK(uint16_t timeout_ms)
mrpt::utils::CConfigFileBase
This class allows loading and storing values and vectors of different types from a configuration text...
Definition: CConfigFileBase.h:31
CGenericSensor.h
mrpt::hwdrivers::CCANBusReader::CANBusAutoPoll
bool CANBusAutoPoll()
mrpt::hwdrivers::CCANBusReader::loadConfig_sensorSpecific
void loadConfig_sensorSpecific(const mrpt::utils::CConfigFileBase &configSource, const std::string &iniSection)
See the class documentation at the top for expected parameters.
mrpt::hwdrivers::CCANBusReader::sendCommandToCANReader
bool sendCommandToCANReader(const uint8_t *cmd, const uint16_t cmd_len, bool wait=true)
mrpt::hwdrivers::CCANBusReader::getBaudRate
int getBaudRate() const
Definition: CCANBusReader.h:121
mrpt::hwdrivers::CCANBusReader::CCANBusReader
CCANBusReader()
Constructor
mrpt::obs::CObservationCANBusJ1939
This class stores a message from a CAN BUS with the protocol J1939.
Definition: obs/CObservationCANBusJ1939.h:27
mrpt::hwdrivers::CSerialPort
A communications serial port built as an implementation of a utils::CStream.
Definition: CSerialPort.h:44
mrpt::hwdrivers::CGenericSensor
A generic interface for a wide-variety of sensors designed to be used in the application RawLogGrabbe...
Definition: CGenericSensor.h:64
mrpt::hwdrivers::CCANBusReader::waitContinuousSampleFrame
bool waitContinuousSampleFrame(uint8_t &out_prio, uint8_t &out_pdu_format, uint8_t &out_pdu_spec, uint8_t &out_src_address, uint8_t &out_data_length, uint16_t &out_pgn, std::vector< uint8_t > &out_data, std::vector< char > &out_raw_frame)
mrpt::hwdrivers::CCANBusReader
This "software driver" implements the communication protocol for interfacing a SICK LMS 2XX laser sca...
Definition: CCANBusReader.h:54
mrpt::hwdrivers::CCANBusReader::m_mySerialPort
CSerialPort * m_mySerialPort
Will be !=NULL only if I created it, so I must destroy it at the end.
Definition: CCANBusReader.h:87
mrpt::hwdrivers::CCANBusReader::setBaudRate
void setBaudRate(int baud)
Changes the serial port baud rate (call prior to 'doProcess'); valid values are 9600,...
Definition: CCANBusReader.h:119
mrpt::hwdrivers::CCANBusReader::getSerialPort
std::string getSerialPort() const
Definition: CCANBusReader.h:114
mrpt::hwdrivers::CCANBusReader::queryVersion
bool queryVersion(bool printOutVersion=false)
HWDRIVERS_IMPEXP
#define HWDRIVERS_IMPEXP
Definition: hwdrivers_impexp.h:82
mrpt::hwdrivers::CCANBusReader::m_canbus_speed
int m_canbus_speed
Definition: CCANBusReader.h:91
mrpt::hwdrivers::CCANBusReader::waitIncomingFrame
bool waitIncomingFrame(uint16_t timeout)



Page generated by Doxygen 1.8.20 for MRPT 1.4.0 SVN: at Thu Aug 27 02:40:23 UTC 2020