Main MRPT website > C++ reference
MRPT logo
CBoardSonars.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef CBoardSonars_H
29 #define CBoardSonars_H
30 
33 #include <mrpt/synch.h>
37 
38 namespace mrpt
39 {
40  namespace hwdrivers
41  {
42  /** This "software driver" implements the communication protocol for interfacing a Ultrasonic range finder SRF10 through a custom USB board.
43  *
44  * 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.
45  * 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
46  * call "setDeviceSerialNumber". The default serial number is "SONAR001"
47  *
48  * Warning: Avoid defining an object of this class in a global scope if you want to catch all potential
49  * exceptions during the constructors (like USB interface DLL not found, etc...)
50  *
51  * \code
52  * PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS:
53  * -------------------------------------------------------
54  * [supplied_section_name]
55  * USB_serialNumber=SONAR001
56  * gain=6 ; Value between 0 and 16, for analog gains between 40 and 700.
57  * maxRange=4.0 ; In meters, used for device internal timer.
58  * minTimeBetweenPings=0.3 ; In seconds
59  *
60  * ; The order in which sonars will be fired, indexed by their I2C addresses [0,15]
61  * ; Up to 16 devices, but you can put any number of devices (from 1 to 16).
62  * firingOrder=0 1 2 3
63  *
64  *
65  * \endcode
66  *
67  * \ingroup mrpt_hwdrivers_grp
68  */
70  {
72 
73  public:
74  /** Constructor
75  */
76  CBoardSonars();
77 
78  /** Destructor
79  */
80  virtual ~CBoardSonars(){}
81 
82  /** Query the firmware version on the device (can be used to test communications).
83  * \return true on success, false on communications errors or device not found.
84  */
85  bool queryFirmwareVersion( std::string &out_firmwareVersion );
86 
87  /** Request the latest range measurements.
88  * \return true on success, false on communications errors or device not found.
89  */
90  bool getObservation( mrpt::slam::CObservationRange &obs );
91 
92  /** Requests a command of "change address" for a given SRF10 device.
93  * currentAddress and newAddress are the I2C addresses in the range 0 to 15 (mapped to 0xE0 to 0xFE internally).
94  * \return true on success, false on communications errors or device not found.
95  */
96  bool programI2CAddress( uint8_t currentAddress, uint8_t newAddress );
97 
98  /** This method should be called periodically (at least at 1Hz to capture ALL the real-time data)
99  * It is thread safe, i.e. you can call this from one thread, then to other methods from other threads.rip
100  */
101  void doProcess();
102 
103  protected:
104  /** A copy of the device serial number (to open the USB FTDI chip)
105  */
106  std::string m_usbSerialNumber;
107 
108  /** A value between 0 and 16, for gains between 40 and 700 (not linear).
109  */
110  uint8_t m_gain;
111 
112  /** The maximum range in meters, used for the internal device timer (value between 4cm and 11m).
113  */
114  float m_maxRange;
115 
116  /** The order in which sonars will be fired, indexed by their I2C addresses [0,15].
117  * Up to 16 devices, but you can put any number of devices (from 1 to 16).
118  */
119  std::vector<int32_t> m_firingOrder;
120 
121  /** The individual gains of the sonars, indexed by their I2C addresses [0,15].
122  * Up to 16 devices, but you can put any number of devices (from 1 to 16).
123  */
124  std::map<uint16_t,int32_t> m_sonarGains;
125 
126  /** The poses of the sonars: x[m] y[m] z[m] yaw[deg] pitch[deg] roll[deg]
127  * Up to 16 devices, but you can put any number of devices (from 1 to 16).
128  */
129  std::map<uint16_t,mrpt::math::TPose3D> m_sonarPoses;
130 
131  /** The minimum time between sonar pings (in seconds).
132  */
134 
135  /** Tries to connect to the USB device (if disconnected).
136  * \return True on connection OK, false on error.
137  */
138  bool checkConnectionAndConnect();
139 
140  /** Sends the configuration (max range, gain,...) to the USB board. Used internally after a successfull connection.
141  * \return true on success, false on communications errors or device not found.
142  */
143  bool sendConfigCommands();
144 
145  /** Loads specific configuration for the device from a given source of configuration parameters, for example, an ".ini" file,
146  * loading from the section "[iniSection]" (see utils::CConfigFileBase and derived classes)
147  * See hwdrivers::CBoardSonars for the possible parameters
148  */
149  void loadConfig_sensorSpecific( const mrpt::utils::CConfigFileBase &configSource,
150  const std::string &iniSection );
151 
152 
153 
154  }; // End of class
155  } // End of namespace
156 } // End of namespace
157 
158 
159 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013