Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleDPPanTiltControl.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 /** @example ExampleDPPanTiltControl.cpp
26  @relates DPPanTiltControl
27  @ingroup g_examples
28  @brief Simple example for usage of Directed Perception PTU
29 
30  Maximal pan positions (left,right) are -3091,+3019 = -159,+159 degree
31  Maximal tilt positions (down,up) are -913,+602 = -47,+31 degree
32  Resolution degree per position is 0.051428
33  Maximal unloaded speed is 5833 positions/second = 300 degree/second
34 
35  @author MIP
36 */
37 
38 #include <PanTilt/DPPanTiltControl.hh>
39 
40 using namespace BIAS;
41 using namespace std;
42 
43 int main(int argc, char *argv[])
44 {
45 
46  BIAS::DPPanTiltControl panTiltControl;
47  bool bRet = false;
48  if (argc < 2)
49  bRet = panTiltControl.InitPanTiltUnit(0);
50  else
51  bRet = panTiltControl.InitPanTiltUnit(argv[1]);
52  if (!bRet) {
53  cout << "Initialising PTU failed!" << endl;
54  return -1;
55  }
56  panTiltControl.AwaitCompletion();
57 
58  panTiltControl.SetMode(ABSOLUTEMODE);
59  panTiltControl.SetSpeed(1000, 1000);
60  panTiltControl.SetAcceleration(250, 250);
61 
62  if (argc > 2) {
63  if (argv[2][0] == '-' && argv[2][1] == 'r') {
64  panTiltControl.SetPosition(0, 0);
65  cout << "Reset pan-tilt unit." << endl;
66  panTiltControl.ClosePanTiltUnit();
67  return 0;
68  }
69  }
70 
71  bool quit = false;
72  char input;
73  int actPan = -DPPTU_MINPAN;
74  int actTilt = 0;
75  int degree = 0;
76  panTiltControl.SetSpeed(DPPTU_MAXSPEED/10, DPPTU_MAXSPEED/10);
77 
78  while (!quit) {
79 
80  actPan = (int)((double)degree/panTiltControl.GetPanResolution()) + DPPTU_MINPAN;
81 
82  if (actPan > DPPTU_MAXPAN || actTilt > DPPTU_MAXTILT ||
83  actPan < DPPTU_MINPAN || actTilt < DPPTU_MINTILT) {
84  quit = true;
85  break;
86  }
87 
88  panTiltControl.SetPosition(actPan, actTilt);
89 
90  // send synchronisation command to PTU and wait for answer
91 
92  cout << (double)(actPan-DPPTU_MINPAN)*panTiltControl.GetPanResolution()
93  << " degree reached. Continue? (y/n) ";
94  cin >> input;
95  cout << endl;
96  if (input == 'N' || input == 'n') quit = true;
97 
98  degree += 5;
99  }
100 
101  panTiltControl.ClosePanTiltUnit();
102  return 0;
103 }
void AwaitCompletion()
Await completion of currently executed command.
char SetSpeed(int nPanSpeed, int nTiltSpeed)
Set speed for movement.
Basic controller interface for Directed Perception Pan Tilt Unit.
void SetPosition(int nPanPos, int nTiltPos, bool bWaitComplete=true)
Set the current position of the PTU in steps.
int SetMode(int nMode)
Set the mode in which the camera is to operate.
void ClosePanTiltUnit()
closes the comport stream connected to PTU
double GetPanResolution()
Get the resolution of the pan axis.
bool InitPanTiltUnit(int nPort, bool bUSB=false)
Open the given serial port and initialize the pan tilt unit.
char SetAcceleration(int nPanAcc, int nTiltAcc)
Set acceleration for movement.