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



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019