Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PanTiltManualControl.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 #include <Base/Common/BIASpragma.hh>
26 #include <PanTilt/DPPanTiltControl.hh>
27 #ifdef WIN32
28  #include <conio.h>
29 #else // WIN32
30  #include <ncurses.h>
31 #endif // WIN32
32 #include <fstream>
33 
34 #include "PanTiltManualControl.hh"
35 
36 using namespace std;
37 using namespace BIAS;
38 
39 /* contructor, just calls base constructor */
40 PanTiltManualControl::PanTiltManualControl(std::string device, bool heavyDutyMode):
41  PanTiltControlInterface(device, heavyDutyMode)
42 {
43 
44 }
45 /* starts the control */
47  int min_pan = -2000;
48  int max_pan = 2000;
49  int min_tilt = -900;
50  int max_tilt = 700;
51  int pan_mod = 100;
52  int tilt_mod = 100;
53 
55  await_completion();
56  PanTiltControlInterface::ptControl.SetSpeed(MAXSPEED/4,MAXSPEED/4);
57 
58  ofstream myfile;
59  myfile.open("ptu_data.txt", ios::out);
60 
61  int key=-1;
62  bool looping = true;
63  bool move_pt;
64  while(looping) {
65  key = getch();
66  move_pt = false;
67  switch (key) {
68  case 'a':
69  cur_pan+=pan_mod;
70  if (cur_pan > max_pan)
71  cur_pan = max_pan;
72  move_pt = true;
73  break;
74  case 'd':
75  cur_pan-=pan_mod;
76  if (cur_pan < min_pan)
77  cur_pan = min_pan;
78  move_pt = true;
79  break;
80  case 'w':
81  cur_tilt+=tilt_mod;
82  if (cur_tilt > max_tilt)
83  cur_tilt = max_tilt;
84  move_pt = true;
85  break;
86  case 's':
87  cur_tilt-=tilt_mod;
88  if (cur_tilt < min_tilt)
89  cur_tilt = min_tilt;
90  move_pt = true;
91  break;
92  case 'o':
93  PanTiltControlInterface::ptControl.SetSpeed(MAXSPEED/4, MAXSPEED/4);
94  for (int i=0;i<=10;i+=2) {
95  int tilt = -500+(tilt_mod*i);
96  key = getch();
97  if (key == 'q')
98  break;
100  key = getch();
101  if (key == 'q')
102  break;
104  }
105  PanTiltControlInterface::ptControl.SetSpeed(MAXSPEED, MAXSPEED);
106  move_pt=true;
107  break;
108  case ' ':
109  looping = false;
110  myfile.close();
111  break;
112  }
113  if (move_pt) {
115  await_completion();
116  double p,t;
118  myfile << p << " ";
119  myfile << t << endl;
120 #ifdef WIN32
121  cout << "PAN: " << cur_pan << " TILT: " << cur_tilt << endl;
122  cout << "PAN: " << p << " TILT: " << t << endl;
123 #else
124  mvprintw(4,0, "PAN: %d Tilt: %d \n", cur_pan, cur_tilt);
125  mvprintw(5,0, "PAN: %f Tilt: %f \n", p, t);
126 #endif
127  }
128  }
130  cout << "exited from ncurses loop" << endl;
131 }
char SetSpeed(int nPanSpeed, int nTiltSpeed)
Set speed for movement.
abstract control class for control of Directed Perception Pan Tilt Unit.
void StartControl()
Start the control.
static void GetPositionDegrees(double &panDegree, double &tiltDegree)
Get position in degrees, values should be updated by derived classes.
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.