MRPT  2.0.4
CBoardSonars.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 #pragma once
10 
15 
16 namespace mrpt::hwdrivers
17 {
18 /** This "software driver" implements the communication protocol for
19  * interfacing a Ultrasonic range finder SRF10 through a custom USB board.
20  *
21  * In this class the "bind" is ignored since it is designed for USB
22  * connections only, thus it internally generate the required object for
23  * simplicity of use.
24  * The serial number of the USB device is used to open it on the first call
25  * to "doProcess", thus you must call "loadConfig" before this, or manually
26  * call "setDeviceSerialNumber". The default serial number is "SONAR001"
27  *
28  * Warning: Avoid defining an object of this class in a global scope if you
29  * want to catch all potential
30  * exceptions during the constructors (like USB interface DLL not found,
31  * etc...)
32  *
33  * \code
34  * PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS:
35  * -------------------------------------------------------
36  * [supplied_section_name]
37  * USB_serialNumber=SONAR001
38  * gain=6 ; Value between 0 and 16, for analog gains between 40
39  * and 700.
40  * maxRange=4.0 ; In meters, used for device internal timer.
41  * minTimeBetweenPings=0.3 ; In seconds
42  *
43  * ; The order in which sonars will be fired, indexed by their I2C addresses
44  * [0,15]
45  * ; Up to 16 devices, but you can put any number of devices (from 1 to 16).
46  * firingOrder=0 1 2 3
47  *
48  *
49  * \endcode
50  *
51  * \ingroup mrpt_hwdrivers_grp
52  */
54 {
56 
57  public:
58  /** Constructor
59  */
60  CBoardSonars();
61 
62  /** Destructor
63  */
64  ~CBoardSonars() override = default;
65  /** Query the firmware version on the device (can be used to test
66  * communications).
67  * \return true on success, false on communications errors or device not
68  * found.
69  */
70  bool queryFirmwareVersion(std::string& out_firmwareVersion);
71 
72  /** Request the latest range measurements.
73  * \return true on success, false on communications errors or device not
74  * found.
75  */
77 
78  /** Requests a command of "change address" for a given SRF10 device.
79  * currentAddress and newAddress are the I2C addresses in the range 0 to
80  * 15 (mapped to 0xE0 to 0xFE internally).
81  * \return true on success, false on communications errors or device not
82  * found.
83  */
84  bool programI2CAddress(uint8_t currentAddress, uint8_t newAddress);
85 
86  // See docs in parent class
87  void doProcess() override;
88 
89  protected:
90  /** A copy of the device serial number (to open the USB FTDI chip)
91  */
92  std::string m_usbSerialNumber;
93 
94  /** A value between 0 and 16, for gains between 40 and 700 (not linear).
95  */
96  uint8_t m_gain;
97 
98  /** The maximum range in meters, used for the internal device timer (value
99  * between 4cm and 11m).
100  */
101  float m_maxRange;
102 
103  /** The order in which sonars will be fired, indexed by their I2C addresses
104  * [0,15].
105  * Up to 16 devices, but you can put any number of devices (from 1 to 16).
106  */
107  std::vector<int32_t> m_firingOrder;
108 
109  /** The individual gains of the sonars, indexed by their I2C addresses
110  * [0,15].
111  * Up to 16 devices, but you can put any number of devices (from 1 to 16).
112  */
113  std::map<uint16_t, int32_t> m_sonarGains;
114 
115  /** The poses of the sonars: x[m] y[m] z[m] yaw[deg] pitch[deg] roll[deg]
116  * Up to 16 devices, but you can put any number of devices (from 1 to 16).
117  */
118  std::map<uint16_t, mrpt::math::TPose3D> m_sonarPoses;
119 
120  /** The minimum time between sonar pings (in seconds).
121  */
123 
124  /** Tries to connect to the USB device (if disconnected).
125  * \return True on connection OK, false on error.
126  */
128 
129  /** Sends the configuration (max range, gain,...) to the USB board. Used
130  * internally after a successfull connection.
131  * \return true on success, false on communications errors or device not
132  * found.
133  */
134  bool sendConfigCommands();
135 
136  /** Loads specific configuration for the device from a given source of
137  * configuration parameters, for example, an ".ini" file,
138  * loading from the section "[iniSection]" (see config::CConfigFileBase
139  * and
140  * derived classes)
141  * See hwdrivers::CBoardSonars for the possible parameters
142  */
144  const mrpt::config::CConfigFileBase& configSource,
145  const std::string& iniSection) override;
146 
147 }; // End of class
148 } // namespace mrpt::hwdrivers
A generic interface for a wide-variety of sensors designed to be used in the application RawLogGrabbe...
std::map< uint16_t, int32_t > m_sonarGains
The individual gains of the sonars, indexed by their I2C addresses [0,15].
Definition: CBoardSonars.h:113
void doProcess() override
This method will be invoked at a minimum rate of "process_rate" (Hz)
bool queryFirmwareVersion(std::string &out_firmwareVersion)
Query the firmware version on the device (can be used to test communications).
Declares a class derived from "CObservation" that encapsules a single range measurement, and associated parameters.
bool checkConnectionAndConnect()
Tries to connect to the USB device (if disconnected).
void loadConfig_sensorSpecific(const mrpt::config::CConfigFileBase &configSource, const std::string &iniSection) override
Loads specific configuration for the device from a given source of configuration parameters, for example, an ".ini" file, loading from the section "[iniSection]" (see config::CConfigFileBase and derived classes) See hwdrivers::CBoardSonars for the possible parameters.
std::string m_usbSerialNumber
A copy of the device serial number (to open the USB FTDI chip)
Definition: CBoardSonars.h:92
Contains classes for various device interfaces.
~CBoardSonars() override=default
Destructor.
std::vector< int32_t > m_firingOrder
The order in which sonars will be fired, indexed by their I2C addresses [0,15].
Definition: CBoardSonars.h:107
This class allows loading and storing values and vectors of different types from a configuration text...
float m_minTimeBetweenPings
The minimum time between sonar pings (in seconds).
Definition: CBoardSonars.h:122
This "software driver" implements the communication protocol for interfacing a Ultrasonic range finde...
Definition: CBoardSonars.h:53
uint8_t m_gain
A value between 0 and 16, for gains between 40 and 700 (not linear).
Definition: CBoardSonars.h:96
#define DEFINE_GENERIC_SENSOR(class_name)
This declaration must be inserted in all CGenericSensor classes definition, within the class declarat...
A definition of a CStream actually representing a USB connection to a FTDI chip.
bool sendConfigCommands()
Sends the configuration (max range, gain,...) to the USB board.
std::map< uint16_t, mrpt::math::TPose3D > m_sonarPoses
The poses of the sonars: x[m] y[m] z[m] yaw[deg] pitch[deg] roll[deg] Up to 16 devices, but you can put any number of devices (from 1 to 16).
Definition: CBoardSonars.h:118
bool programI2CAddress(uint8_t currentAddress, uint8_t newAddress)
Requests a command of "change address" for a given SRF10 device.
float m_maxRange
The maximum range in meters, used for the internal device timer (value between 4cm and 11m)...
Definition: CBoardSonars.h:101
bool getObservation(mrpt::obs::CObservationRange &obs)
Request the latest range measurements.



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