Aria  2.8.0
ArPTZ Class Referenceabstract

Base class which handles the PTZ cameras. More...

#include <ArPTZ.h>

Inherited by ArAMPTU, ArDPPTU, ArRVisionPTZ, ArSonyPTZ, and ArVCC4.

Public Member Functions

 ArPTZ (ArRobot *robot)
 
virtual bool canGetFOV (void)
 Whether we can get the FOV (field of view) or not.
 
virtual bool canGetRealPanTilt (void) const
 Whether getPan() hand getTilt() return the device's real position, or last commanded position.
 
virtual bool canGetRealZoom (void) const
 Whether getZoom() returns the device's real zoom amount, or last commanded zoom position.
 
virtual bool canPanTiltSlew ()
 Can pan and tilt speed (slew rates) be set to move device?
 
virtual bool canSetFocus (void) const
 If the driver can set the focus on the camera, or not.
 
virtual bool canSetGain (void) const
 If the driver can set gain on the camera, or not.
 
virtual bool canZoom (void) const =0
 Returns true if camera can zoom and this class can control the zoom amount.
 
virtual void connectHandler (void)
 Internal, attached to robot, inits the camera when robot connects.
 
virtual int getAuxPort (void)
 Gets the port the device is set to communicate on.
 
virtual ArDeviceConnectiongetDeviceConnection (void)
 Gets the device connection used by this PTZ camera.
 
virtual double getFocus (double focus) const
 Get the focus the camera is set to. 0 if not supported.
 
virtual double getFOVAtMaxZoom (void)
 Gets the field of view at maximum zoom.
 
virtual double getFOVAtMinZoom (void)
 Gets the field of view at minimum zoom.
 
virtual double getGain (double gain) const
 Get the gain the camera is set to. 0 if not supported.
 
bool getInverted ()
 Get whether the camera is inverted (upside down). If true, pan and tilt axes will be reversed.
 
virtual double getMaxNegPan (void) const
 Gets the lowest negative degree the camera can pan to (inverted if camera is inverted)
 
virtual double getMaxNegTilt (void) const
 Gets the lowest negative degree the camera can tilt to (inverted if camera is inverted)
 
double getMaxPan () const
 Gets the highest positive degree the camera can pan to (inverted if camera is inverted) More...
 
virtual double getMaxPosPan (void) const
 Gets the highest positive degree the camera can pan to (inverted if camera is inverted)
 
virtual double getMaxPosTilt (void) const
 Gets the highest positive degree the camera can tilt to (inverted if camera is inverted)
 
double getMaxTilt () const
 Gets the highest positive degree the camera can tilt to (inverted if camera is inverted) More...
 
virtual int getMaxZoom (void) const
 Gets the maximum value for the zoom on this camera.
 
double getMinPan () const
 Gets the lowest negative degree the camera can pan to (inverted if camera is inverted) More...
 
double getMinTilt () const
 Gets the lowest negative degree the camera can tilt to (inverted if camera is inverted) More...
 
virtual int getMinZoom (void) const
 Gets the lowest value for the zoom on this camera.
 
virtual double getPan (void) const
 The angle the camera is panned to (or last commanded value sent, if unable to obtain real pan position) More...
 
ArRobotgetRobot ()
 Return ArRobot object this PTZ is associated with. May be NULL.
 
virtual double getTilt (void) const
 The angle the camera is tilted to (or last commanded value sent, if unable to obtain real pan position) More...
 
virtual const char * getTypeName ()=0
 Return name of this PTZ type.
 
virtual int getZoom (void) const
 The amount the camera is zoomed to (or last commanded value sent, if unable to obtain real pan position) More...
 
virtual bool haltPanTilt ()
 Halt any pan/tilt movement, if device supports it.
 
virtual bool haltZoom ()
 Halt any zoom movement, if device supports that.
 
virtual bool init (void)=0
 Initializes the camera.
 
virtual bool packetHandler (ArBasePacket *packet)
 Handles a packet that was read from the device. More...
 
virtual bool pan (double degrees)
 Pans to the given degrees. 0 is straight ahead, - is to the left, + to the right.
 
virtual bool panRel (double degrees)
 Pans relative to current position by given degrees.
 
virtual bool panSlew (double s)
 Set pan slew rate (speed) (degrees/sec) if device supports it (see canPanTiltSlew())
 
virtual bool panTilt (double degreesPan, double degreesTilt)
 Pans and tilts to the given degrees.
 
virtual bool panTiltRel (double degreesPan, double degreesTilt)
 Pans and tilts relatives to the current position by the given degrees.
 
virtual ArBasePacketreadPacket (void)
 Reads a packet from the device connection, MUST NOT BLOCK. More...
 
virtual void reset (void)
 Resets the camera. More...
 
virtual bool robotPacketHandler (ArRobotPacket *packet)
 Handles a packet that was read by the robot. More...
 
virtual bool sendPacket (ArBasePacket *packet)
 Sends a given packet to the camera (via robot or serial port, depending) More...
 
virtual void sensorInterpHandler (void)
 Internal, for attaching to the robots sensor interp to read serial port.
 
virtual bool setAuxPort (int auxPort)
 Sets the aux port on the robot to be used to communicate with this device. More...
 
virtual bool setDeviceConnection (ArDeviceConnection *connection, bool driveFromRobotLoop=true)
 Sets the device connection to be used by this PTZ camera, if set this camera will send commands via this connection, otherwise its via robot aux. More...
 
virtual bool setFocus (double focus) const
 Set focus on camera, range of 1-100. More...
 
virtual bool setGain (double gain) const
 Set gain on camera, range of 1-100. More...
 
void setInverted (bool inv)
 Set whether the camera is inverted (upside down). If true, pan and tilt axes will be reversed.
 
virtual bool tilt (double degrees)
 Tilts to the given degrees. 0 is middle, - is downward, + is upwards.
 
virtual bool tiltRel (double degrees)
 Tilts relative to the current position by given degrees.
 
virtual bool tiltSlew (double s)
 Set tilt slew rate (speed) (degrees/sec) if device supports it (see canPanTiltSlew())
 
virtual bool zoom (int zoomValue)
 Zooms to the given value.
 
virtual bool zoomRel (int zoomValue)
 Zooms relative to the current value, by the given value.
 
virtual ~ArPTZ ()
 Destructor.
 

Protected Member Functions

void setLimits (double maxPosPan, double maxNegPan, double maxPosTilt, double maxNegTilt, int maxZoom=0, int minZoom=0)
 Subclasses call this to set extents (limits) returned by getMaxPosPan(), getMaxNegPan(), getMaxPosTilt(), getMaxNegTilt(), getMaxZoom(), and getMinZoom(). More...
 
virtual double getMaxPosPan_i (void) const
 Versions of the pan and tilt limit accessors where inversion is not applied, for use by subclasses to check when given pan/tilt commands. More...
 
double getMaxPan_i () const
 
virtual double getMaxPosTilt_i (void) const
 
double getMinPan_i () const
 
virtual double getMaxNegPan_i (void) const
 
double getMaxTilt_i () const
 
virtual double getMaxNegTilt_i (void) const
 
double getMinTilt_i () const
 
virtual bool pan_i (double degrees)=0
 Internal implementations by subclasses. More...
 
virtual bool panRel_i (double degrees)=0
 
virtual bool tilt_i (double degrees)=0
 
virtual bool tiltRel_i (double degrees)=0
 
virtual bool panTilt_i (double degreesPan, double degreesTilt)=0
 
virtual bool panTiltRel_i (double degreesPan, double degreesTilt)=0
 
virtual double getPan_i (void) const =0
 
virtual double getTilt_i (void) const =0
 

Protected Attributes

int myAuxPort
 
ArCommands::Commands myAuxRxCmd
 
ArCommands::Commands myAuxTxCmd
 
ArDeviceConnectionmyConn
 
ArFunctorC< ArPTZmyConnectCB
 
bool myInverted
 
double myMaxNegPan
 
double myMaxNegTilt
 
double myMaxPosPan
 
double myMaxPosTilt
 
int myMaxZoom
 
int myMinZoom
 
ArRobotmyRobot
 
ArRetFunctor1C< bool, ArPTZ, ArRobotPacket * > myRobotPacketHandlerCB
 
ArFunctorC< ArPTZmySensorInterpCB
 

Detailed Description

Base class which handles the PTZ cameras.

This class is mainly concerned with making all the cameras look the same for outgoing data, it is also set up to facilitate the acquisition of incoming data but that is described in the following paragraphs. There are two ways this can be used. The first is the simplest and default behavior and should be used by those whose cameras are attached to their robot's microcontroller, a ArRobot pointer is passed in to the contructor, this is where the commands will be sent to the robot via the robot's connection which will then send it along over the second serial port. The second way is to pass an ArDeviceConnection to setDeviceConnection, if this is done commands will be sent along the given serial port, this should ONLY be done if the camera is attached straight to a serial port on the computer this program is running on.

The next two paragraphs describe how to get data back from the cameras, but this base class is set up so that by default it won't try to get data back and assumes you're not trying to do that. If you are trying to get data back the important functions are packetHandler, robotPacketHandler and readPacket and you should read the docs on those.

If the camera is attached to the robot (and you are thus using the first method described in the first paragraph) then the only way to get data back is to send an ArCommands::GETAUX, then set up a robotPacketHandler for the AUX id and have it call the packetHandler you set up in in the class.

If the camera is attached to the serial port on the computer (and thus the second method described in the first paragraph was used) then its more complicated... the default way is to just pass in an ArDeviceConnection to setDeviceConnection and implement the readPacket method (which MUST not block), and every time through the robot loop readPacket (with the sensorInterpHandler) will be called and any packets will be given to the packetHandler (which you need to implement in your class) to be processed. The other way to do this method is to pass both an ArDefaultConnection and false to setDeviceConnection, this means the camera will not be read at all by default, and you're on your own for reading the data in (ie like your own thread).

Examples:
cameraPTZExample.cpp.

Constructor & Destructor Documentation

◆ ArPTZ()

ArPTZ::ArPTZ ( ArRobot robot)
Parameters
robotThe robot this camera is attached to, can be NULL

Member Function Documentation

◆ getMaxPan()

double ArPTZ::getMaxPan ( ) const
inline

Gets the highest positive degree the camera can pan to (inverted if camera is inverted)

◆ getMaxPosPan_i()

virtual double ArPTZ::getMaxPosPan_i ( void  ) const
inlineprotectedvirtual

Versions of the pan and tilt limit accessors where inversion is not applied, for use by subclasses to check when given pan/tilt commands.

◆ getMaxTilt()

double ArPTZ::getMaxTilt ( ) const
inline

Gets the highest positive degree the camera can tilt to (inverted if camera is inverted)

◆ getMinPan()

double ArPTZ::getMinPan ( ) const
inline

Gets the lowest negative degree the camera can pan to (inverted if camera is inverted)

◆ getMinTilt()

double ArPTZ::getMinTilt ( ) const
inline

Gets the lowest negative degree the camera can tilt to (inverted if camera is inverted)

◆ getPan()

virtual double ArPTZ::getPan ( void  ) const
inlinevirtual

The angle the camera is panned to (or last commanded value sent, if unable to obtain real pan position)

See also
canGetRealPanTilt()
Examples:
cameraPTZExample.cpp.

◆ getTilt()

virtual double ArPTZ::getTilt ( void  ) const
inlinevirtual

The angle the camera is tilted to (or last commanded value sent, if unable to obtain real pan position)

See also
canGetRealPanTilt()
Examples:
cameraPTZExample.cpp.

◆ getZoom()

virtual int ArPTZ::getZoom ( void  ) const
inlinevirtual

The amount the camera is zoomed to (or last commanded value sent, if unable to obtain real pan position)

See also
canZoom();
canGetZoom()

◆ packetHandler()

virtual bool ArPTZ::packetHandler ( ArBasePacket packet)
inlinevirtual

Handles a packet that was read from the device.

This should work for the robot packet handler or for packets read in from readPacket (the joys of OO), but it can't deal with the need to check the id on robot packets, so you should check the id from robotPacketHandler and then call this one so that your stuff can be used by both robot and serial port connections.

Parameters
packetthe packet to handle
Returns
true if this packet was handled (ie this knows what it is), false otherwise

◆ pan_i()

virtual bool ArPTZ::pan_i ( double  degrees)
protectedpure virtual

Internal implementations by subclasses.

Inverted is not applied in these functions, it is done in the public interface above. Note, once execution enters one of these _i methods, then inversion has been applied and no call should be made to any pan/tilt or max/min limit accessor method that does not end in _i, or inversion will be applied again, reversing it.

Since
2.7.6

◆ readPacket()

virtual ArBasePacket* ArPTZ::readPacket ( void  )
inlinevirtual

Reads a packet from the device connection, MUST NOT BLOCK.

This should read in a packet from the myConn connection and return a pointer to a packet if there was on to read in, or NULL if there wasn't one... this MUST not block if it is used with the default mode of being driven from the sensorInterpHandler, since that is on the robot loop.

Returns
packet read in, or NULL if there was no packet read

◆ reset()

virtual void ArPTZ::reset ( void  )
inlinevirtual

Resets the camera.

This function will reset the camera to 0 0 pan tilt, and 0 zoom, on some cameras that can get out of sync it may need to do more, such as call init on it again.

Examples:
cameraPTZExample.cpp.

◆ robotPacketHandler()

bool ArPTZ::robotPacketHandler ( ArRobotPacket packet)
virtual

Handles a packet that was read by the robot.

This handles packets read in from the robot, this function should just check the ID of the robot packet and then return what packetHandler thinks of the packet.

Parameters
packetthe packet to handle
Returns
true if the packet was handled (ie this konws what it is), false otherwise

◆ sendPacket()

bool ArPTZ::sendPacket ( ArBasePacket packet)
virtual

Sends a given packet to the camera (via robot or serial port, depending)

Parameters
packetthe packet to send
Returns
true if the packet could be sent, false otherwise

◆ setAuxPort()

bool ArPTZ::setAuxPort ( int  auxPort)
virtual

Sets the aux port on the robot to be used to communicate with this device.

Parameters
auxPortWhich auxilliary serial port on the robot's microcontroller that the device is connected to. (The C166 controller only has one port; the H8 has two; the SH has three.)
Returns
true if auxPort was valid (1, 2 or 3). False otherwise. If auxPort was an invalid number, the previous setting will be retained.

◆ setDeviceConnection()

bool ArPTZ::setDeviceConnection ( ArDeviceConnection connection,
bool  driveFromRobotLoop = true 
)
virtual

Sets the device connection to be used by this PTZ camera, if set this camera will send commands via this connection, otherwise its via robot aux.

serial port (see setAuxPortt())

Parameters
connectionthe device connection the camera is connected to, normally a serial port
driveFromRobotLoopif this is true then a sensor interp callback wil be set and that callback will read packets and call the packet handler on them
Returns
true if the serial port is opened or can be opened, false otherwise

◆ setFocus()

virtual bool ArPTZ::setFocus ( double  focus) const
inlinevirtual

Set focus on camera, range of 1-100.

Returns false if out of range or if you can't set the focus on the camera

◆ setGain()

virtual bool ArPTZ::setGain ( double  gain) const
inlinevirtual

Set gain on camera, range of 1-100.

Returns false if out of range or if you can't set the gain on the camera

◆ setLimits()

void ArPTZ::setLimits ( double  maxPosPan,
double  maxNegPan,
double  maxPosTilt,
double  maxNegTilt,
int  maxZoom = 0,
int  minZoom = 0 
)
inlineprotected

Subclasses call this to set extents (limits) returned by getMaxPosPan(), getMaxNegPan(), getMaxPosTilt(), getMaxNegTilt(), getMaxZoom(), and getMinZoom().

Since
2.7.6

The documentation for this class was generated from the following files: