File: cameraPTZExample.cpp

package info (click to toggle)
libaria 2.8.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 13,628 kB
  • ctags: 16,574
  • sloc: cpp: 135,490; makefile: 925; python: 597; java: 570; ansic: 182
file content (167 lines) | stat: -rw-r--r-- 7,501 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
Adept MobileRobots Robotics Interface for Applications (ARIA)
Copyright (C) 2004, 2005 ActivMedia Robotics LLC
Copyright (C) 2006, 2007, 2008, 2009, 2010 MobileRobots Inc.
Copyright (C) 2011, 2012, 2013 Adept Technology

     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.

     This program 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 General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with this program; if not, write to the Free Software
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

If you wish to redistribute ARIA under different terms, contact 
Adept MobileRobots for information about a commercial version of ARIA at 
robots@mobilerobots.com or 
Adept MobileRobots, 10 Columbia Drive, Amherst, NH 03031; +1-603-881-7960
*/
#include "Aria.h"
//#include "ArVideo.h"

/** @example cameraPTZExample.cpp This is an example showing how to connect to
 * and use a camera's PTZ control (or DPPTU)
 *
 * This program can control PTZ cameras with support built in to the ARIA
 * library: Canon VCC 4/5, Sony PTZ, RVision, and DPPTU.    To control the Axis
 * network cameras, see example programs in the ArVideo library instead.
 *
 * PTZ type and connection parameters are read from robot parameter file if
 * available, or use command-line arguments to override the robot parameter
 * file. Run with --help for a complete list of command-line options available.
 *
 * For example, to connect to Canon VCC on robot auxilliary serial port, use:
 *  ./cameraPTZExample -ptzType vcc4 
 *
 * To connect to Canon VCC on serial port COM4, use:
 *  ./cameraPTZExample -ptzType vcc4 -ptzSerialPort COM4 
 * or on Linux this works too:
 *  ./cameraPTZExample -ptzType vcc4 -ptzSerialPort /dev/ttyS3
 *
 * To connect to RVision camera, use:
 *  ./cameraPTZExample -ptzType rvision
 * 
 * To connect to DPPTU use:
 *  ./cameraPTZExample -ptzType dpptu
 *
 * Canon VCC defaults to use the microcontroller port Aux1.  Use
 * -ptzRobotAuxSerialPort or -ptzSerialPort arguments to change.
 */


int main(int argc, char **argv)
{
  Aria::init();
	//ArVideo::init();
//  ArLog::init(ArLog::StdOut, ArLog::Verbose);
  ArArgumentParser parser(&argc, argv);
  parser.loadDefaultArguments();
  ArRobot robot;
  ArRobotConnector robotConnector(&parser, &robot);

  // This is used to create and configure the PTZ interface object based on the
  // robot's parameter file and this program's command line options (run with
  // -help for list). Must be created before calling Aria::parseArgs().
  ArPTZConnector ptzConnector(&parser, &robot);

  if(!robotConnector.connectRobot())
  {
    ArLog::log(ArLog::Terse, "cameraPTZExample: Warning, Could not connect to the robot. Won't use robot parameter file for defaults");
  }

  if (!Aria::parseArgs() || !parser.checkHelpAndWarnUnparsed())
  {
    Aria::logOptions();
    Aria::exit(1);
  }

  ArLog::log(ArLog::Normal, "cameraPTZExample: Connected.");

  robot.runAsync(true);

  // Create and connect to all PTZs given in robot parameter file and command
  // line.
  const int PauseTime = 3500; // ms
  ptzConnector.connect();
  ArUtil::sleep(PauseTime*2);
  for(size_t i = 0; i < ptzConnector.getNumPTZs(); ++i)
  {
    ArLog::log(ArLog::Normal, "cameraPTZExample: [getPTZ(%d)..]", i);

    ArPTZ *ptz = ptzConnector.getPTZ(i);
    if(!ptz)
    {
      ArLog::log(ArLog::Normal, "cameraPTZExample: there is no PTZ %d.", i+1);     
      continue;
    }

    ArLog::log(ArLog::Normal, "cameraPTZExample: ===== PTZ #%d is a %s =====", i+1, ptz->getTypeName());

    ArLog::log(ArLog::Normal, "cameraPTZExample: Pan left -90..");
    ptz->pan(-90);
    ArUtil::sleep(PauseTime);
    ArLog::log(ArLog::Normal, "cameraPTZExample: Pan position is now %f (%s).", ptz->getPan(), (ptz->canGetRealPanTilt()?"real position from camera":"last command sent"));
    if(!ArMath::compareFloats(ptz->getPan(), -90, 1))
      ArLog::log(ArLog::Normal, "cameraPTZExample: Warning: pan position is more than one degree different from command -90.");
      
    ArLog::log(ArLog::Normal, "cameraPTZExample: Pan right 90..");
    ptz->pan(90);
    ArUtil::sleep(PauseTime);
    ArLog::log(ArLog::Normal, "cameraPTZExample: Pan position is now %f. (%s)", ptz->getPan(), (ptz->canGetRealPanTilt()?"real position from camera":"last command sent"));
    if(!ArMath::compareFloats(ptz->getPan(), 90, 1))
      ArLog::log(ArLog::Normal, "cameraPTZExample: Warning: pan position is more than one degree different from command 90.");

    ArLog::log(ArLog::Normal, "cameraPTZExample: Pan center 0..");
    ptz->pan(0);
    ArUtil::sleep(PauseTime);
    ArLog::log(ArLog::Normal, "cameraPTZExample: Pan position is now %f (%s).", ptz->getPan(), (ptz->canGetRealPanTilt()?"real position from camera":"last command sent"));
    if(!ArMath::compareFloats(ptz->getPan(), 0, 1))
      ArLog::log(ArLog::Normal, "cameraPTZExample: Warning: pan position is more than one degree different from command 0.");

    ArLog::log(ArLog::Normal, "cameraPTZExample: Tilt up 90..");
    ptz->tilt(90);
    ArUtil::sleep(PauseTime);
    ArLog::log(ArLog::Normal, "cameraPTZExample: Tilt position is now %f(%s).", ptz->getTilt(), (ptz->canGetRealPanTilt()?"real position from camera":"last command sent"));
    if(!ArMath::compareFloats(ptz->getTilt(), 90, 1))
      ArLog::log(ArLog::Normal, "cameraPTZExample: Warning: tilt position is more than one degree different from command 90.");

    ArLog::log(ArLog::Normal, "cameraPTZExample: Tilt down -20..");
    ptz->tilt(-20);
    ArUtil::sleep(PauseTime);
    ArLog::log(ArLog::Normal, "cameraPTZExample: Tilt position is now %f(%s).", ptz->getTilt(), (ptz->canGetRealPanTilt()?"real position from camera":"last command sent"));
    if(!ArMath::compareFloats(ptz->getTilt(), -20, 1))
      ArLog::log(ArLog::Normal, "cameraPTZExample: Warning: tilt position is more than one degree different from command -20.");

    ArLog::log(ArLog::Normal, "cameraPTZExample: Tilt center 0..");
    ptz->tilt(0);
    ArUtil::sleep(PauseTime);
    ArLog::log(ArLog::Normal, "cameraPTZExample: Tilt position is now %f (%s).", ptz->getTilt(), (ptz->canGetRealPanTilt()?"real position from camera":"last command sent"));
    if(!ArMath::compareFloats(ptz->getTilt(), 0, 1))
      ArLog::log(ArLog::Normal, "cameraPTZExample: Warning: tilt position is more than one degree different from command 0.");

    ArLog::log(ArLog::Normal, "cameraPTZExample: Reset..");
    ptz->reset();
    ArLog::log(ArLog::Normal, "cameraPTZExample: Pan position is now %f (%s).", ptz->getPan(), (ptz->canGetRealPanTilt()?"real position from camera":"last command sent"));
    ArLog::log(ArLog::Normal, "cameraPTZExample: Tilt position is now %f (%s).", ptz->getTilt(), (ptz->canGetRealPanTilt()?"real position from camera":"last command sent"));
    ArUtil::sleep(PauseTime);
  }

  ArLog::log(ArLog::Normal, "cameraPTZExample: Ending robot thread..");
  robot.stopRunning();

  // wait for the thread to stop
  robot.waitForRunExit();

  // exit
  ArLog::log(ArLog::Normal, "cameraPTZExample: Exiting.");
  Aria::exit(0);
  return 0;
}