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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 3a26b90fd Wed Mar 25 20:17:03 2020 +0100 at miƩ mar 25 23:05:41 CET 2020