MRPT  2.0.4
CEnoseModular.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
13 #include <mrpt/comms/CSerialPort.h>
17 #include <memory> // unique_ptr
18 
19 namespace mrpt::hwdrivers
20 {
21 /** A class for interfacing an e-NoseModular via a FTDI USB link.
22  * Implemented for the Mdular board v1.0 designed by 2013 @ MAPIR (University
23  * of Malaga).
24  *
25  * \code
26  * PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS:
27  * -------------------------------------------------------
28  * [supplied_section_name]
29  * USB_serialname=ENOSE001 // USB FTDI pipe: will open only if COM_port_*
30  * are not set or empty
31  *
32  * COM_port_WIN = COM1 // Serial port to connect to.
33  * COM_port_LIN = ttyS0
34  *
35  * COM_baudRate = 115200
36  *
37  * ; 3D position (in meters) of the master +slave eNoses
38  * enose_poses_x=<MASTER X> <SLAVE#1 X> <SLAVE#2 X> <SLAVE#3 X>...
39  * enose_poses_y=<MASTER Y> <SLAVE#1 Y> <SLAVE#2 Y> <SLAVE#3 Y>...
40  * enose_poses_z=<MASTER Z> <SLAVE#1 Z> <SLAVE#2 Z> <SLAVE#3 Z>...
41  *
42  * ; 3D pose angles (in degrees) of the master +slave eNoses
43  * enose_poses_yaw=<MASTER YAW> <SLAVE#1 YAW> <SLAVE#2 YAW> <SLAVE#3 YAW>...
44  * enose_poses_pitch=<MASTER PITCH> <SLAVE#1 PITCH> <SLAVE#2 PITCH> <SLAVE#3
45  * PITCH>...
46  * enose_poses_roll=<MASTER ROLL> <SLAVE#1 ROLL> <SLAVE#2 ROLL> <SLAVE#3
47  * ROLL>...
48  *
49  * \endcode
50  *
51  * \ingroup mrpt_hwdrivers_grp
52  */
54 {
56 
57  protected:
58  /** A copy of the device serial number (to open the USB FTDI chip)
59  */
60  std::string m_usbSerialNumber;
63 
64  /** If not an empty string (default), will open that serial port, otherwise
65  * will try to open USB FTDI device "m_usbSerialNumber" */
66  std::string m_COM_port;
67  /** Default=115200 */
68  unsigned int m_COM_baud{115200};
69 
70  // Only one of these two streams will be !=nullptr and open for each
71  // specific eNose board!
72  /** FTDI comms pipe (when not in serial port mode) */
73  std::unique_ptr<mrpt::comms::CInterfaceFTDI> m_stream_FTDI;
74  /** Serial port comms */
75  std::unique_ptr<mrpt::comms::CSerialPort> m_stream_SERIAL;
76 
77  /** The 3D pose of the master + N slave eNoses on the robot (meters &
78  * radians) */
81 
82  /** Tries to connect to the USB device (if disconnected).
83  * \return nullptr on error, otherwise a stream to be used for comms.
84  */
86 
87  /** See the class documentation at the top for expected parameters */
89  const mrpt::config::CConfigFileBase& configSource,
90  const std::string& section) override;
91 
92  /** Purge the Serial/FTDI buffer */
93  void purgeBuffers();
94 
95  public:
96  /** Constructor
97  * \param serialNumberUSBdevice The serial number (text) of the device to
98  * open.
99  * The constructor will try to open the device. You can check if it failed
100  * calling "isOpen()".
101  */
102  CEnoseModular();
103 
104  /** Request the master eNose the latest readings from all the eNoses.
105  * The output observation contains a valid timestamp and 3D positions if
106  * "loadConfig" has been called previously.
107  * \return true if OK, false if there were any error.
108  */
110 
111  // See docs in parent class
112  void doProcess() override;
113 
114  /** If not an empty string, will open that serial port, otherwise will try
115  * to open USB FTDI device "m_usbSerialNumber"
116  * The default is an empty string. Example strings: "COM1", "ttyUSB0", ...
117  */
118  inline void setSerialPort(const std::string& port) { m_COM_port = port; }
119  inline std::string getSerialPort() const { return m_COM_port; }
120  /** Set the serial port baud rate (default: 115200) */
121  inline void setSerialPortBaud(unsigned int baud) { m_COM_baud = baud; }
122  inline unsigned int getSerialPortBaud() const { return m_COM_baud; }
123 }; // end of class
124 } // namespace mrpt::hwdrivers
A generic interface for a wide-variety of sensors designed to be used in the application RawLogGrabbe...
std::vector< float > enose_poses_z
Definition: CEnoseModular.h:79
std::vector< float > enose_poses_roll
Definition: CEnoseModular.h:79
void purgeBuffers()
Purge the Serial/FTDI buffer.
void setSerialPort(const std::string &port)
If not an empty string, will open that serial port, otherwise will try to open USB FTDI device "m_usb...
std::string getSerialPort() const
Contains classes for various device interfaces.
std::vector< float > enose_poses_yaw
Definition: CEnoseModular.h:79
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: io/CStream.h:28
mrpt::Clock::time_point TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:40
This class allows loading and storing values and vectors of different types from a configuration text...
std::vector< float > enose_poses_pitch
Definition: CEnoseModular.h:79
void setSerialPortBaud(unsigned int baud)
Set the serial port baud rate (default: 115200)
mrpt::system::TTimeStamp initial_timestamp
Definition: CEnoseModular.h:61
std::string m_usbSerialNumber
A copy of the device serial number (to open the USB FTDI chip)
Definition: CEnoseModular.h:60
std::vector< float > enose_poses_x
The 3D pose of the master + N slave eNoses on the robot (meters & radians)
Definition: CEnoseModular.h:79
std::unique_ptr< mrpt::comms::CSerialPort > m_stream_SERIAL
Serial port comms.
Definition: CEnoseModular.h:75
Declares a class derived from "CObservation" that represents a set of readings from gas sensors...
std::string m_COM_port
If not an empty string (default), will open that serial port, otherwise will try to open USB FTDI dev...
Definition: CEnoseModular.h:66
std::vector< float > enose_poses_y
Definition: CEnoseModular.h:79
mrpt::io::CStream * checkConnectionAndConnect()
Tries to connect to the USB device (if disconnected).
#define DEFINE_GENERIC_SENSOR(class_name)
This declaration must be inserted in all CGenericSensor classes definition, within the class declarat...
unsigned int getSerialPortBaud() const
bool getObservation(mrpt::obs::CObservationGasSensors &outObservation)
Request the master eNose the latest readings from all the eNoses.
unsigned int m_COM_baud
Default=115200.
Definition: CEnoseModular.h:68
void doProcess() override
This method should be called periodically (at least at 1Hz to capture ALL the real-time data) It is t...
std::unique_ptr< mrpt::comms::CInterfaceFTDI > m_stream_FTDI
FTDI comms pipe (when not in serial port mode)
Definition: CEnoseModular.h:73
void loadConfig_sensorSpecific(const mrpt::config::CConfigFileBase &configSource, const std::string &section) override
See the class documentation at the top for expected parameters.
A class for interfacing an e-NoseModular via a FTDI USB link.
Definition: CEnoseModular.h:53



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020