Main MRPT website > C++ reference
MRPT logo
CPtuDPerception.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 
29 #ifndef CPtuDPerception_H
30 #define CPtuDPerception_H
31 
34 
35 namespace mrpt
36 {
37  namespace hwdrivers
38  {
39  /** This class implements initialization and comunication methods to
40  * control a Pan and Tilt Unit model PTU-46-17.5, working in radians .
41  * \ingroup mrpt_hwdrivers_grp
42  */
44  {
45 
46  public:
47 
48  /** Default constructor */
49 
51 
52  /** Destructor */
53 
54  virtual ~CPtuDPerception(){ close(); }
55 
56  /*************************** Commands ***************************/
57 
58  public:
59 
60  /** Search limit forward */
61 
62  virtual bool rangeMeasure();
63 
64  /** Specification of positions in absolute terms */
65 
66  virtual bool moveToAbsPos(char axis,double nRad);
67 
68  /** Query position in absolute terms */
69 
70  virtual bool absPosQ(char axis,double &nRad);
71 
72  /** Specify desired axis position as an offset from the current position. \n
73  * This method recives the number of radians to move.
74  * \code
75  * Example of use:
76  * TT-500 *
77  * A *
78  * TO * Current Tilt position is -500
79  * TO500 *
80  * A *
81  * TT * Current Pan position is 1000
82  * \endcode
83  */
84 
85  virtual bool moveToOffPos(char axis,double nRad);
86 
87  /** Query position in relative terms */
88 
89  virtual bool offPosQ(char axis,double &nRad);
90 
91  /** Query max movement limit of a axis in absolute terms */
92 
93  virtual bool maxPosQ(char axis,double &nRad);
94 
95  /** Query min movement limit of a axis in absolute terms */
96 
97  virtual bool minPosQ(char axis,double &nRad);
98 
99  /** Query if exist movement limits */
100 
101  virtual bool enableLimitsQ(bool &enable); // Query if exist some limit
102 
103  /** Enable/Disable movement limits */
104 
105  virtual bool enableLimits(bool set);
106 
107  /** With I mode (default) instructs pan-tilt unit to immediately
108  * execute positional commands. \n
109  * In S mode instructs pan-tilt unit to execute positional commands
110  * only when an Await Position Command Completion command is executed
111  * or when put into Immediate Execution Mode. \n
112  * \code
113  * Example of use of S mode:
114  * DR *
115  * S *
116  * PP1500 *
117  * TP-900 *
118  * PP * Current Pan position is 0
119  * TP * Current Tilt position is 0
120  * A *
121  * PP * Current Pan position is 1500
122  * TP * Current Tilt position is -900
123  * \endcode
124  */
125 
126  virtual bool inmediateExecution(bool set);
127 
128  /** Wait the finish of the last position command to
129  * continue accept commands
130  */
131 
132  virtual bool aWait(void);
133 
134  /** Inmediately stop all */
135 
136  virtual bool haltAll();
137 
138  /** Inmediately stop */
139 
140  virtual bool halt(char axis);
141 
142  /** Specification of turn speed */
143 
144  virtual bool speed(char axis,double radSec);
145 
146  /** Query turn speed */
147 
148  virtual bool speedQ(char axis,double &radSec);
149 
150  /** Specification (de/a)celeration in turn */
151 
152  virtual bool aceleration(char axis,double radSec2);
153 
154  /** Query (de/a)celeration in turn */
155 
156  virtual bool acelerationQ(char axis,double &radSec2);
157 
158  /** Specification of velocity to which start and finish
159  * the (de/a)celeration
160  */
161 
162  virtual bool baseSpeed(char axis,double radSec);
163 
164  /** Query velocity to which start and finish
165  * the (de/a)celeration
166  */
167 
168  virtual bool baseSpeedQ(char axis,double &radSec);
169 
170  /** Specification of velocity upper limit */
171 
172  virtual bool upperSpeed(char axis,double radSec);
173 
174  /** Query velocity upper limit */
175 
176  virtual bool upperSpeedQ(char axis,double &radSec);
177 
178  /** Specification of velocity lower limit */
179 
180  virtual bool lowerSpeed(char axis,double radSec);
181 
182  /** Query velocity lower limit */
183 
184  virtual bool lowerSpeedQ(char axis,double &radSec);
185 
186  /** Reset PTU to initial state */
187 
188  virtual bool reset(void);
189 
190  /** Save or restart default values */
191 
192  virtual bool save(void);
193 
194  /** Restore default values */
195 
196  virtual bool restoreDefaults(void);
197 
198  /** Restore factory default values */
199 
200  virtual bool restoreFactoryDefaults(void);
201 
202  /** Version and CopyRights */
203 
204  virtual bool version(char * nVersion);
205 
206  /** Number of version */
207 
208  virtual void nversion(double &nVersion);
209 
210  /** Query power mode */
211 
212  virtual bool powerModeQ(bool transit,char &mode);
213 
214  /** Specification of power mode */
215 
216  virtual bool powerMode(bool transit,char mode);
217 
218  /** Check if ptu is moving */
219 
220  virtual double status(double &rad){ return 1; }
221 
222  /** Set limits of movement */
223 
224  virtual bool setLimits(char axis, double &l, double &u);
225 
226  /* Change motion direction */
227 
228  virtual bool changeMotionDir();
229 
230 
231  /**************************** State Queries ********************/
232 
233  /** Check errors, returns 0 if there are not errors or error code in otherwise
234  * Error codes:
235  * \code
236  * 1: Com error
237  * 2: Time out error
238  * 3: Init error
239  * 4: Pan tilt hit error
240  * 5: Pan hit error
241  * 6: Tilt hit error
242  * 7: Max limit error
243  * 8: Min limit error
244  * 9: Out of range
245  * 10: Illegal command error
246  * 11: Unexpected error
247  * \endcode
248  **/
249 
250  virtual int checkErrors();
251 
252  inline bool noError() { return nError==1; }
253  inline bool comError() { return (nError % CPtuDPerception::ComError)==0; }
254  inline bool timeoutError() { return (nError % CPtuDPerception::TimeoutError)==0; }
255  inline bool initError() { return (nError % CPtuDPerception::InitError)==0; }
256  inline bool panTiltHitError() { return (nError % CPtuDPerception::PanTiltHitError)==0; }
257  inline bool panHitError() { return (nError % CPtuDPerception::PanHitError)==0; }
258  inline bool tiltHitError() { return (nError % CPtuDPerception::TiltHitError)==0; }
259  inline bool maxLimitError() { return (nError % CPtuDPerception::MaxLimitError)==0; }
260  inline bool minLimitError () { return (nError % CPtuDPerception::MinLimitError)==0; }
261  inline bool outOfRange() { return (nError % CPtuDPerception::OutOfRange)==0; }
262  inline bool illegalCommandError() { return (nError % CPtuDPerception::IllegalCommandError)==0; }
263  inline bool unExpectedError() { return (nError % CPtuDPerception::UnExpectedError)==0; }
264 
265  /** Clear errors **/
266 
267  virtual void clearErrors() { nError=NoError; }
268 
269 
270  /*************************** Other member methods *****************/
271 
272  public:
273 
274  /** PTU and serial port initialization */
275 
276  virtual bool init(const std::string port);
277 
278  /** Close conection with serial port */
279 
280  virtual void close();
281 
282  /** To obtains the mistake for use discrete values when the movement
283  * is expressed in radians. Parameters are the absolute position in
284  * radians and the axis desired
285  */
286 
287  virtual double radError(char axis,double nRadMoved);
288 
289  /** To obtain the discrete value for a number of radians */
290 
291  virtual long radToPos(char axis,double nRad);
292 
293  /** To obtain the number of radians for a discrete value */
294 
295  virtual double posToRad(char axis,long nPos);
296 
297  /** Performs a scan in the axis indicated and whit the precision desired. \n
298  * \param <axis> {Pan or Till} \n
299  * \param <tWait> {Wait time betwen commands} \n
300  * \param <initial> {initial position}
301  * \param <final> {final position}
302  * \param <radPre> {radians precision for the scan}
303  */
304 
305  virtual bool scan(char axis, int wait, float initial, float final, double radPre);
306 
307  /** Query verbose mode */
308 
309  virtual bool verboseQ(bool &modo);
310 
311  /** Set verbose. \n
312  * \conde
313  * Example of response with FV (verbose) active:
314  * FV *
315  * PP * Current pan position is 0
316  * Example of response with FT (terse) active:
317  * FT *
318  * PP * 0
319  * \endcode
320  */
321 
322  virtual bool verbose(bool set);
323 
324  /** Query echo mode */
325 
326  virtual bool echoModeQ(bool &mode);
327 
328  /** Enable/Disable echo response with command. \n
329  * \code
330  * Example of use (EE supposed):
331  * PP * 22
332  * ED *
333  * <pp entered again, but not echoed>* 22
334  * \endcode
335  */
336 
337  virtual bool echoMode(bool mode);
338 
339  /** Query the pan and tilt resolution per position moved
340  * and initialize local atributes
341  */
342 
343  virtual bool resolution(void);
344 
345 
346  /*************************** Methods for internal use ****************/
347 
348  private:
349 
350  /** To transmition commands to the PTU */
351 
352  virtual bool transmit(const char * command);
353 
354  /** To receive the responseof the PTU */
355 
356  virtual bool receive(const char * command,char * response);
357 
358  /** Used to obtains a number of radians */
359 
360  virtual bool radQuerry(char axis,char command,double &nRad);
361 
362  /** Method used for asign a number of radians with a command */
363 
364  virtual bool radAsign(char axis,char command,double nRad);
365 
366  /** Convert string to double */
367 
368  virtual double convertToDouble(char *sDouble);
369 
370  /** Convert string to long */
371 
372  virtual long convertToLong(char *sLong);
373 
374  /**************************** Atributes ********************/
375 
376  public:
377 
378  enum { NoError = 1, ComError = 2, TimeoutError = 3,
379  InitError = 5,PanHitError = 7, TiltHitError = 11, PanTiltHitError=13,
380  MaxLimitError = 17, MinLimitError = 19, OutOfRange = 23,
381  IllegalCommandError = 29, UnExpectedError =31 };
382 
383  /** TimeoutError: Only occurs if the communication is cut with PTU
384  * so it is advisable to check the connection and initialize
385  * again the comunication.
386  */
387 
388  int nError;
389 
390  enum { Pan = 'P', Tilt = 'T' };
391  enum { Regular = 'R', High = 'H', Low = 'L', Off = 'O' };
392  enum { Com1 = 1, Com2 = 2, Com3 = 3, Com4 = 4 };
393 
394 
395  }; // End of class
396 
397  } // End of namespace
398 
399 } // End of namespace
400 
401 #endif



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