Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleDPPanTiltControl2.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 ExampleDPPanTiltControl2.cpp
26  @relates DPPanTiltControl
27  @ingroup g_examples
28  @brief Simple example for driving to the left and right with the
29  Directed Perception PTU.
30  @author MIP
31 */
32 
33 #include <PanTilt/DPPanTiltControl.hh>
34 
35 using namespace BIAS;
36 using namespace std;
37 
38 int main(int argc, char *argv[])
39 {
40  DPPanTiltControl panTiltControl;
41 
42  bool bRet = false;
43  if (argc < 2)
44  bRet = panTiltControl.InitPanTiltUnit(0);
45  else
46  bRet = panTiltControl.InitPanTiltUnit(argv[1]);
47  if (!bRet) {
48  cout<<"Initialising PTU failed!"<<endl;
49  return -1;
50  }
51  else
52  panTiltControl.SetMode(ABSOLUTEMODE);
53 
54  panTiltControl.AwaitCompletion();
55  panTiltControl.SetSpeed(DPPTU_MAXSPEED/4, DPPTU_MAXSPEED/4);
56 
57 // panTiltControl.MoveRight(1000);
58 // panTiltControl.MoveLeft(2000);
59 // panTiltControl.MoveRight(1000);
60 
61  panTiltControl.SetMode(SPEEDMODE);
62 
63 // panTiltControl.SetSpeed(-3000,-3000);
64 // sleep(1);
65 // panTiltControl.SetSpeed(3000,3000);
66 // sleep(1);
67 // panTiltControl.SetSpeed(0,0);
68 
69  bool reverse = true;
70  for(int i=0;i<2;i++){
71  if(reverse){
72  panTiltControl.SetPosition(-2000,500);
73  panTiltControl.SetPosition(2000,-500);
74  reverse = false;
75  }
76  else{
77  panTiltControl.SetPosition(2000,-500);
78  panTiltControl.SetPosition(-2000,500);
79  reverse = true;
80  }
81  }
82 
83  panTiltControl.ClosePanTiltUnit();
84  return 0;
85 }
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
bool InitPanTiltUnit(int nPort, bool bUSB=false)
Open the given serial port and initialize the pan tilt unit.