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



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011