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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019