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.
#include "Aria.h"
int main(int argc, char **argv)
{
{
ArLog::log(
ArLog::Terse,
"cameraPTZExample: Warning, Could not connect to the robot. Won't use robot parameter file for defaults");
}
{
}
const int PauseTime = 3500;
for(
size_t i = 0; i < ptzConnector.
getNumPTZs(); ++i)
{
if(!ptz)
{
continue;
}
if(!ArMath::compareFloats(ptz->
getPan(), -90, 1))
ArLog::log(
ArLog::Normal,
"cameraPTZExample: Warning: pan position is more than one degree different from command -90.");
if(!ArMath::compareFloats(ptz->
getPan(), 90, 1))
ArLog::log(
ArLog::Normal,
"cameraPTZExample: Warning: pan position is more than one degree different from command 90.");
if(!ArMath::compareFloats(ptz->
getPan(), 0, 1))
ArLog::log(
ArLog::Normal,
"cameraPTZExample: Warning: pan position is more than one degree different from command 0.");
if(!ArMath::compareFloats(ptz->
getTilt(), 90, 1))
ArLog::log(
ArLog::Normal,
"cameraPTZExample: Warning: tilt position is more than one degree different from command 90.");
if(!ArMath::compareFloats(ptz->
getTilt(), -20, 1))
ArLog::log(
ArLog::Normal,
"cameraPTZExample: Warning: tilt position is more than one degree different from command -20.");
if(!ArMath::compareFloats(ptz->
getTilt(), 0, 1))
ArLog::log(
ArLog::Normal,
"cameraPTZExample: Warning: tilt position is more than one degree different from command 0.");
}
return 0;
}
bool connectRobot(void)
Sets up the robot then connects it.
Definition: ArRobotConnector.cpp:405
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
bool connect()
For each PTZ specified in program arguments, and in robot parameters with PTZAutoConnect set to true,...
Definition: ArPTZConnector.cpp:69
void stopRunning(bool doDisconnect=true)
Stops the robot from doing any more processing.
Definition: ArRobot.cpp:340
size_t getNumPTZs() const
Definition: ArPTZConnector.h:93
void loadDefaultArguments(int positon=1)
Adds args from default files and environmental variables.
Definition: ArArgumentParser.cpp:736
ArPTZ * getPTZ(size_t i=0) const
Definition: ArPTZConnector.h:97
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
@ Terse
Use terse logging.
Definition: ArLog.h:61
virtual bool tilt(double degrees)
Tilts to the given degrees. 0 is middle, - is downward, + is upwards.
Definition: ArPTZ.h:123
virtual void reset(void)
Resets the camera.
Definition: ArPTZ.h:107
Connect to robot or simulator based on program command line parameters.
Definition: ArRobotConnector.h:80
static void exit(int exitCode=0)
Shutdown all Aria processes/threads, call exit callbacks, and exit the program.
Definition: Aria.cpp:367
static void log(LogLevel level, const char *str,...)
Log a message, with formatting and variable number of arguments.
Definition: ArLog.cpp:93
virtual const char * getTypeName()=0
Return name of this PTZ type.
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
bool checkHelpAndWarnUnparsed(unsigned int numArgsOkay=0)
Checks for the help strings and warns about unparsed arguments.
Definition: ArArgumentParser.cpp:843
Central class for communicating with and operating the robot.
Definition: ArRobot.h:82
Parse and store program command-line arguments for use by other ARIA classes.
Definition: ArArgumentParser.h:64
static void logOptions(void)
Logs all the options for the program (Calls all the callbacks added with addLogOptionsCB())
Definition: Aria.cpp:794
Factory for creating and configuring interfaces for pan/tilt units or camera pan/tilt/zoom control ba...
Definition: ArPTZConnector.h:74
virtual bool canGetRealPanTilt(void) const
Whether getPan() hand getTilt() return the device's real position, or last commanded position.
Definition: ArPTZ.h:158
Base class which handles the PTZ cameras.
Definition: ArPTZ.h:88
void runAsync(bool stopRunIfNotConnected, bool runNonThreadedPacketReader=false)
Starts the instance to do processing in its own new thread.
Definition: ArRobot.cpp:301
static bool parseArgs(void)
Parses the arguments for the program (calls all the callbacks added with addParseArgsCB())
Definition: Aria.cpp:759
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
static void sleep(unsigned int ms)
Sleep for the given number of milliseconds.
Definition: ariaUtil.cpp:151
@ Normal
Use normal logging.
Definition: ArLog.h:62
WaitState waitForRunExit(unsigned int msecs=0)
Suspend calling thread until the ArRobot run loop has exited.
Definition: ArRobot.cpp:2923