ArServerHandlerCamera Class Reference

#include <ArServerHandlerCamera.h>

Inheritance diagram for ArServerHandlerCamera:

ArCameraCollectionItem List of all members.

Detailed Description

Accepts and processes camera pan/tilt/zoom requests from the client, and provides information about the camera (such as its current position).

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:

  • getCameraModeList<CameraName>: Gets the list of modes that this camera supports
  • getCameraModeUpdated<CameraName>: Sent when the mode is changed
  • setCameraMode<CameraName>: Command to change the camera mode (give mode name)

Examples:

serverDemo.cpp.


Public Member Functions

virtual void addToCameraCollection (ArCameraCollection &collection)
 ArServerHandlerCamera (ArServerBase *server, ArRobot *robot, ArPTZ *camera)
 This constructor is maintained for backwards compatibility.
 ArServerHandlerCamera (const char *cameraName, ArServerBase *server, ArRobot *robot, ArPTZ *camera, ArCameraCollection *collection)
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 ()
void handleCameraModeUpdated (ArServerClient *client, ArNetPacket *packet)
 Refer to handleSetCameraMode for a description of the supported modes and the various packet structures.
void handleGetCameraData (ArServerClient *client, ArNetPacket *packet)
void handleGetCameraInfo (ArServerClient *client, ArNetPacket *packet)
void handleGetCameraModeList (ArServerClient *client, ArNetPacket *packet)
void handleResetCamera (ArServerClient *client, ArNetPacket *packet)
void handleSetCameraAbs (ArServerClient *client, ArNetPacket *packet)
void handleSetCameraMode (ArServerClient *client, ArNetPacket *packet)
 The following modes are currently supported:
  • Position: The user controls the camera position; no additional parameters in the packet
  • LookAtGoal: The robot automatically points the camera in the direction of its destination goal; no additional parameters in the packet
  • LookAtPoint: The robot "looks" at a specified point in the map; the packet contains: byte4, the x coordinate; byte4, the y coordinate.

void handleSetCameraPct (ArServerClient *client, ArNetPacket *packet)
void handleSetCameraRel (ArServerClient *client, ArNetPacket *packet)
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 }
 CAMERA_MODE_LOOK_AT_GOAL
 CAMERA_MODE_LOOK_AT_POINT
 CAMERA_MODE_POSITION
enum  CameraMode { CAMERA_MODE_POSITION, CAMERA_MODE_LOOK_AT_GOAL, CAMERA_MODE_LOOK_AT_POINT }
 DOUBLE_FACTOR = 100
 Multiplier for putting/getting "double" values to/from a packet.

Protected Member Functions

void addDoubleToPacket (double val, ArNetPacket &packet)
 The "double" value is really a 2-byte integer multiplied by the DOUBLE_FACTOR.
void buildModePacket (void)
double getCurrentZoomRatio ()
 Gets the current camera zoom as a ratio of its zoom range.
double getDoubleFromPacket (ArNetPacket &packet)
 The "double" value is really a 2-byte integer multiplied by the DOUBLE_FACTOR.
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

ArPTZmyCamera
 Camera that is controlled.
ArFunctor2C< ArServerHandlerCamera,
ArServerClient *, ArNetPacket * > 
myCameraAbsCB
ArFunctor2C< ArServerHandlerCamera,
ArServerClient *, ArNetPacket * > 
myCameraCB
ArCameraCollectionmyCameraCollection
 Pointer to the camera collection (if any).
ArFunctor2C< ArServerHandlerCamera,
ArServerClient *, ArNetPacket * > 
myCameraInfoCB
CameraMode myCameraMode
std::map< CameraMode, std::string > myCameraModeNameMap
ArNetPacket myCameraModePacket
std::string myCameraName
 Unique name of the associated camera.
ArFunctor2C< ArServerHandlerCamera,
ArServerClient *, ArNetPacket * > 
myCameraUpdateCB
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
ArRobotmyRobot
 Associated robot (primarily used for locking).
ArServerBasemyServer
 Server from which requests are received.
ArFunctorC< ArServerHandlerCameramyUserTaskCB


Member Enumeration Documentation

anonymous enum [protected]

Enumerator:
DOUBLE_FACTOR  Multiplier for putting/getting "double" values to/from a packet.

enum ArServerHandlerCamera::CameraMode [protected]

Enumerator:
CAMERA_MODE_POSITION 
CAMERA_MODE_LOOK_AT_GOAL 
CAMERA_MODE_LOOK_AT_POINT 


Constructor & Destructor Documentation

ArServerHandlerCamera::ArServerHandlerCamera ( const char *  cameraName,
ArServerBase server,
ArRobot robot,
ArPTZ camera,
ArCameraCollection collection 
)

Parameters:
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 
)

This constructor is maintained for backwards compatibility.

It will not work in a multi-camera configuration.

Deprecated:
Parameters:
server the ArServerBase * used to send/receive requests
robot the associated ArRobot *
camera the ArPTZ * that provides access to the actual camera

ArServerHandlerCamera::~ArServerHandlerCamera (  )  [virtual]

Destructor.


Member Function Documentation

void ArServerHandlerCamera::addDoubleToPacket ( double  val,
ArNetPacket packet 
) [inline, protected]

The "double" value is really a 2-byte integer multiplied by the DOUBLE_FACTOR.

void ArServerHandlerCamera::addToCameraCollection ( ArCameraCollection collection  )  [virtual]

Parameters:
collection the ArCameraCollection to which to add the camera commands

Implements ArCameraCollectionItem.

void ArServerHandlerCamera::buildModePacket ( void   )  [protected]

void ArServerHandlerCamera::camera ( ArServerClient client,
ArNetPacket packet 
)

Handles the camera network packet, with information stored as byte integers.

void ArServerHandlerCamera::cameraAbs ( ArServerClient client,
ArNetPacket packet 
)

Handles the cameraAbs network packet, with information stored as byte integers.

void ArServerHandlerCamera::cameraInfo ( ArServerClient client,
ArNetPacket packet 
)

Handles the cameraInfo network packet, with information returned as byte2 integers.

void ArServerHandlerCamera::cameraModeLookAtGoal ( void   ) 

Puts the camera into a mode where it will look at the goal.

void ArServerHandlerCamera::cameraModeLookAtGoalClearGoal ( void   ) 

Clears the goal for the camera mode that points at the goal.

void ArServerHandlerCamera::cameraModeLookAtGoalSetGoal ( ArPose  pose  ) 

Sets the goal for the camera mode that points at the goal.

void ArServerHandlerCamera::cameraModeLookAtPoint ( ArPose  pose,
bool  controlZoom = true 
)

Puts the camera into a mode where it will look at a point.

void ArServerHandlerCamera::cameraModePosition ( void   ) 

Puts the camera in position mode.

void ArServerHandlerCamera::cameraPct ( ArServerClient client,
ArNetPacket packet 
)

Handles the cameraPct network packet, with information stored as byte integers.

void ArServerHandlerCamera::cameraUpdate ( ArServerClient client,
ArNetPacket packet 
)

Handles the cameraUpdate network packet, with information returned as byte2 integers.

const char * ArServerHandlerCamera::getCameraName (  )  [virtual]

Returns:
char * the unique name of the associated camera (if specified in the constructor)

Implements ArCameraCollectionItem.

double ArServerHandlerCamera::getCurrentZoomRatio (  )  [inline, protected]

Gets the current camera zoom as a ratio of its zoom range.

double ArServerHandlerCamera::getDoubleFromPacket ( ArNetPacket packet  )  [inline, protected]

The "double" value is really a 2-byte integer multiplied by the DOUBLE_FACTOR.

double ArServerHandlerCamera::getZoomRange (  )  [inline, protected]

Gets the range of the camera's zoom.

double ArServerHandlerCamera::getZoomRatio ( double  absZoom  )  [inline, protected]

Converts the given absolute zoom value to a ratio of the camera's zoom range.

void ArServerHandlerCamera::handleCameraModeUpdated ( ArServerClient client,
ArNetPacket packet 
)

Refer to handleSetCameraMode for a description of the supported modes and the various packet structures.

Parameters:
client the ArServerClient * that sent the request
packet the ArNetPacket * that contains the request

void ArServerHandlerCamera::handleGetCameraData ( ArServerClient client,
ArNetPacket packet 
)

Parameters:
client the ArServerClient * that sent the request
packet the ArNetPacket * that contains the request

void ArServerHandlerCamera::handleGetCameraInfo ( ArServerClient client,
ArNetPacket packet 
)

Parameters:
client the ArServerClient * that sent the request
packet the ArNetPacket * that contains the request

void ArServerHandlerCamera::handleGetCameraModeList ( ArServerClient client,
ArNetPacket packet 
)

Parameters:
client the ArServerClient * that sent the request
packet the ArNetPacket * that contains the request

void ArServerHandlerCamera::handleResetCamera ( ArServerClient client,
ArNetPacket packet 
)

Parameters:
client the ArServerClient * that sent the request
packet the ArNetPacket * that contains the request

void ArServerHandlerCamera::handleSetCameraAbs ( ArServerClient client,
ArNetPacket packet 
)

Parameters:
client the ArServerClient * that sent the request
packet the ArNetPacket * that contains the request

void ArServerHandlerCamera::handleSetCameraMode ( ArServerClient client,
ArNetPacket packet 
)

The following modes are currently supported:

Parameters:
client the ArServerClient * that sent the request
packet the ArNetPacket * that contains the request

void ArServerHandlerCamera::handleSetCameraPct ( ArServerClient client,
ArNetPacket packet 
)

Parameters:
client the ArServerClient * that sent the request
packet the ArNetPacket * that contains the request

void ArServerHandlerCamera::handleSetCameraRel ( ArServerClient client,
ArNetPacket packet 
)

Parameters:
client the ArServerClient * that sent the request
packet the ArNetPacket * that contains the request

void ArServerHandlerCamera::resetCamera ( bool  lockRobot = true  ) 

Resets the camera.

void ArServerHandlerCamera::setCameraAbs ( double  pan,
double  tilt,
double  zoom,
bool  lockRobot = true 
)

Sends the camera absolute commands to the camera (and puts it in position mode).

Parameters:
pan the degrees to pan to (absolute)
tilt the degrees to tilt to (absolute)
zoom the percent (number between 0 and 100) to pan to (absolute)
lockRobot whether to lock the robot or not

void ArServerHandlerCamera::setCameraPct ( double  panPct,
double  tiltPct,
bool  lockRobot = true 
)

Sends the camera percent commands to the camera (and puts it in position mode).

Parameters:
panPct the double percent offset from the image frame center by which to pan the camera; values range -100 to 100. 0 indicates no change.
tiltPct the double percent offset from the image frame center by which to tilt the camera; values range -100 to 100. 0 indicates no change.
lockRobot whether to lock the robot or not

Figure how much the x/y/z components of the left/right vector, this part is pretty straightforward since its just multiplying the left/right vector by the cos or sin to get the component in that direction (which is based on the pan)

     ------------------   y 
     |\)lr |
     | \   | sin lr
     |  \  | 
     |   \ |
     |    \|
     x
     

That derives the sin lr for the length of the vector... for how much of that is in which direction

         dx = sin lr * sin pan
     ------------------------- y
     |\)pan  |
     | \     |
     |  \slr |  dy = sin lr * cos pan
     |   \   |
     |    \  |
     |     \ |
     |      \|
     x
     

Where slr is the sin lr derived above and pan is the pan angle (since we're doing vectors the position we calculate these components from doesn't matter so we just move it back to 0 to make life easier)...

The - on the sin is needed, I think its because the camera pans positive to the right and negative to the left instead of positive to the right.

Figure how much the x/y/z components of the up/down vector,

So for x and y first we find how much is in the x/y plane (sin(ud) * sin(oldTilt)) and then we multiply that by the same sin or cos of the pan to see how much is in which coord...

For z we just multiply the up/down vector by the cos to find what the movement in z is.

Now add the original vector, the vector from left/right and the vector from up/down together.

Now find where we have to pan and tilt to...

| , | /|z | / | |/t |y -)--|------- / \)p| / / h\ | / x / \|/

Where x, y, and z are the values we found above and tilt and pan are the tilt (angle of the line off of the x/y plane) and pan values (angle of the line within the x/y plain) we need to point at that point, h is the hypotenuse of the line projected into the x/y plane.

tan pan = x / y ! pan = atan (x / y)

cos pan = y / hyp hyp = y / cos pan

sin pan = x / hyp hyp = x / sin pan

tan tilt = z / hyp

! tilt = atan (z / hyp) (substitute in one of the hyps)

Pan is easy since its just the atan of x and y.

This denom can be either y/cos(pan) or x / sin(pan) depending on which solution you use and we use them in a way that won't get us a divide by 0.

void ArServerHandlerCamera::setCameraRel ( double  pan,
double  tilt,
double  zoom,
bool  lockRobot = true 
)

Sends the camera relative commands to the camera (and puts it in position mode).

Parameters:
pan the degrees to pan to (relative)
tilt the degrees to tilt to (relative)
zoom the percent (number between 0 and 100) to change pan by (relative)
lockRobot whether to lock the robot or not

void ArServerHandlerCamera::userTask ( void   )  [protected]


Member Data Documentation

ArPTZ* ArServerHandlerCamera::myCamera [protected]

Camera that is controlled.

ArFunctor2C<ArServerHandlerCamera, ArServerClient *, ArNetPacket *> ArServerHandlerCamera::myCameraAbsCB [protected]

Deprecated:

ArFunctor2C<ArServerHandlerCamera, ArServerClient *, ArNetPacket *> ArServerHandlerCamera::myCameraCB [protected]

Deprecated:

ArCameraCollection* ArServerHandlerCamera::myCameraCollection [protected]

Pointer to the camera collection (if any).

ArFunctor2C<ArServerHandlerCamera, ArServerClient *, ArNetPacket *> ArServerHandlerCamera::myCameraInfoCB [protected]

Deprecated:

CameraMode ArServerHandlerCamera::myCameraMode [protected]

std::map<CameraMode, std::string> ArServerHandlerCamera::myCameraModeNameMap [protected]

ArNetPacket ArServerHandlerCamera::myCameraModePacket [protected]

std::string ArServerHandlerCamera::myCameraName [protected]

Unique name of the associated camera.

ArFunctor2C<ArServerHandlerCamera, ArServerClient *, ArNetPacket *> ArServerHandlerCamera::myCameraUpdateCB [protected]

Deprecated:

std::map<std::string, ArFunctor2<ArServerClient *, ArNetPacket *> *> ArServerHandlerCamera::myCommandToCBMap [protected]

Map of ArCameraCommand names to the callback that handles the packet.

std::map<std::string, int> ArServerHandlerCamera::myCommandToIntervalMap [protected]

Map of ArCameraCommand names to the preferred default request interval.

std::map<std::string, std::string> ArServerHandlerCamera::myCommandToPacketNameMap [protected]

Map of ArCameraCommand names to a unique network packet name.

ArPose ArServerHandlerCamera::myGoal [protected]

bool ArServerHandlerCamera::myGoalAchieved [protected]

bool ArServerHandlerCamera::myGoalAchievedLast [protected]

bool ArServerHandlerCamera::myGoalResetZoom [protected]

ArPose ArServerHandlerCamera::myLookAtPoint [protected]

ArMutex ArServerHandlerCamera::myModeMutex [protected]

bool ArServerHandlerCamera::myPointResetZoom [protected]

ArRobot* ArServerHandlerCamera::myRobot [protected]

Associated robot (primarily used for locking).

ArServerBase* ArServerHandlerCamera::myServer [protected]

Server from which requests are received.

ArFunctorC<ArServerHandlerCamera> ArServerHandlerCamera::myUserTaskCB [protected]


The documentation for this class was generated from the following files:
Generated on Fri Jul 31 12:37:29 2009 for ArNetworking by  doxygen 1.4.7