Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleDPPanTiltControl.cpp

Simple example for usage of Directed Perception PTUMaximal pan positions (left,right) are -3091,+3019 = -159,+159 degree Maximal tilt positions (down,up) are -913,+602 = -47,+31 degree Resolution degree per position is 0.051428 Maximal unloaded speed is 5833 positions/second = 300 degree/second

Author
MIP
/*
This file is part of the BIAS library (Basic ImageAlgorithmS).
Copyright (C) 2003-2009 (see file CONTACT for details)
Multimediale Systeme der Informationsverarbeitung
Institut fuer Informatik
Christian-Albrechts-Universitaet Kiel
BIAS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
BIAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with BIAS; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/** @example ExampleDPPanTiltControl.cpp
@relates DPPanTiltControl
@ingroup g_examples
@brief Simple example for usage of Directed Perception PTU
Maximal pan positions (left,right) are -3091,+3019 = -159,+159 degree
Maximal tilt positions (down,up) are -913,+602 = -47,+31 degree
Resolution degree per position is 0.051428
Maximal unloaded speed is 5833 positions/second = 300 degree/second
@author MIP
*/
#include <PanTilt/DPPanTiltControl.hh>
using namespace BIAS;
using namespace std;
int main(int argc, char *argv[])
{
BIAS::DPPanTiltControl panTiltControl;
bool bRet = false;
if (argc < 2)
bRet = panTiltControl.InitPanTiltUnit(0);
else
bRet = panTiltControl.InitPanTiltUnit(argv[1]);
if (!bRet) {
cout << "Initialising PTU failed!" << endl;
return -1;
}
panTiltControl.AwaitCompletion();
panTiltControl.SetMode(ABSOLUTEMODE);
panTiltControl.SetSpeed(1000, 1000);
panTiltControl.SetAcceleration(250, 250);
if (argc > 2) {
if (argv[2][0] == '-' && argv[2][1] == 'r') {
panTiltControl.SetPosition(0, 0);
cout << "Reset pan-tilt unit." << endl;
panTiltControl.ClosePanTiltUnit();
return 0;
}
}
bool quit = false;
char input;
int actPan = -DPPTU_MINPAN;
int actTilt = 0;
int degree = 0;
panTiltControl.SetSpeed(DPPTU_MAXSPEED/10, DPPTU_MAXSPEED/10);
while (!quit) {
actPan = (int)((double)degree/panTiltControl.GetPanResolution()) + DPPTU_MINPAN;
if (actPan > DPPTU_MAXPAN || actTilt > DPPTU_MAXTILT ||
actPan < DPPTU_MINPAN || actTilt < DPPTU_MINTILT) {
quit = true;
break;
}
panTiltControl.SetPosition(actPan, actTilt);
// send synchronisation command to PTU and wait for answer
cout << (double)(actPan-DPPTU_MINPAN)*panTiltControl.GetPanResolution()
<< " degree reached. Continue? (y/n) ";
cin >> input;
cout << endl;
if (input == 'N' || input == 'n') quit = true;
degree += 5;
}
panTiltControl.ClosePanTiltUnit();
return 0;
}