Main MRPT website > C++ reference
MRPT logo

CPtuDPerception.h

Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                   http://mrpt.sourceforge.net/                            |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 
00029 #ifndef CPtuDPerception_H
00030 #define CPtuDPerception_H
00031 
00032 #include <mrpt/hwdrivers/CSerialPort.h>
00033 #include <mrpt/hwdrivers/CPtuBase.h>
00034 
00035 namespace mrpt
00036 {
00037         namespace hwdrivers
00038         {
00039                 /** This class implements initialization and comunication methods to
00040                   * control a Pan and Tilt Unit model PTU-46-17.5, working in radians .
00041                   */
00042                 class HWDRIVERS_IMPEXP CPtuDPerception : public CPtuBase
00043                 {
00044 
00045                 public:
00046 
00047                         /** Default constructor */
00048 
00049                         CPtuDPerception() {};
00050 
00051                         /** Destructor */
00052 
00053                         virtual ~CPtuDPerception(){ close(); }
00054 
00055                 /*************************** Commands ***************************/
00056 
00057                 public:
00058 
00059                         /** Search limit forward */
00060 
00061                         virtual bool rangeMeasure();
00062 
00063                         /** Specification of positions in absolute terms */
00064 
00065                         virtual bool moveToAbsPos(char axis,double nRad);
00066 
00067                         /** Query position in absolute terms */
00068 
00069                         virtual bool absPosQ(char axis,double &nRad);
00070 
00071                         /** Specify desired axis position as an offset from the current position. \n
00072                         *       This method recives the number of radians to move.
00073                         *       \code
00074                         *       Example of use:
00075                         *               TT-500 *
00076                         *               A *
00077                         *               TO * Current Tilt position is -500
00078                         *               TO500 *
00079                         *               A *
00080                         *               TT * Current Pan position is 1000 
00081                         *       \endcode
00082                         */
00083 
00084                         virtual bool moveToOffPos(char axis,double nRad);
00085 
00086                         /** Query position in relative terms */
00087 
00088                         virtual bool offPosQ(char axis,double &nRad);
00089 
00090                         /** Query max movement limit of a axis in absolute terms */
00091 
00092                         virtual bool maxPosQ(char axis,double &nRad);
00093 
00094                         /** Query min movement limit of a axis in absolute terms */
00095 
00096                         virtual bool minPosQ(char axis,double &nRad);
00097 
00098                         /** Query if exist movement limits */
00099 
00100                         virtual bool enableLimitsQ(bool &enable); // Query if exist some limit
00101 
00102                         /** Enable/Disable movement limits */
00103 
00104                         virtual bool enableLimits(bool set);
00105 
00106                         /** With I mode (default) instructs pan-tilt unit to immediately
00107                         *       execute positional commands. \n
00108                         *       In S mode instructs pan-tilt unit to execute positional commands
00109                         *       only when an Await Position Command Completion command is executed
00110                         *       or when put into Immediate Execution Mode. \n
00111                         *       \code
00112                         *       Example of use of S mode:
00113                         *               DR *
00114                         *               S *
00115                         *               PP1500 *
00116                         *               TP-900 *
00117                         *               PP * Current Pan position is 0
00118                         *               TP * Current Tilt position is 0
00119                         *               A *
00120                         *               PP * Current Pan position is 1500
00121                         *               TP * Current Tilt position is -900
00122                         *       \endcode
00123                         */
00124 
00125                         virtual bool inmediateExecution(bool set);
00126 
00127                         /** Wait the finish of the last position command to
00128                         *       continue accept commands
00129                         */
00130 
00131                         virtual bool aWait(void);
00132 
00133                         /** Inmediately stop all */
00134 
00135                         virtual bool haltAll();
00136 
00137                         /** Inmediately stop */
00138 
00139                         virtual bool halt(char axis);
00140 
00141                         /** Specification of turn speed */
00142 
00143                         virtual bool  speed(char axis,double radSec);
00144 
00145                         /** Query turn speed */
00146 
00147                         virtual bool  speedQ(char axis,double &radSec);
00148 
00149                         /** Specification (de/a)celeration in turn */
00150 
00151                         virtual bool  aceleration(char axis,double radSec2);
00152 
00153                         /** Query (de/a)celeration in turn */
00154 
00155                         virtual bool  acelerationQ(char axis,double &radSec2);
00156 
00157                         /** Specification of velocity to which start and finish
00158                         *       the (de/a)celeration
00159                         */
00160 
00161                         virtual bool  baseSpeed(char axis,double radSec);
00162 
00163                         /** Query velocity to which start and finish
00164                         *       the (de/a)celeration
00165                         */
00166 
00167                         virtual bool  baseSpeedQ(char axis,double &radSec);
00168 
00169                         /** Specification of velocity upper limit */
00170 
00171                         virtual bool upperSpeed(char axis,double radSec);
00172 
00173                         /** Query velocity upper limit */
00174 
00175                         virtual bool upperSpeedQ(char axis,double &radSec);
00176 
00177                         /** Specification of velocity lower limit */
00178 
00179                         virtual bool lowerSpeed(char axis,double radSec);
00180 
00181                         /** Query velocity lower limit */
00182 
00183                         virtual bool lowerSpeedQ(char axis,double &radSec);
00184 
00185                         /** Reset PTU to initial state */
00186 
00187                         virtual bool reset(void);
00188 
00189                         /** Save or restart default values */
00190 
00191                         virtual bool save(void);
00192 
00193                         /** Restore default values */
00194 
00195                         virtual bool restoreDefaults(void);
00196 
00197                         /** Restore factory default values */
00198 
00199                         virtual bool restoreFactoryDefaults(void);
00200 
00201                         /** Version and CopyRights */
00202 
00203                         virtual bool version(char * nVersion);
00204 
00205                         /** Number of version */
00206 
00207                         virtual void nversion(double &nVersion);
00208 
00209                         /** Query power mode */
00210 
00211                         virtual bool powerModeQ(bool transit,char &mode);
00212 
00213                         /** Specification of power mode */
00214 
00215                         virtual bool powerMode(bool transit,char mode);
00216 
00217                         /** Check if ptu is moving */
00218 
00219                         virtual double status(double &rad){ return 1; }
00220 
00221                         /** Set limits of movement */
00222 
00223                         virtual bool setLimits(char axis, double &l, double &u);
00224 
00225                         /* Change motion direction */
00226 
00227                         virtual bool changeMotionDir();
00228 
00229 
00230                 /**************************** State Queries ********************/
00231                         
00232                         /** Check errors, returns 0 if there are not errors or error code in otherwise
00233                         *       Error codes:
00234                         *       \code
00235                         *       1: Com error
00236                         *       2: Time out error
00237                         *       3: Init error
00238                         *       4: Pan tilt hit error
00239                         *       5: Pan hit error
00240                         *       6: Tilt hit error
00241                         *       7: Max limit error
00242                         *       8: Min limit error
00243                         *       9: Out of range
00244                         *       10: Illegal command error
00245                         *       11: Unexpected error
00246                         *   \endcode
00247                         **/
00248 
00249                         virtual int checkErrors();
00250 
00251                         inline bool noError() { return nError==1; }
00252                         inline bool comError() { return (nError % CPtuDPerception::ComError)==0; }
00253                         inline bool timeoutError() { return (nError % CPtuDPerception::TimeoutError)==0; }
00254                         inline bool initError() { return (nError % CPtuDPerception::InitError)==0; }
00255                         inline bool panTiltHitError() { return (nError % CPtuDPerception::PanTiltHitError)==0; }
00256                         inline bool panHitError() { return (nError % CPtuDPerception::PanHitError)==0; }
00257                         inline bool tiltHitError() { return (nError % CPtuDPerception::TiltHitError)==0; }
00258                         inline bool maxLimitError() { return (nError % CPtuDPerception::MaxLimitError)==0; }
00259                         inline bool minLimitError () { return (nError % CPtuDPerception::MinLimitError)==0; }
00260                         inline bool outOfRange() { return (nError % CPtuDPerception::OutOfRange)==0; }
00261                         inline bool illegalCommandError() { return (nError % CPtuDPerception::IllegalCommandError)==0; }
00262                         inline bool unExpectedError() { return (nError % CPtuDPerception::UnExpectedError)==0; }
00263                         
00264                         /** Clear errors **/
00265 
00266                         virtual void clearErrors() { nError=NoError; }
00267 
00268 
00269                 /*************************** Other member methods *****************/
00270 
00271                 public:
00272 
00273                         /** PTU and serial port initialization */
00274 
00275                         virtual bool init(const std::string port);
00276 
00277                         /** Close conection with serial port */
00278 
00279                         virtual void close();
00280 
00281                         /** To obtains the mistake for use discrete values when the movement
00282                         *       is expressed in radians. Parameters are the absolute position in
00283                         *       radians and the axis desired
00284                         */
00285 
00286                         virtual double radError(char axis,double nRadMoved);
00287 
00288                         /**  To obtain the discrete value for a number of radians */
00289 
00290                         virtual long radToPos(char axis,double nRad);
00291 
00292                         /** To obtain the number of radians for a discrete value */
00293 
00294                         virtual double posToRad(char axis,long nPos);
00295 
00296                         /** Performs a scan in the axis indicated and whit the precision desired. \n
00297                         *               \param <axis> {Pan or Till} \n
00298                         *               \param <tWait> {Wait time betwen commands} \n
00299                         *               \param <initial> {initial position}
00300                         *               \param <final> {final position}
00301                         *               \param <radPre> {radians precision for the scan}
00302                         */
00303 
00304                         virtual bool scan(char axis, int wait, float initial, float final, double radPre);
00305                                                 
00306                         /** Query verbose mode */
00307 
00308                         virtual bool verboseQ(bool &modo);
00309 
00310                         /** Set verbose. \n
00311                         *       \conde
00312                         *       Example of response with FV (verbose) active:
00313                         *               FV *
00314                         *               PP * Current pan position is 0
00315                         *               Example of response with FT (terse) active:
00316                         *               FT *
00317                         *               PP * 0
00318                         *       \endcode
00319                         */
00320 
00321                         virtual bool verbose(bool set);
00322 
00323                         /** Query echo mode */
00324 
00325                         virtual bool echoModeQ(bool &mode);
00326 
00327                         /** Enable/Disable echo response with command. \n
00328                         *       \code
00329                         *       Example of use (EE supposed):
00330                         *               PP * 22
00331                         *               ED *
00332                         *               <pp entered again, but not echoed>* 22
00333                         *       \endcode
00334                         */
00335 
00336                         virtual bool echoMode(bool mode);
00337 
00338                         /** Query the pan and tilt resolution per position moved
00339                         *       and initialize local atributes
00340                         */
00341 
00342                         virtual bool resolution(void);
00343 
00344 
00345                 /*************************** Methods for internal use ****************/
00346 
00347                 private:
00348 
00349                         /** To transmition commands to the PTU */
00350 
00351                         virtual bool transmit(const char * command);
00352 
00353                         /** To receive the responseof the PTU */
00354 
00355                         virtual bool receive(const char * command,char * response);
00356 
00357                         /** Used to obtains a number of radians */
00358 
00359                         virtual bool radQuerry(char axis,char command,double &nRad);
00360 
00361                         /** Method used for asign a number of radians with a command */
00362 
00363                         virtual bool radAsign(char axis,char command,double nRad);
00364 
00365                         /** Convert string to double */
00366 
00367                         virtual double convertToDouble(char *sDouble);
00368 
00369                         /** Convert string to long */
00370 
00371                         virtual long convertToLong(char *sLong);
00372 
00373                 /**************************** Atributes ********************/
00374 
00375                 public:
00376 
00377                         enum { NoError = 1, ComError = 2, TimeoutError = 3,
00378                                                 InitError = 5,PanHitError = 7, TiltHitError = 11, PanTiltHitError=13,
00379                                                 MaxLimitError = 17, MinLimitError = 19, OutOfRange = 23,
00380                                                 IllegalCommandError = 29, UnExpectedError =31 };
00381 
00382                         /** TimeoutError: Only occurs if the communication is cut with PTU
00383                         *               so it is advisable to check the connection and initialize
00384                         *               again the comunication.
00385                         */
00386 
00387                         int nError;
00388 
00389                         enum { Pan = 'P', Tilt = 'T' };
00390                         enum { Regular = 'R', High = 'H', Low = 'L', Off = 'O' };
00391                         enum { Com1 = 1, Com2 = 2, Com3 = 3, Com4 = 4 };
00392 
00393 
00394                 };      // End of class
00395 
00396         } // End of namespace
00397 
00398 } // End of namespace
00399 
00400 #endif



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN:exported at Tue Jan 25 21:56:31 UTC 2011