MRPT  2.0.0
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([[maybe_unused]] double& rad) override { return 1; }
195 
196  /** Set limits of movement */
197 
198  bool setLimits(char axis, double& l, double& u) override;
199 
200  /* Change motion direction */
201 
202  bool changeMotionDir() override;
203 
204  /**************************** State Queries ********************/
205 
206  /** Check errors, returns 0 if there are not errors or error code in
207  *otherwise
208  * Error codes:
209  * \code
210  * 1: Com error
211  * 2: Time out error
212  * 3: Init error
213  * 4: Pan tilt hit error
214  * 5: Pan hit error
215  * 6: Tilt hit error
216  * 7: Max limit error
217  * 8: Min limit error
218  * 9: Out of range
219  * 10: Illegal command error
220  * 11: Unexpected error
221  * \endcode
222  **/
223 
224  int checkErrors() override;
225 
226  inline bool noError() { return nError == 1; }
227  inline bool comError() { return (nError % CPtuDPerception::ComError) == 0; }
228  inline bool timeoutError()
229  {
230  return (nError % CPtuDPerception::TimeoutError) == 0;
231  }
232  inline bool initError()
233  {
234  return (nError % CPtuDPerception::InitError) == 0;
235  }
236  inline bool panTiltHitError()
237  {
239  }
240  inline bool panHitError()
241  {
242  return (nError % CPtuDPerception::PanHitError) == 0;
243  }
244  inline bool tiltHitError()
245  {
246  return (nError % CPtuDPerception::TiltHitError) == 0;
247  }
248  inline bool maxLimitError()
249  {
250  return (nError % CPtuDPerception::MaxLimitError) == 0;
251  }
252  inline bool minLimitError()
253  {
254  return (nError % CPtuDPerception::MinLimitError) == 0;
255  }
256  inline bool outOfRange()
257  {
258  return (nError % CPtuDPerception::OutOfRange) == 0;
259  }
260  inline bool illegalCommandError()
261  {
263  }
264  inline bool unExpectedError()
265  {
267  }
268 
269  /** Clear errors **/
270 
271  void clearErrors() override { nError = NoError; }
272  /*************************** Other member methods *****************/
273 
274  public:
275  /** PTU and serial port initialization */
276 
277  bool init(const std::string& port) override;
278 
279  /** Close Connection with serial port */
280 
281  void close() override;
282 
283  /** To obtains the mistake for use discrete values when the movement
284  * is expressed in radians. Parameters are the absolute position in
285  * radians and the axis desired
286  */
287 
288  double radError(char axis, double nRadMoved) override;
289 
290  /** To obtain the discrete value for a number of radians */
291 
292  long radToPos(char axis, double nRad) override;
293 
294  /** To obtain the number of radians for a discrete value */
295 
296  double posToRad(char axis, long nPos) override;
297 
298  /** Performs a scan in the axis indicated and whit the precision desired. \n
299  * \param <axis> {Pan or Till} \n
300  * \param <tWait> {Wait time betwen commands} \n
301  * \param <initial> {initial position}
302  * \param <final> {final position}
303  * \param <radPre> {radians precision for the scan}
304  */
305 
306  bool scan(char axis, int wait, float initial, float final, double radPre)
307  override;
308 
309  /** Query verbose mode */
310 
311  bool verboseQ(bool& modo) override;
312 
313  /** Set verbose. \n
314  * \conde
315  * Example of response with FV (verbose) active:
316  * FV *
317  * PP * Current pan position is 0
318  * Example of response with FT (terse) active:
319  * FT *
320  * PP * 0
321  * \endcode
322  */
323 
324  bool verbose(bool set) override;
325 
326  /** Query echo mode */
327 
328  bool echoModeQ(bool& mode) override;
329 
330  /** Enable/Disable echo response with command. \n
331  * \code
332  * Example of use (EE supposed):
333  * PP * 22
334  * ED *
335  * <pp entered again, but not echoed>* 22
336  * \endcode
337  */
338 
339  bool echoMode(bool mode) override;
340 
341  /** Query the pan and tilt resolution per position moved
342  * and initialize local atributes
343  */
344 
345  bool resolution() override;
346 
347  /*************************** Methods for internal use ****************/
348 
349  private:
350  /** To transmition commands to the PTU */
351 
352  bool transmit(const char* command) override;
353 
354  /** To receive the responseof the PTU */
355 
356  bool receive(const char* command, char* response) override;
357 
358  /** Used to obtains a number of radians */
359 
360  bool radQuerry(char axis, char command, double& nRad) override;
361 
362  /** Method used for asign a number of radians with a command */
363 
364  bool radAsign(char axis, char command, double nRad) override;
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  enum
378  {
379  NoError = 1,
380  ComError = 2,
391  };
392 
393  /** TimeoutError: Only occurs if the communication is cut with PTU
394  * so it is advisable to check the connection and initialize
395  * again the communication.
396  */
397 
398  int nError;
399 
400  enum
401  {
402  Pan = 'P',
403  Tilt = 'T'
404  };
405  enum
406  {
407  Regular = 'R',
408  High = 'H',
409  Low = 'L',
410  Off = 'O'
411  };
412  enum
413  {
414  Com1 = 1,
415  Com2 = 2,
416  Com3 = 3,
417  Com4 = 4
418  };
419 
420 }; // End of class
421 
422 } // 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.
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...
double status([[maybe_unused]] double &rad) override
Check if ptu is moving.
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.
bool lowerSpeedQ(char axis, double &radSec) override
Query velocity lower limit.



Page generated by Doxygen 1.8.14 for MRPT 2.0.0 Git: b38439d21 Tue Mar 31 19:58:06 2020 +0200 at miƩ abr 1 00:50:30 CEST 2020