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



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST