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