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



Page generated by Doxygen 1.8.16 for MRPT 1.4.0 SVN: at Mon Oct 14 23:11:08 UTC 2019