#include <ArServerHandlerCamera.h>
Inheritance diagram for ArServerHandlerCamera:
The following requests are accepted. Arguments and return values are stored in the packet as signed 16-bit values. (They are converted to double-precision floating point values when received by dividing by 100; to store floating point values, multiply by 100 first: packet.byte2ToBuf((ArTypes::Byte2)(100.0 * doubleVal));
or see also getDoubleFromPacket() and addDoubleToPacket().)
Each request name is suffixed by the name of the camera to control. If more than one camera is used, each can have a different name (given in the constructor), and commands for the different cameras are differentiated by appending the camera name to the command requests listed below. For example, an ArServerHandlerCamera with camera name of "A" would receive "setCameraRelA". while the handler with camera name of "B" would receive "setCameraAbsB". If no camera name is given (typical if just one ArServerHandlerCamera object is created), just the base requests are used. To provide information to the client about the multiple cameras and their names, use ArCameraCollection and an ArServerHandlerCameraCollection object.
setCameraRel | Command to pan and tilt the camera from the current position by the values given in the first two arguments. If a third argument is given, zoom from the current position. |
setCameraAbs | Command to pan and tilt the camera to the absolute positions given by the first two arguments. If a third argument is given, set the zoom to that absolute position. |
setCameraPct | Command to pan and tilt the camera to the given positions as percentage of their overall ranges. |
getCameraData | Data request to get current pan and tilt values. Also get zoom value if available. |
getCameraInfo | Data request to get pan and tilt ranges. Also gets the zoom range if available.
In addition, some older camera requests are accepted for partial backwards compatability with old clients: cameraUpdate, cameraInfo, cameraAbs, camera, and cameraPct. These requests take values as single bytes, rather than multiplied floats as 2-bytes as the above commands do. Note, these cannot be used in a multi-camera configuration. These requests are in a user permission group called CameraControl. In addition to positioning the camera, ArServerHandlerCamera can support additional "modes" for camera control, if additional code is added to update ArServerHandlerCamera with the state of other systems such as navigation. The additional modes are LookAtGoal and LookAtPoint. An external system such as navigation (e.g. ARNL) must keep the camera handler object updated with its current goal by calling cameraModeLookAtGoalSetGoal() and cameraModeLookAtGoalClearGoal(), and ArServerHandlerCamera will continuously point the camera at that point or goal as the robot moves. The network requests associated with setting modes are:
|
Public Member Functions | |
virtual void | addToCameraCollection (ArCameraCollection &collection) |
Adds the camera commands to the given collection. | |
ArServerHandlerCamera (ArServerBase *server, ArRobot *robot, ArPTZ *camera) | |
Constructor. | |
ArServerHandlerCamera (const char *cameraName, ArServerBase *server, ArRobot *robot, ArPTZ *camera, ArCameraCollection *collection) | |
Constructs a new handler for the specified camera. | |
void | camera (ArServerClient *client, ArNetPacket *packet) |
Handles the camera network packet, with information stored as byte integers. | |
void | cameraAbs (ArServerClient *client, ArNetPacket *packet) |
Handles the cameraAbs network packet, with information stored as byte integers. | |
void | cameraInfo (ArServerClient *client, ArNetPacket *packet) |
Handles the cameraInfo network packet, with information returned as byte2 integers. | |
void | cameraModeLookAtGoal (void) |
Puts the camera into a mode where it will look at the goal. | |
void | cameraModeLookAtGoalClearGoal (void) |
Clears the goal for the camera mode that points at the goal. | |
void | cameraModeLookAtGoalSetGoal (ArPose pose) |
Sets the goal for the camera mode that points at the goal. | |
void | cameraModeLookAtPoint (ArPose pose, bool controlZoom=true) |
Puts the camera into a mode where it will look at a point. | |
void | cameraModePosition (void) |
Puts the camera in position mode. | |
void | cameraPct (ArServerClient *client, ArNetPacket *packet) |
Handles the cameraPct network packet, with information stored as byte integers. | |
void | cameraUpdate (ArServerClient *client, ArNetPacket *packet) |
Handles the cameraUpdate network packet, with information returned as byte2 integers. | |
const char * | getCameraName () |
Returns the name of the camera that is controlled by this handler. | |
void | handleCameraModeUpdated (ArServerClient *client, ArNetPacket *packet) |
Handle the mode request, generally this is sent when it changes. | |
void | handleGetCameraData (ArServerClient *client, ArNetPacket *packet) |
Handles the getCameraData network packet, returning information in double format. | |
void | handleGetCameraInfo (ArServerClient *client, ArNetPacket *packet) |
Handles the getCameraInfo network packet, returning information in double format. | |
void | handleGetCameraModeList (ArServerClient *client, ArNetPacket *packet) |
Handles the mode list for the camera. | |
void | handleResetCamera (ArServerClient *client, ArNetPacket *packet) |
Handle the reset. | |
void | handleSetCameraAbs (ArServerClient *client, ArNetPacket *packet) |
Handles the setCameraAbs network packet, with information in double format. | |
void | handleSetCameraMode (ArServerClient *client, ArNetPacket *packet) |
Handle the set mode request. | |
void | handleSetCameraPct (ArServerClient *client, ArNetPacket *packet) |
Handles the setCameraPct network packet, with information in double format. | |
void | handleSetCameraRel (ArServerClient *client, ArNetPacket *packet) |
Handles the setCameraRel network packet, with information in double format. | |
void | resetCamera (bool lockRobot=true) |
Resets the camera. | |
void | setCameraAbs (double pan, double tilt, double zoom, bool lockRobot=true) |
Sends the camera absolute commands to the camera (and puts it in position mode). | |
void | setCameraPct (double panPct, double tiltPct, bool lockRobot=true) |
Sends the camera percent commands to the camera (and puts it in position mode). | |
void | setCameraRel (double pan, double tilt, double zoom, bool lockRobot=true) |
Sends the camera relative commands to the camera (and puts it in position mode). | |
virtual | ~ArServerHandlerCamera () |
Destructor. | |
Protected Types | |
enum | { DOUBLE_FACTOR = 100 } |
enum | CameraMode { CAMERA_MODE_POSITION, CAMERA_MODE_LOOK_AT_GOAL, CAMERA_MODE_LOOK_AT_POINT } |
Protected Member Functions | |
void | addDoubleToPacket (double val, ArNetPacket &packet) |
Adds the given value as a "double" to the given network packet. | |
void | buildModePacket (void) |
double | getCurrentZoomRatio () |
Gets the current camera zoom as a ratio of its zoom range. | |
double | getDoubleFromPacket (ArNetPacket &packet) |
Reads a "double" value from the given network packet. | |
double | getZoomRange () |
Gets the range of the camera's zoom. | |
double | getZoomRatio (double absZoom) |
Converts the given absolute zoom value to a ratio of the camera's zoom range. | |
void | userTask (void) |
Protected Attributes | |
ArPTZ * | myCamera |
Camera that is controlled. | |
ArFunctor2C< ArServerHandlerCamera, ArServerClient *, ArNetPacket * > | myCameraAbsCB |
Old (integer-style) handler for the cameraAbs packet. | |
ArFunctor2C< ArServerHandlerCamera, ArServerClient *, ArNetPacket * > | myCameraCB |
Old (integer-style) handler for the camera packet. | |
ArCameraCollection * | myCameraCollection |
Pointer to the camera collection (if any). | |
ArFunctor2C< ArServerHandlerCamera, ArServerClient *, ArNetPacket * > | myCameraInfoCB |
Old (integer-style) handler for the cameraInfo packet. | |
CameraMode | myCameraMode |
std::map< CameraMode, std::string > | myCameraModeNameMap |
ArNetPacket | myCameraModePacket |
std::string | myCameraName |
Unique name of the associated camera. | |
ArFunctor2C< ArServerHandlerCamera, ArServerClient *, ArNetPacket * > | myCameraUpdateCB |
Old (integer-style) handler for the cameraUpdate packet. | |
std::map< std::string, ArFunctor2< ArServerClient *, ArNetPacket * > * > | myCommandToCBMap |
Map of ArCameraCommand names to the callback that handles the packet. | |
std::map< std::string, int > | myCommandToIntervalMap |
Map of ArCameraCommand names to the preferred default request interval. | |
std::map< std::string, std::string > | myCommandToPacketNameMap |
Map of ArCameraCommand names to a unique network packet name. | |
ArPose | myGoal |
bool | myGoalAchieved |
bool | myGoalAchievedLast |
bool | myGoalResetZoom |
ArPose | myLookAtPoint |
ArMutex | myModeMutex |
bool | myPointResetZoom |
ArRobot * | myRobot |
Associated robot (primarily used for locking). | |
ArServerBase * | myServer |
Server from which requests are received. | |
ArFunctorC< ArServerHandlerCamera > | myUserTaskCB |
anonymous enum [protected] |
ArServerHandlerCamera::ArServerHandlerCamera | ( | const char * | cameraName, | |
ArServerBase * | server, | |||
ArRobot * | robot, | |||
ArPTZ * | camera, | |||
ArCameraCollection * | collection | |||
) |
Constructs a new handler for the specified camera.
cameraName | the unique char * name of the associated camera | |
server | the ArServerBase * used to send/receive requests | |
robot | the associated ArRobot * | |
camera | the ArPTZ * that provides access to the actual camera | |
collection | the ArCameraCollection * to which to add the camera command information; if NULL, then addToCameraCollection() must be called manually. |
ArServerHandlerCamera::ArServerHandlerCamera | ( | ArServerBase * | server, | |
ArRobot * | robot, | |||
ArPTZ * | camera | |||
) |
Constructor.
This constructor is maintained for backwards compatibility. It will not work in a multi-camera configuration.
server | the ArServerBase * used to send/receive requests | |
robot | the associated ArRobot * | |
camera | the ArPTZ * that provides access to the actual camera |
void ArServerHandlerCamera::addDoubleToPacket | ( | double | val, | |
ArNetPacket & | packet | |||
) | [inline, protected] |
Adds the given value as a "double" to the given network packet.
The "double" value is really a 2-byte integer multiplied by the DOUBLE_FACTOR.
virtual void ArServerHandlerCamera::addToCameraCollection | ( | ArCameraCollection & | collection | ) | [virtual] |
Adds the camera commands to the given collection.
collection | the ArCameraCollection to which to add the camera commands |
Implements ArCameraCollectionItem.
const char* ArServerHandlerCamera::getCameraName | ( | ) | [virtual] |
Returns the name of the camera that is controlled by this handler.
Implements ArCameraCollectionItem.
double ArServerHandlerCamera::getDoubleFromPacket | ( | ArNetPacket & | packet | ) | [inline, protected] |
Reads a "double" value from the given network packet.
The "double" value is really a 2-byte integer multiplied by the DOUBLE_FACTOR.
void ArServerHandlerCamera::handleCameraModeUpdated | ( | ArServerClient * | client, | |
ArNetPacket * | packet | |||
) |
Handle the mode request, generally this is sent when it changes.
Refer to handleSetCameraMode for a description of the supported modes and the various packet structures.
client | the ArServerClient * that sent the request | |
packet | the ArNetPacket * that contains the request |
void ArServerHandlerCamera::handleGetCameraData | ( | ArServerClient * | client, | |
ArNetPacket * | packet | |||
) |
Handles the getCameraData network packet, returning information in double format.
client | the ArServerClient * that sent the request | |
packet | the ArNetPacket * that contains the request |
void ArServerHandlerCamera::handleGetCameraInfo | ( | ArServerClient * | client, | |
ArNetPacket * | packet | |||
) |
Handles the getCameraInfo network packet, returning information in double format.
client | the ArServerClient * that sent the request | |
packet | the ArNetPacket * that contains the request |
void ArServerHandlerCamera::handleGetCameraModeList | ( | ArServerClient * | client, | |
ArNetPacket * | packet | |||
) |
Handles the mode list for the camera.
client | the ArServerClient * that sent the request | |
packet | the ArNetPacket * that contains the request |
void ArServerHandlerCamera::handleResetCamera | ( | ArServerClient * | client, | |
ArNetPacket * | packet | |||
) |
Handle the reset.
client | the ArServerClient * that sent the request | |
packet | the ArNetPacket * that contains the request |
void ArServerHandlerCamera::handleSetCameraAbs | ( | ArServerClient * | client, | |
ArNetPacket * | packet | |||
) |
Handles the setCameraAbs network packet, with information in double format.
client | the ArServerClient * that sent the request | |
packet | the ArNetPacket * that contains the request |
void ArServerHandlerCamera::handleSetCameraMode | ( | ArServerClient * | client, | |
ArNetPacket * | packet | |||
) |
Handle the set mode request.
The following modes are currently supported:
client | the ArServerClient * that sent the request | |
packet | the ArNetPacket * that contains the request |
void ArServerHandlerCamera::handleSetCameraPct | ( | ArServerClient * | client, | |
ArNetPacket * | packet | |||
) |
Handles the setCameraPct network packet, with information in double format.
client | the ArServerClient * that sent the request | |
packet | the ArNetPacket * that contains the request |
void ArServerHandlerCamera::handleSetCameraRel | ( | ArServerClient * | client, | |
ArNetPacket * | packet | |||
) |
Handles the setCameraRel network packet, with information in double format.
client | the ArServerClient * that sent the request | |
packet | the ArNetPacket * that contains the request |
ArFunctor2C<ArServerHandlerCamera, ArServerClient *, ArNetPacket *> ArServerHandlerCamera::myCameraCB [protected] |