Aria  2.8.0
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.

/*
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"
int main(int argc, char **argv)
{
//ArVideo::init();
// ArLog::init(ArLog::StdOut, ArLog::Verbose);
ArArgumentParser parser(&argc, argv);
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");
}
{
}
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.");
return 0;
}
ArRobotConnector::connectRobot
bool connectRobot(void)
Sets up the robot then connects it.
Definition: ArRobotConnector.cpp:405
ArPTZ::getPan
virtual double getPan(void) const
The angle the camera is panned to (or last commanded value sent, if unable to obtain real pan positio...
Definition: ArPTZ.h:143
ArPTZConnector::connect
bool connect()
For each PTZ specified in program arguments, and in robot parameters with PTZAutoConnect set to true,...
Definition: ArPTZConnector.cpp:69
ArRobot::stopRunning
void stopRunning(bool doDisconnect=true)
Stops the robot from doing any more processing.
Definition: ArRobot.cpp:340
ArPTZConnector::getNumPTZs
size_t getNumPTZs() const
Definition: ArPTZConnector.h:93
ArArgumentParser::loadDefaultArguments
void loadDefaultArguments(int positon=1)
Adds args from default files and environmental variables.
Definition: ArArgumentParser.cpp:736
ArPTZConnector::getPTZ
ArPTZ * getPTZ(size_t i=0) const
Definition: ArPTZConnector.h:97
ArPTZ::pan
virtual bool pan(double degrees)
Pans to the given degrees. 0 is straight ahead, - is to the left, + to the right.
Definition: ArPTZ.h:111
ArLog::Terse
Use terse logging.
Definition: ArLog.h:61
ArPTZ::tilt
virtual bool tilt(double degrees)
Tilts to the given degrees. 0 is middle, - is downward, + is upwards.
Definition: ArPTZ.h:123
ArPTZ::reset
virtual void reset(void)
Resets the camera.
Definition: ArPTZ.h:107
ArRobotConnector
Connect to robot or simulator based on program command line parameters.
Definition: ArRobotConnector.h:80
Aria::exit
static void exit(int exitCode=0)
Shutdown all Aria processes/threads, call exit callbacks, and exit the program.
Definition: Aria.cpp:367
ArLog::log
static void log(LogLevel level, const char *str,...)
Log a message, with formatting and variable number of arguments.
Definition: ArLog.cpp:93
ArPTZ::getTypeName
virtual const char * getTypeName()=0
Return name of this PTZ type.
Aria::init
static void init(SigHandleMethod method=SIGHANDLE_THREAD, bool initSockets=true, bool sigHandleExitNotShutdown=true)
Initialize Aria global data struture and perform OS-specific initialization, including adding OS sign...
Definition: Aria.cpp:128
ArArgumentParser::checkHelpAndWarnUnparsed
bool checkHelpAndWarnUnparsed(unsigned int numArgsOkay=0)
Checks for the help strings and warns about unparsed arguments.
Definition: ArArgumentParser.cpp:843
ArRobot
Central class for communicating with and operating the robot.
Definition: ArRobot.h:82
ArArgumentParser
Parse and store program command-line arguments for use by other ARIA classes.
Definition: ArArgumentParser.h:64
Aria::logOptions
static void logOptions(void)
Logs all the options for the program (Calls all the callbacks added with addLogOptionsCB())
Definition: Aria.cpp:794
ArPTZConnector
Factory for creating and configuring interfaces for pan/tilt units or camera pan/tilt/zoom control ba...
Definition: ArPTZConnector.h:74
ArPTZ::canGetRealPanTilt
virtual bool canGetRealPanTilt(void) const
Whether getPan() hand getTilt() return the device's real position, or last commanded position.
Definition: ArPTZ.h:158
ArPTZ
Base class which handles the PTZ cameras.
Definition: ArPTZ.h:88
ArRobot::runAsync
void runAsync(bool stopRunIfNotConnected, bool runNonThreadedPacketReader=false)
Starts the instance to do processing in its own new thread.
Definition: ArRobot.cpp:301
Aria::parseArgs
static bool parseArgs(void)
Parses the arguments for the program (calls all the callbacks added with addParseArgsCB())
Definition: Aria.cpp:759
ArPTZ::getTilt
virtual double getTilt(void) const
The angle the camera is tilted to (or last commanded value sent, if unable to obtain real pan positio...
Definition: ArPTZ.h:148
ArUtil::sleep
static void sleep(unsigned int ms)
Sleep for the given number of milliseconds.
Definition: ariaUtil.cpp:151
ArLog::Normal
Use normal logging.
Definition: ArLog.h:62
ArRobot::waitForRunExit
WaitState waitForRunExit(unsigned int msecs=0)
Suspend calling thread until the ArRobot run loop has exited.
Definition: ArRobot.cpp:2923