latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 2004, 2005, 2006 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * This file is part of the LTI-Computer Vision Library (LTI-Lib) 00006 * 00007 * The LTI-Lib is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License (LGPL) 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * The LTI-Lib is distributed in the hope that it will be 00013 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00014 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with the LTI-Lib; see the file LICENSE. If 00019 * not, write to the Free Software Foundation, Inc., 59 Temple Place - 00020 * Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 00023 00024 /*-------------------------------------------------------------------- 00025 * project ....: LTI-Lib: Image Processing and Computer Vision Library 00026 * file .......: ltiDirectedPerceptionPTU.h 00027 * authors ....: Christian Hein, Florian Bley 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 17.12.2004 00030 * revisions ..: $Id: ltiDirectedPerceptionPTU.h,v 1.4 2006/02/08 12:03:16 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_DIRECTED_PERCEPTION_P_T_U_H_ 00034 #define _LTI_DIRECTED_PERCEPTION_P_T_U_H_ 00035 00036 00037 #include "ltiPanTiltUnit.h" 00038 #include "ltiSerial.h" 00039 00040 00041 00042 namespace lti { 00043 /** 00044 * This class performs handling of the pan-tilt unit PTU-D46-17 from the manufactor DirectedPerception.<br> 00045 * <TABLE> 00046 * <TR> 00047 * <TD COLSPAN="3">Base data (taken from the specifications)</TD> 00048 * </TR> 00049 * <TR> 00050 * <TD ALIGN="LEFT">Pan range</TD> <TD ALIGN="RIGHT">-159 degrees</TD> <TD>+159 degrees</TD> 00051 * </TR> 00052 * <TR> 00053 * <TD ALIGN="LEFT">Tilt Range</TR> <TD ALIGN="Right">-47 degrees</TD> <TD>+31 degrees</TD> 00054 * </TR> 00055 * <TR> 00056 * <TD ALIGN="LEFT">Max unloaded speed</TD> <TD COLSPAN="2" ALIGN="RIGHT">300 degrees/second</TD> 00057 * </TR> 00058 * <TR> 00059 * <TD ALIGN="LEFT">Resolution</TD> <TD COLSPAN="2" ALIGN="RIGHT">3.086' = 0.051428 degrees/position</TD> 00060 * </TR> 00061 * </TABLE> 00062 * <br> 00063 * <b>Initializing</b><br> 00064 * Before you start sending any commands, the pan-tilt unit (PTU) has to be initialized. This happens 00065 * by using directedPerceptionPTU::initialize(). If this method has not been successfully 00066 * executed, all methods working on the PTU will not do and return a false with 00067 * an adequate report in the status string. The routine tests the communication between the 00068 * serial port and the PTU, sets pan/tilt position to 0,0, acceleration and speed to default values. 00069 * They should deal with the most mounted loads.<br> 00070 * <br> 00071 * 00072 * <b>Execution modes</b><br> 00073 * As you can see from the corresponding methods, the pan-tilt unit provides two execution functions: 00074 * slaved and immidiate. The standard mode is immidiate. In immidiate mode, position commands are 00075 * excuted at once, when they have been sent to the unit. In slaved mode, position commands are 00076 * not executed before an await command was send. That means in fact not before 00077 * directedPerceptionPTU::awaitPosCommandCompletion() is applied. This realizes that pan and tilt 00078 * movement act more or less synchronously. An adequate example in angle format degrees might be: 00079 * <br> 00080 * \code 00081 * lti::directedPerceptionPTU ptu; 00082 * ptu.setExecMode(directedPerceptionPTU::parameters::slaved); 00083 * ptu.setPan(-90.f); 00084 * ptu.setTilt(30.f); 00085 * ptu.awaitPosCommandCompletion(); 00086 * \endcode 00087 * <br> 00088 * If you give more than one pan and tilt combination only the last one will be applied, because 00089 * the earlier ones are overwritten immediately.<br> 00090 * 00091 * <b>Speeds and Accelerations</b><br> 00092 * Note that minimum/maximum pan and tilt speeds/accelerations are more less experimental. So 00093 * some speed and acceleration combinations could not be legal. As in speed and acceleration setting 00094 * it is not checked, whether the pan-tilt unit took over the changes correctly, it could happen, 00095 * that a setting function returns true, although the PTU rejected the given values. If you have 00096 * the feeling that some settings were not applied, try values, which have a larger distance to 00097 * the max. or min. borders. In most cases this will not occur, since it is not necessary to set 00098 * extreme speed and acceleration values for common applications. Also the max/min speeds and 00099 * accelerations are already limited.<br> 00100 * If you like to experiment with the pan-tilt unit to test it, use a terminal programm (e.g. 00101 * minicom under linux) to set up communication between the pc and the device. Work with 9600 00102 * baud, 1 start bit, 8 data bits, 1 stop bit, no parity. The instructions can be taken from 00103 * the manual which you can find under <a href="http://www.directedperception.com">www.directedPerception.com</a> <br> 00104 * 00105 * <b>Relative positions</b><br> 00106 * As announced in some methods, relative positioning provides the danger of huge divergences 00107 * between the real and the internal positions. This can occur, if a big amount of relative 00108 * position commands are set after each other very fast, without a sufficent break between them. 00109 * Then the internal positions are faster updated, than the the pan-tilt could execute the commands. 00110 * What happens, is the following: E.g. the PTU gets the command to pan relatively with a few degrees. 00111 * Before that is finished, the next command arrives and tells to pan again relatively with some degrees. 00112 * Now the position of the new command does not calculate from where the first would end in a 00113 * few seconds, but from where it is currently located. Thus, errors accumulate over time. 00114 * That results in an decreasing driving interval . This could be avoided, if a long enoug sleep command is 00115 * applied between position setting or working with the await and isIdle methods as shown in the example. 00116 * If a not wanted difference has been recognized the internal values could be updated with the real ones by using 00117 * directedPerceptionPTU::updatePanTilt(). Be aware that the values can only be updated, if 00118 * directedPerceptionPTU::isPTUidle() returns true. Otherwise the positions can not be read from 00119 * the unit.<br> 00120 * 00121 * <b>Determining an idle pan-tilt unit</b><br> 00122 * The method directedPerceptionPTU::isPTUidle() provides to check the PTU working 00123 * condition. Each time, when a method is called, which directly sends commands to the pan-tilt 00124 * unit, an instruction counter is increased. For every command which is successfully applied the 00125 * unit sends an asterix '*' and for each failed command a '!'. The method reads out the serial buffer 00126 * and decreases the instruction counter with the number of '*' and '!' it has read. So, if all 00127 * commands have been worked out, the instruction counter is back to zero and the method returns 00128 * true. Otherwise, if the instruction counters value is greater than zero, it returns false.<br> 00129 * Note that in immidiate execution mode an asterix is already returned from the pan-tilt unit, 00130 * if the desired position can be driven, but has not started moving yet. That means, that 00131 * directedPerceptionPTU::isPTUidle() returns also true, if the last position command is still 00132 * being executed. You can avoid this by subsequently calling directedPerceptionPTU::awaitPosCommandCompletion(). 00133 * Then the idle method only returns true, when the pan-tilt unit has finished its move.<br> 00134 * 00135 * Here is a short example code for using the pan-tilt unit.<br> 00136 * \code 00137 * #include "ltiDirectedPerceptionPTU.h" 00138 * #include <iostream> 00139 * 00140 * int main(void) { 00141 * lti::directedPerceptionPTU ptu; 00142 * ptu.initialize(); // Test the connection and make first settings 00143 * ptu.setAngleFormat(lti::panTiltUnit::parameters::Degrees); // Set angle format to degrees 00144 * ptu.setPan(90.f); // Set Pan to 90 00145 * ptu.awaitPosCommandCompletion(); // Do not accept commands till ptu is in position 00146 * while ( !ptu.isPTuIdle() ) { // Wait until position is reached 00147 * // do nothing 00148 * } 00149 * cout << "Internal position: " << ptu.getPan() << endl; 00150 * cout << "Real position: " << ptu.getCurrentPan() << endl; 00151 * 00152 * // Now this will cause a huge difference between real and internal position 00153 * // Try to drive back to zero position in 5 degrees steps and relative positioning. 00154 * ptu.setPosMode(lti::directedPerceptionPTU::parameters::relative); 00155 * for ( int i=0; i<90; i=i+5 ) { 00156 * ptu.setPan(-i); 00157 * } 00158 * 00159 * ptu.awaitPosCommandCompletion(); // Do not accept commands till ptu is in position 00160 * while ( !ptu.isPTuIdle() ) { // Wait until position is reached 00161 * // do nothing 00162 * } 00163 * // Print positions 00164 * cout << "Internal position: " << ptu.getPan() << endl; 00165 * cout << "Real position: " << ptu.getCurrentPan() << endl; 00166 * cout << "Difference : " << ptu.getCurrentPan()-ptu.getPan() << " " << endl; 00167 * ptu.updatePanTilt(); // Update internal parameters 00168 * cout << "Updated parameters:" << endl; 00169 * cout << "Internal position: " << ptu.getPan() << endl; 00170 * cout << "Real position: " << ptu.getCurrentPan() << endl; 00171 * cout << "Difference : " << ptu.getCurrentPan()-ptu.getPan() << " " << endl; 00172 * // Drive to starting position 00173 * ptu.setPosMode(lti::directedPerceptionPTU::parameters::relative); 00174 * ptu.setPan(0.f); 00175 * return(0); 00176 * } 00177 * \endcode 00178 * <br> 00179 */ 00180 class directedPerceptionPTU : public panTiltUnit { 00181 public: 00182 /** 00183 * The parameters for the class DirectedPerceptionPTU 00184 */ 00185 class parameters : public panTiltUnit::parameters { 00186 public: 00187 /** 00188 * Default constructor 00189 */ 00190 parameters(); 00191 00192 /** 00193 * Copy constructor 00194 * @param other the parameters object to be copied 00195 */ 00196 parameters(const parameters& other); 00197 00198 /** 00199 * Destructor 00200 */ 00201 ~parameters(); 00202 00203 /** 00204 * Returns name of this type 00205 */ 00206 const char* getTypeName() const; 00207 00208 /** 00209 * Copy the contents of a parameters object 00210 * @param other the parameters object to be copied 00211 * @return a reference to this parameters object 00212 */ 00213 parameters& copy(const parameters& other); 00214 00215 /** 00216 * Copy the contents of a parameters object 00217 * @param other the parameters object to be copied 00218 * @return a reference to this parameters object 00219 */ 00220 parameters& operator=(const parameters& other); 00221 00222 00223 /** 00224 * Returns a pointer to a clone of the parameters 00225 */ 00226 virtual functor::parameters* clone() const; 00227 00228 /** 00229 * Write the parameters in the given ioHandler 00230 * @param handler the ioHandler to be used 00231 * @param complete if true (the default) the enclosing begin/end will 00232 * be also written, otherwise only the data block will be written. 00233 * @return true if write was successful 00234 */ 00235 virtual bool write(ioHandler& handler,const bool complete=true) const; 00236 00237 /** 00238 * Read the parameters from the given ioHandler 00239 * @param handler the ioHandler to be used 00240 * @param complete if true (the default) the enclosing begin/end will 00241 * be also written, otherwise only the data block will be written. 00242 * @return true if write was successful 00243 */ 00244 virtual bool read(ioHandler& handler,const bool complete=true); 00245 00246 # ifdef _LTI_MSC_6 00247 /** 00248 * This function is required by MSVC only, as a workaround for a 00249 * very awful bug, which exists since MSVC V.4.0, and still by 00250 * V.6.0 with all bugfixes (so called "service packs") remains 00251 * there... This method is also public due to another bug, so please 00252 * NEVER EVER call this method directly: use read() instead 00253 */ 00254 bool readMS(ioHandler& handler,const bool complete=true); 00255 00256 /** 00257 * This function is required by MSVC only, as a workaround for a 00258 * very awful bug, which exists since MSVC V.4.0, and still by 00259 * V.6.0 with all bugfixes (so called "service packs") remains 00260 * there... This method is also public due to another bug, so please 00261 * NEVER EVER call this method directly: use write() instead 00262 */ 00263 bool writeMS(ioHandler& handler,const bool complete=true) const; 00264 # endif 00265 00266 // ------------------------------------------------ 00267 // the parameters 00268 // ------------------------------------------------ 00269 public: 00270 // Serial-Object 00271 serial connectionToPTU; 00272 00273 // Response Time 00274 static const int ptuResponseTime; 00275 00276 // Position Modes 00277 enum ePosModes { absolute, relative }; 00278 ePosModes posMode; 00279 00280 // Execution Modes 00281 enum eExecModes { immidiate , slaved }; 00282 eExecModes execMode; 00283 00284 // Speeds 00285 static const float maxPanSpeed; 00286 static const float maxTiltSpeed; 00287 static const float minPanSpeed; 00288 static const float minTiltSpeed; 00289 float panSpeed; 00290 float tiltSpeed; 00291 00292 // Acceleration 00293 static const float maxPanAcceleration; 00294 static const float maxTiltAcceleration; 00295 static const float minPanAcceleration; 00296 static const float minTiltAcceleration; 00297 float panAcceleration; 00298 float tiltAcceleration; 00299 00300 // Booleans 00301 bool connectedToPTU; 00302 00303 // Resolution 00304 static const float resolutionPerPosition; 00305 00306 // Counters 00307 static int instructionCounter; 00308 00309 }; 00310 00311 /** 00312 * Default constructor 00313 */ 00314 directedPerceptionPTU(); 00315 00316 /** 00317 * Construct a functor using the given parameters 00318 */ 00319 directedPerceptionPTU(const parameters& par); 00320 00321 /** 00322 * Copy constructor 00323 * @param other the object to be copied 00324 */ 00325 directedPerceptionPTU(const directedPerceptionPTU& other); 00326 00327 /** 00328 * Destructor 00329 */ 00330 virtual ~directedPerceptionPTU(); 00331 00332 /** 00333 * Returns the name of this type ("DirectedPerceptionPTU") 00334 */ 00335 virtual const char* getTypeName() const; 00336 00337 /** 00338 * Copy data of "other" functor. 00339 * @param other the functor to be copied 00340 * @return a reference to this functor object 00341 */ 00342 directedPerceptionPTU& copy(const directedPerceptionPTU& other); 00343 00344 /** 00345 * Alias for copy member 00346 * @param other the functor to be copied 00347 * @return a reference to this functor object 00348 */ 00349 directedPerceptionPTU& operator=(const directedPerceptionPTU& other); 00350 00351 /** 00352 * Returns a pointer to a clone of this functor. 00353 */ 00354 virtual functor* clone() const; 00355 00356 /** 00357 * Returns used parameters 00358 */ 00359 const parameters& getParameters() const; 00360 00361 /** 00362 * Tests connection to pan-tilt unit and sets initial speeds, acceleration and position 00363 * @return true if a communication could be established. False, if serial port could not 00364 * be accessed or timeout occured. 00365 */ 00366 bool initialize(); 00367 00368 /** 00369 * Sets angle format to degrees or radiants. 00370 * @return false, if an error occured, otherwise true. 00371 * Standard angle format is in radiants. 00372 */ 00373 bool setAngleFormat(parameters::eAngleFormatType anAngleFormat); 00374 /** 00375 * Sets command execution mode to immidiate or slaved. 00376 * @return false, if an error occured, otherwise true. 00377 * In immidiate mode pan-tilt unit is instructed to execute 00378 * positional commands at once. In slaved mode position 00379 * commands are only executed, when method directedPerceptionPTU::awaitPosCommandCompletion() 00380 * is applied. 00381 * Standard format is immidiate 00382 */ 00383 bool setExecMode(parameters::eExecModes anExecMode); 00384 /** 00385 * Sets position mode to absolute or relative. 00386 * @return false, if an error occured, otherwise true. 00387 * In absolute mode the pan-tilt-unit drives directly to the 00388 * desired positions. In relative mode position commands are 00389 * executed concerning the actual axis position. The offset is 00390 * then an angle distance between current and desired position. 00391 * Standard position mode is absolute. 00392 */ 00393 bool setPosMode(parameters::ePosModes anPosMode); 00394 00395 /** 00396 * Reset the pan-tilt unit. 00397 * Forces the pan-tilt unit to drive through its pan and tilt axis to determine min/max positions. 00398 * After that pan-tilt position 0,0 is applied. 00399 * @return false if serial port could not be accessed, timeout occured or the pan-tilt unit was not 00400 * initialized properly. Otherwise true. 00401 */ 00402 bool reset(); 00403 00404 /** 00405 * Stop all movement of the pan-tilt unit. 00406 * The pan-tilt unit freezes at its current pan and tilt position. 00407 * @return false if serial port could not be accessed, timeout occured or the pan-tilt unit was not 00408 * initialized properly. Otherwise true. 00409 */ 00410 bool stopPanTilt(); 00411 00412 /** 00413 * Stop pan movement. 00414 * The pan-tilt unit freezes at its current pan position. 00415 * @return false if serial port could not be accessed, timeout occured or the pan-tilt unit was not 00416 * initialized properly. Otherwise true. 00417 */ 00418 bool stopPan(); 00419 00420 /* 00421 * Stop tilt movement. 00422 * The pan-tilt unit freezes at its current pan position. 00423 * @return false if serial port could not be accessed, timeout occured or the pan-tilt unit was not 00424 * initialized properly. Otherwise true. 00425 */ 00426 bool stopTilt(); 00427 00428 /** 00429 * Set desired pan-tilt position. 00430 * If the given pan and tilt positions, which could be set in radiants or degrees, are within 00431 * minimum/maximum range the pan-tilt unit will drive there. If the values are out of range, 00432 * max or min positions are applied. This will be commented in the status string. 00433 * Depending on posMode the position can be set in absolute or relative angle parameters. 00434 * Notise, that pan-tilt position commands in the slaved execution mode are only applied, when 00435 * the directedPerceptionPTU::awaitPosCommandCompletion() method is called after setting pan-tilt. If you give more than one 00436 * pan-tilt combination in slaved mode before calling await method, only the last will be executed. 00437 * @return false if serial port could not be accessed, timeout occured or the pan-tilt unit was not 00438 * initialized properly. Otherwise true. 00439 */ 00440 bool setPanTilt(float pan, float tilt); 00441 00442 /** 00443 * Set desired pan position. 00444 * If the given pan position, which could be set in radiants or degrees, is within 00445 * minimum/maximum range the pan-tilt unit will drive there. If the value is out of range, 00446 * max or min position is applied. This will be commented in the status string. 00447 * Depending on posMode the position can be set in absolute or relative angle parameters. 00448 * Notise, that pan-tilt position commands in the slaved execution mode are only applied, when 00449 * the directedPerceptionPTU::awaitPosCommandCompletion() method is called after setting pan-tilt. If you give more than one 00450 * pan-tilt combination in slaved mode before calling await method, only the last will be executed. 00451 * @return false if serial port could not be accessed, timeout occured or the pan-tilt unit was not 00452 * initialized properly. Otherwise true. 00453 */ 00454 bool setPan(float pan); 00455 00456 /** 00457 * Set desired tilt position 00458 * If the given tilt position, which could be set in radiants or degrees, is within 00459 * minimum/maximum range the pan-tilt unit will drive there. If the value is out of range, 00460 * max or min position is applied. This will be commented in the status string. 00461 * Depending on posMode the position can be set in absolute or relative angle parameters. 00462 * Notise, that pan-tilt position commands in the slaved execution mode are only applied, when 00463 * the directedPerceptionPTU::awaitPosCommandCompletion() method is called after setting pan-tilt. If you give more than one 00464 * pan-tilt combination in slaved mode before calling await method, only the last will be executed. 00465 * @return false if serial port could not be accessed, timeout occured or the pan-tilt unit was not 00466 * initialized properly. Otherwise true. 00467 */ 00468 bool setTilt(float tilt); 00469 00470 /** 00471 * Get internal pan and tilt positions. 00472 * Depending on the current angle format the values are stored in the given 00473 * reference parameters in radiants or degrees. 00474 * Note that the internal pan and tilt positions could differ very much from the physical 00475 * ones, if you apply a large amount of relative position commands shortly after each other. 00476 * You can update the internal values by using directedPerceptionPTU::updatePanTilt(). 00477 * @return true in every case 00478 */ 00479 bool getPanTilt(float& pan, float& tilt) const; 00480 00481 /** 00482 * Get internal pan position. 00483 * Depending on the current angle format the value is returned in radiants or degrees. They 00484 * are always in absolute positions, independent from position mode. 00485 * Note that the internal pan and tilt positions could differ very much from the physical 00486 * ones, if you apply a large amount of relative position commands shortly after each other. 00487 * You can update the internal values by using directedPerceptionPTU::updatePanTilt(). 00488 * @return true in every case 00489 */ 00490 float getPan() const; 00491 00492 /** 00493 * Get internal tilt position. 00494 * Depending on the current angle format the value is returned in radiants or degrees. 00495 * It is always in absolute position, independent from position mode. 00496 * Note that the internal pan and tilt positions could differ very much from the physical 00497 * ones, if you apply a large amount of relative position commands shortly after each other. 00498 * You can update the internal values by using directedPerceptionPTU::updatePanTilt(). 00499 * @return true in every case 00500 */ 00501 float getTilt() const; 00502 00503 /** 00504 * Reads out physically occuring pan and tilt axis positions from the pan-tilt unit and 00505 * stores them in the given reference parameters. Depending on the current angle format 00506 * the values contain the absolute positions in degrees or radiants. They are always in 00507 * absolute positions, independent from position mode. 00508 * Note that the internal pan and tilt positions could differ very much from the physical 00509 * ones, if you apply a large amount of relative position commands shortly after each other. 00510 * You can update the internal values by using directedPerceptionPTU::updatePanTilt(). 00511 * This method uses the directedPerceptionPTU::isIdlePTU() to determine, if the unit is 00512 * still performing commands. If so, the positions can not be read out. 00513 * @return true if positions could be read correctly from the pan-tilt unit. False, if 00514 * read command could not be send, timeout occured, unproper initialization of the PTU or 00515 * if the pan-tilt unit is not idle cause it's still peforming more than one position 00516 * command. 00517 */ 00518 bool getCurrentPanTilt(float& pan, float& tilt); 00519 00520 /** 00521 * Reads out physically occuring pan axis position from the pan-tilt unit and 00522 * store it in the given reference parameter. Depending on the current angle format 00523 * the value contains the absolute position in degrees or radiants. It is always in absolute 00524 * position, independent from position mode. 00525 * Note that the internal pan and tilt positions could differ very much from the physical 00526 * ones, if you apply a large amount of relative position commands shortly after each other. 00527 * You can update the internal values by using directedPerceptionPTU::updatePanTilt(). 00528 * This method uses the directedPerceptionPTU::isIdlePTU() to determine, if the unit is 00529 * still performig commands. If so, the positions can not be read out. 00530 * @return true if the position could be read correctly from the pan-tilt unit. False, if 00531 * read command could not be send, timeout occured, unproper initialization of the PTU or 00532 * if the pan-tilt unit is not idle cause it's still peforming more than one position 00533 * command. This is reported inthe statusString. 00534 */ 00535 float getCurrentPan(); 00536 00537 /** 00538 * Reads out physically occuring tilt axis position from the pan-tilt unit and 00539 * store it in the given reference parameter. Depending on the current angle format 00540 * the value contains the absolute position in degrees or radiants. It is always in absolute 00541 * position, independent from position mode. 00542 * Note that the internal pan and tilt positions could differ very much from the physical 00543 * ones, if you apply a large amount of relative position commands shortly after each other. 00544 * You can update the internal values by using directedPerceptionPTU::updatePanTilt(). 00545 * This method uses the directedPerceptionPTU::isIdlePTU() to determine, if the unit is 00546 * still performig commands. If so, the positions can not be read out. 00547 * @return true if the position could be read correctly from the pan-tilt unit. False, if 00548 * read command could not be send, timeout occured, unproper initialization of the PTU or 00549 * if the pan-tilt unit is not idle cause it's still peforming more than one position 00550 * command. This is reported in the status string. 00551 */ 00552 float getCurrentTilt(); 00553 00554 /** 00555 * Enables autoscan in pan direction. 00556 * In autoscan or monitor mode the pan-tilt unit keeps moving between the given 00557 * pan and/or tilt positions until another position command or 00558 * directedPerceptionPTU::stopAutoscan() is applied. Through this method the unit 00559 * is instructed to move between panPos1 and panPos2 with the current pan speed and 00560 * pan acceleration. Autoscan is only available in absolute positions. Please, make sure 00561 * you stop autoscan with directedPerceptionPTU::stopAutoscan(). This is saver than by applying 00562 * further position commands. If the given values are not within maximum and minimum pan range, 00563 * max/min positions are applied. 00564 * @return false, if serial port could not be accessed, timeout occured, unproper initialization 00565 * of the PTU or the pan positions were given in relative values. This is reported in status 00566 * string. Otherwise the method returns true. 00567 */ 00568 bool setAutoscan( float panPos1, float panPos2 ); 00569 00570 /** 00571 * Enables autoscan in pan and tilt direction. 00572 * In autoscan or monitor mode the pan-tilt unit keeps moving between the given 00573 * pan and/or tilt positions until another position command or 00574 * directedPerceptionPTU::stopAutoscan() is applied. Through this method the unit 00575 * is instructed to move between panPos1 and panPos2 and between tiltPos1 and tilt Pos2 with 00576 * current pan/tilt speeds/accelerations. Autoscan is only available in absolute positions. 00577 * Please, make sure you stop autoscan with directedPerceptionPTU::stopAutoscan(). This is 00578 * saver than by applying further position commands. If the given values are not within 00579 * maximum and minimum pan/tilt range, max/min positions are applied. 00580 * @return false, if serial port could not be accessed, timeout occured, unproper initialization 00581 * of the PTU or the pan/tilt positions were given in relative values. This is reported in 00582 * status string. Otherwise the method returns true. 00583 */ 00584 bool setAutoscan( float panPos1, float panPos2, float tiltPos1, float tiltPos2 ); 00585 00586 /** 00587 * Enables autoscan with the last applied autoscan parameters . 00588 * In autoscan or monitor mode the pan-tilt unit keeps moving between the given 00589 * pan and/or tilt positions until another position command or 00590 * directedPerceptionPTU::stopAutoscan() is applied. Through this method the unit 00591 * is instructed to move between pan and tilt positions given, when executing autoscan 00592 * the last time. If it was not enabled before the pan-tilt unit starts moving between max 00593 * and min pan positions in current pan speed and acceleration. Autoscan is only available 00594 * in absolute positions. Please, make sure you stop autoscan with directedPerceptionPTU::stopAutoscan(). 00595 * This is saver than by applying further position commands. If the given values are not within 00596 * maximum and minimum pan/tilt range, max/min positions are applied. 00597 * @return false, if serial port could not be accessed, timeout occured, unproper initialization 00598 * of the PTU or the pan/tilt positions were given in relative values. This is reported in 00599 * status string. Otherwise the method returns true. 00600 */ 00601 bool setAutoscan(); 00602 00603 /** 00604 * Stops autoscan and forces the pan-tilt unit to drive to starting position ( Pan, Tilt ) 00605 * = ( 0, 0 ). 00606 * @return false, if serial port could not be accessed, timeout occured or the PTU was unproperly 00607 * initialized. This is reported in status string. Otherwise the method returns true. 00608 */ 00609 bool stopAutoscan(); 00610 00611 /** 00612 * Sets the pan speed to the desired value panSpeed, which can be given in radiants or degrees. 00613 * It is always interpreted as absolute setting, independent from position mode. 00614 * If it is between allowed minimum and maximum speed, the change is dircetly taken over. 00615 * If the value is out of range max respectively min speed is applied. This case is indicated 00616 * by setting the status string. 00617 * @return false , if serial port could not be accessed, timeout occured or the PTU was unproperly 00618 * initialized. This is reported in status string. Otherwise the method returns true. 00619 */ 00620 bool setPanSpeed ( float panSpeed ); 00621 00622 /** 00623 * Sets the tilt speed to the desired value panSpeed, which can be given in radiants or degrees. 00624 * It is always interpreted as absolute setting, independent from position mode. 00625 * If it is between allowed minimum and maximum speed, the change is dircetly taken over. 00626 * If the value is out of range max respectively min tilt speed is applied. This case is indicated 00627 * by setting the status string. 00628 * @return false , if serial port could not be accessed, timeout occured or the PTU was unproperly 00629 * initialized. This is reported in status string. Otherwise the method returns true. 00630 */ 00631 bool setTiltSpeed( float tiltSpeed ); 00632 00633 /** 00634 * Gets maximum pan speed in the desired angle format. 00635 * @return the maximum pan speed in radiants or degrees per second 00636 */ 00637 float getMaxPanSpeed(); 00638 00639 /** 00640 * Gets minimum pan speed in the desired angle format. 00641 * @return the minimum pan speed in radiants or degrees per second 00642 */ 00643 float getMinPanSpeed(); 00644 00645 /** 00646 * Gets maximum tilt speed in the desired angle format. 00647 * @return the maximum tilt speed in radiants or degrees per second 00648 */ 00649 float getMaxTiltSpeed(); 00650 00651 /** 00652 * Gets minimum tilt speed in the desired angle format. 00653 * @return the minimum tilt speed in radiants or degrees per second 00654 */ 00655 float getMinTiltSpeed(); 00656 00657 /** 00658 * Sets the pan acceleration to the desired value panAcc, which can be given in radiants or degrees. 00659 * It is always interpreted as absolute setting, independent from position mode. 00660 * If it is between allowed minimum and maximum pan acceleration, the change is dircetly taken over. 00661 * If the value is out of range max respectively min pan acceleration is applied. This case is indicated 00662 * by setting the status string. 00663 * @return false , if serial port could not be accessed, timeout occured or the PTU was unproperly 00664 * initialized. This is reported in status string. Otherwise the method returns true. 00665 */ 00666 bool setPanAcceleration ( float panAcc ); 00667 00668 /** 00669 * Sets the tilt acceleration to the desired value panAcc, which can be given in radiants or degrees. 00670 * It is always interpreted as absolute setting, independent from position mode. 00671 * If it is between allowed minimum and maximum acceleration, the change is dircetly taken over. 00672 * If the value is out of range max respectively min tilt acceleration is applied. This case is indicated 00673 * by setting the status string. 00674 * @return false , if serial port could not be accessed, timeout occured or the PTU was unproperly 00675 * initialized. This is reported in status string. Otherwise the method returns true. 00676 */ 00677 bool setTiltAcceleration( float tiltAcc ); 00678 00679 /** 00680 * Gets maximum pan acceleration in the desired angle format. 00681 * @return the maximum pan speed in radiants or degrees per second^2 00682 */ 00683 float getMaxPanAcceleration(); 00684 00685 /** 00686 * Gets minimum pan acceleration in the desired angle format. 00687 * @return the minimum pan acceleration speed in radiants or degrees per second^2 00688 */ 00689 float getMinPanAcceleration(); 00690 00691 /** 00692 * Gets maximum tilt acceleration in the desired angle format. 00693 * @return the maximum tilt acceleration speed in radiants or degrees per second^2 00694 */ 00695 float getMaxTiltAcceleration(); 00696 00697 /** 00698 * Gets minimum tilt acceleration in the desired angle format. 00699 * @return the minimum tilt acceleration speed in radiants or degrees per second^2 00700 */ 00701 float getMinTiltAcceleration(); 00702 00703 /** 00704 * Determine whether the pan-tilt unit is still performing commands. 00705 * That means, that at the moment at maximum one command is executed, which is not 00706 * a position command followed by an await instruction.<br> 00707 * @return false, if serial port could not be accessed, timeout occured, the PTU was unproperly 00708 * initialized, or the unit is not idle. This is reported in status string. Otherwise the method 00709 * returns true. 00710 */ 00711 bool isPTUidle(); 00712 00713 /** 00714 * Await the last position command to be completed. 00715 * The pan-tilt unit is instructed to wait executing further commands until the last 00716 * position command is completed. This means till the given pan and tilt positions are 00717 * physically reached. 00718 * @return false, if serial port could not be accessed, timeout occured or the PTU was unproperly 00719 * initialized. This is reported in status string. Otherwise the method returns true. 00720 */ 00721 bool awaitPosCommandCompletion(); 00722 00723 /** 00724 * Reads out the current pan and tilt positions from the PTU and overrides the internal values. 00725 * The method uses directedPTU::getCurrentPanTilt() to get the physically positions. <br> 00726 * Note that the update can only be performed, if the pan-tilt unit is idle. That means, that 00727 * at the moment at maximum one command is executed, which is not a position command followed 00728 * by an await instruction.<br> 00729 * @return false, if serial port could not be accessed, timeout occured, the PTU was unproperly 00730 * initialized, or the unit is not idle. This is reported in status string. Otherwise the method 00731 * returns true. 00732 */ 00733 bool updatePanTilt(); 00734 00735 protected: 00736 /** 00737 * @return a not-constant reference on a parameter object, which can be used to manipulate 00738 * the parameter variable. This is necessary as the functor concept can not be strictly 00739 * kept in. Cause this would restrict the functionality of the class very much. 00740 */ 00741 parameters& getWritableParameters(); 00742 00743 /** 00744 * Converts a given pan or tilt position into the internal PTU-format depending on the 00745 * position mode. 00746 * @return the given position in the internal format as integer. 00747 */ 00748 int convertValueToPTUnits(float position); 00749 00750 /** 00751 * Useful method, which simply reads out the serial buffer until it is empty to ensure, 00752 * that nothing is in it before starting work on the buffer. 00753 * @return nothing 00754 */ 00755 void emptySerialBuffer(); 00756 00757 }; 00758 } 00759 00760 #endif