#include <ArServerHandlerCamera.h>
Inheritance diagram for ArServerHandlerCamera:
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) |
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 } |
enum | CameraMode { CAMERA_MODE_POSITION, CAMERA_MODE_LOOK_AT_GOAL, CAMERA_MODE_LOOK_AT_POINT } |
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 | |
ArPTZ * | myCamera |
Camera that is controlled. | |
ArFunctor2C< ArServerHandlerCamera, ArServerClient *, ArNetPacket * > | myCameraAbsCB |
ArFunctor2C< ArServerHandlerCamera, ArServerClient *, ArNetPacket * > | myCameraCB |
ArCameraCollection * | myCameraCollection |
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 |
ArRobot * | myRobot |
Associated robot (primarily used for locking). | |
ArServerBase * | myServer |
Server from which requests are received. | |
ArFunctorC< ArServerHandlerCamera > | myUserTaskCB |
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.
In addition, some older camera commands are accepted for partial backwards compatability with old clients: cameraUpdate, cameraInfo, cameraAbs, camera, and cameraPct. (However, these commands cannot be used in a multi-camera configuration.)
These requests are in a user permission group called CameraControl.
Definition at line 75 of file ArServerHandlerCamera.h.
|
Definition at line 268 of file ArServerHandlerCamera.h. |
|
Definition at line 379 of file ArServerHandlerCamera.h. |
|
Definition at line 70 of file ArServerHandlerCamera.cpp. |
|
This constructor is maintained for backwards compatibility. It will not work in a multi-camera configuration.
Definition at line 47 of file ArServerHandlerCamera.cpp. |
|
Destructor.
Definition at line 109 of file ArServerHandlerCamera.cpp. References myCommandToCBMap. |
|
The "double" value is really a 2-byte integer multiplied by the DOUBLE_FACTOR.
Definition at line 276 of file ArServerHandlerCamera.h. References DOUBLE_FACTOR. Referenced by handleGetCameraData(), and handleGetCameraInfo(). |
|
Implements ArCameraCollectionItem. Definition at line 509 of file ArServerHandlerCamera.cpp. |
|
Definition at line 1221 of file ArServerHandlerCamera.cpp. References ArBasePacket::byte4ToBuf(), CAMERA_MODE_LOOK_AT_POINT, ArNetPacket::empty(), ArPose::getX(), ArPose::getY(), myCameraMode, myCameraModeNameMap, myCameraModePacket, myLookAtPoint, and ArBasePacket::strToBuf(). Referenced by cameraModeLookAtGoal(), cameraModeLookAtPoint(), and cameraModePosition(). |
|
Handles the camera network packet, with information stored as byte integers.
Definition at line 642 of file ArServerHandlerCamera.cpp. References setCameraRel(). |
|
Handles the cameraAbs network packet, with information stored as byte integers.
Definition at line 657 of file ArServerHandlerCamera.cpp. References setCameraAbs(). |
|
Handles the cameraInfo network packet, with information returned as byte2 integers.
Definition at line 708 of file ArServerHandlerCamera.cpp. References ArBasePacket::byte2ToBuf(), ArBasePacket::byteToBuf(), ArPTZ::canZoom(), client, ArPTZ::getMaxNegPan(), ArPTZ::getMaxNegTilt(), ArPTZ::getMaxPosPan(), ArPTZ::getMaxPosTilt(), ArRobot::lock(), myCamera, myRobot, ArMath::roundInt(), ArClientBase::sendPacketUdp(), and ArRobot::unlock(). |
|
Puts the camera into a mode where it will look at the goal.
Definition at line 1252 of file ArServerHandlerCamera.cpp. References ArServerBase::broadcastPacketTcp(), buildModePacket(), CAMERA_MODE_LOOK_AT_GOAL, ArMutex::lock(), ArLog::log(), myCameraMode, myCameraModePacket, myCommandToPacketNameMap, myGoalAchieved, myGoalAchievedLast, myGoalResetZoom, myModeMutex, myServer, and ArMutex::unlock(). Referenced by handleSetCameraMode(). |
|
Clears the goal for the camera mode that points at the goal.
Definition at line 1302 of file ArServerHandlerCamera.cpp. References ArMutex::lock(), myGoalAchieved, myModeMutex, and ArMutex::unlock(). |
|
Sets the goal for the camera mode that points at the goal.
Definition at line 1292 of file ArServerHandlerCamera.cpp. References ArMutex::lock(), myGoal, myGoalAchieved, myGoalAchievedLast, myGoalResetZoom, myModeMutex, and ArMutex::unlock(). |
|
Puts the camera into a mode where it will look at a point.
Definition at line 1271 of file ArServerHandlerCamera.cpp. References ArServerBase::broadcastPacketTcp(), buildModePacket(), CAMERA_MODE_LOOK_AT_POINT, ArPose::findDistanceTo(), ArPose::getX(), ArPose::getY(), ArMutex::lock(), ArLog::log(), myCameraMode, myCameraModePacket, myCommandToPacketNameMap, myLookAtPoint, myModeMutex, myPointResetZoom, myServer, and ArMutex::unlock(). Referenced by handleSetCameraMode(). |
|
Puts the camera in position mode.
Definition at line 1235 of file ArServerHandlerCamera.cpp. References ArServerBase::broadcastPacketTcp(), buildModePacket(), CAMERA_MODE_POSITION, ArMutex::lock(), ArLog::log(), myCameraMode, myCameraModePacket, myCommandToPacketNameMap, myModeMutex, myServer, and ArMutex::unlock(). Referenced by handleSetCameraMode(), resetCamera(), setCameraAbs(), setCameraPct(), and setCameraRel(). |
|
Handles the cameraPct network packet, with information stored as byte integers.
Definition at line 670 of file ArServerHandlerCamera.cpp. References ArPTZ::canGetFOV(), ArLog::log(), myCamera, and setCameraPct(). |
|
Handles the cameraUpdate network packet, with information returned as byte2 integers.
Definition at line 688 of file ArServerHandlerCamera.cpp. References ArBasePacket::byte2ToBuf(), client, ArPTZ::getMaxZoom(), ArPTZ::getMinZoom(), ArPTZ::getPan(), ArPTZ::getTilt(), ArPTZ::getZoom(), ArRobot::lock(), myCamera, myRobot, ArMath::roundInt(), ArClientBase::sendPacketUdp(), and ArRobot::unlock(). |
|
Implements ArCameraCollectionItem. Definition at line 150 of file ArServerHandlerCamera.cpp. References myCameraName. |
|
Gets the current camera zoom as a ratio of its zoom range.
Definition at line 295 of file ArServerHandlerCamera.h. References ArPTZ::getMaxZoom(), ArPTZ::getMinZoom(), ArPTZ::getZoom(), and myCamera. Referenced by handleGetCameraData(), setCameraPct(), and setCameraRel(). |
|
The "double" value is really a 2-byte integer multiplied by the DOUBLE_FACTOR.
Definition at line 288 of file ArServerHandlerCamera.h. References DOUBLE_FACTOR. Referenced by handleSetCameraAbs(), handleSetCameraPct(), and handleSetCameraRel(). |
|
Gets the range of the camera's zoom.
Definition at line 323 of file ArServerHandlerCamera.h. References ArPTZ::getMaxZoom(), ArPTZ::getMinZoom(), and myCamera. Referenced by setCameraAbs(), and setCameraRel(). |
|
Converts the given absolute zoom value to a ratio of the camera's zoom range.
Definition at line 309 of file ArServerHandlerCamera.h. References ArPTZ::getMaxZoom(), ArPTZ::getMinZoom(), and myCamera. |
|
Refer to handleSetCameraMode for a description of the supported modes and the various packet structures.
Definition at line 1143 of file ArServerHandlerCamera.cpp. References client, ArMutex::lock(), myCameraModePacket, myModeMutex, ArClientBase::sendPacketTcp(), and ArMutex::unlock(). |
|
Definition at line 518 of file ArServerHandlerCamera.cpp. References addDoubleToPacket(), client, getCurrentZoomRatio(), ArPTZ::getPan(), ArPTZ::getTilt(), ArRobot::lock(), myCamera, myRobot, ArClientBase::sendPacketUdp(), and ArRobot::unlock(). |
|
Definition at line 543 of file ArServerHandlerCamera.cpp. References addDoubleToPacket(), ArBasePacket::byteToBuf(), ArPTZ::canZoom(), client, ArPTZ::getMaxNegPan(), ArPTZ::getMaxNegTilt(), ArPTZ::getMaxPosPan(), ArPTZ::getMaxPosTilt(), ArRobot::lock(), ArLog::log(), myCamera, myRobot, ArClientBase::sendPacketUdp(), and ArRobot::unlock(). |
|
Definition at line 1126 of file ArServerHandlerCamera.cpp. References client, ArMutex::lock(), myCameraModeNameMap, myModeMutex, ArClientBase::sendPacketTcp(), ArBasePacket::strToBuf(), ArBasePacket::uByte2ToBuf(), and ArMutex::unlock(). |
|
Definition at line 1309 of file ArServerHandlerCamera.cpp. References resetCamera(). |
|
Definition at line 582 of file ArServerHandlerCamera.cpp. References getDoubleFromPacket(), myCamera, myRobot, and setCameraAbs(). |
|
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.
Definition at line 1151 of file ArServerHandlerCamera.cpp. References CAMERA_MODE_LOOK_AT_GOAL, CAMERA_MODE_LOOK_AT_POINT, CAMERA_MODE_POSITION, cameraModeLookAtGoal(), cameraModeLookAtPoint(), cameraModePosition(), ArLog::log(), myCameraModeNameMap, myCameraName, ArPose::setX(), and ArPose::setY(). |
|
Definition at line 616 of file ArServerHandlerCamera.cpp. References ArPTZ::canGetFOV(), getDoubleFromPacket(), ArLog::log(), myCamera, and setCameraPct(). |
|
Definition at line 598 of file ArServerHandlerCamera.cpp. References getDoubleFromPacket(), and setCameraRel(). |
|
Resets the camera.
Definition at line 1315 of file ArServerHandlerCamera.cpp. References cameraModePosition(), ArRobot::lock(), myCamera, myRobot, ArPTZ::reset(), and ArRobot::unlock(). Referenced by handleResetCamera(). |
|
Sends the camera absolute commands to the camera (and puts it in position mode).
Definition at line 746 of file ArServerHandlerCamera.cpp. References cameraModePosition(), ArPTZ::getMinZoom(), getZoomRange(), IFDEBUG, ArRobot::lock(), myCamera, myRobot, ArPTZ::panTilt(), ArRobot::unlock(), and ArPTZ::zoom(). Referenced by cameraAbs(), and handleSetCameraAbs(). |
|
Sends the camera percent commands to the camera (and puts it in position mode).
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 | | \ | | | 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. Definition at line 878 of file ArServerHandlerCamera.cpp. References ArMath::atan2(), cameraModePosition(), ArMath::cos(), getCurrentZoomRatio(), ArPTZ::getFOVAtMaxZoom(), ArPTZ::getFOVAtMinZoom(), ArPTZ::getPan(), ArPTZ::getTilt(), IFDEBUG, ArRobot::lock(), myCamera, myRobot, ArPTZ::panTilt(), ArMath::sin(), ArMath::tan(), and ArRobot::unlock(). Referenced by cameraPct(), and handleSetCameraPct(). |
|
Sends the camera relative commands to the camera (and puts it in position mode).
Definition at line 782 of file ArServerHandlerCamera.cpp. References cameraModePosition(), getCurrentZoomRatio(), ArPTZ::getMaxZoom(), ArPTZ::getMinZoom(), getZoomRange(), IFDEBUG, ArRobot::lock(), myCamera, myRobot, ArPTZ::panRel(), ArPTZ::panTiltRel(), ArPTZ::tiltRel(), ArRobot::unlock(), and ArPTZ::zoom(). Referenced by camera(), and handleSetCameraRel(). |
|
Definition at line 1190 of file ArServerHandlerCamera.cpp. References CAMERA_MODE_LOOK_AT_GOAL, CAMERA_MODE_LOOK_AT_POINT, ArRobot::findDeltaHeadingTo(), ArMutex::lock(), myCamera, myCameraMode, myGoal, myGoalAchieved, myGoalAchievedLast, myGoalResetZoom, myLookAtPoint, myModeMutex, myPointResetZoom, myRobot, ArPTZ::panTilt(), ArMutex::unlock(), and ArPTZ::zoom(). |
|
Camera that is controlled.
Definition at line 364 of file ArServerHandlerCamera.h. Referenced by cameraInfo(), cameraPct(), cameraUpdate(), getCurrentZoomRatio(), getZoomRange(), getZoomRatio(), handleGetCameraData(), handleGetCameraInfo(), handleSetCameraAbs(), handleSetCameraPct(), resetCamera(), setCameraAbs(), setCameraPct(), setCameraRel(), and userTask(). |
|
Definition at line 416 of file ArServerHandlerCamera.h. |
|
Definition at line 410 of file ArServerHandlerCamera.h. |
|
Pointer to the camera collection (if any).
Definition at line 369 of file ArServerHandlerCamera.h. |
|
Definition at line 428 of file ArServerHandlerCamera.h. |
|
Definition at line 387 of file ArServerHandlerCamera.h. Referenced by buildModePacket(), cameraModeLookAtGoal(), cameraModeLookAtPoint(), cameraModePosition(), and userTask(). |
|
Definition at line 388 of file ArServerHandlerCamera.h. Referenced by buildModePacket(), handleGetCameraModeList(), and handleSetCameraMode(). |
|
Definition at line 389 of file ArServerHandlerCamera.h. Referenced by buildModePacket(), cameraModeLookAtGoal(), cameraModeLookAtPoint(), cameraModePosition(), and handleCameraModeUpdated(). |
|
Unique name of the associated camera.
Definition at line 367 of file ArServerHandlerCamera.h. Referenced by getCameraName(), and handleSetCameraMode(). |
|
Definition at line 422 of file ArServerHandlerCamera.h. |
|
Map of ArCameraCommand names to the callback that handles the packet.
Definition at line 377 of file ArServerHandlerCamera.h. Referenced by ~ArServerHandlerCamera(). |
|
Map of ArCameraCommand names to the preferred default request interval.
Definition at line 374 of file ArServerHandlerCamera.h. |
|
Map of ArCameraCommand names to a unique network packet name.
Definition at line 372 of file ArServerHandlerCamera.h. Referenced by cameraModeLookAtGoal(), cameraModeLookAtPoint(), and cameraModePosition(). |
|
Definition at line 392 of file ArServerHandlerCamera.h. Referenced by cameraModeLookAtGoalSetGoal(), and userTask(). |
|
Definition at line 393 of file ArServerHandlerCamera.h. Referenced by cameraModeLookAtGoal(), cameraModeLookAtGoalClearGoal(), cameraModeLookAtGoalSetGoal(), and userTask(). |
|
Definition at line 394 of file ArServerHandlerCamera.h. Referenced by cameraModeLookAtGoal(), cameraModeLookAtGoalSetGoal(), and userTask(). |
|
Definition at line 395 of file ArServerHandlerCamera.h. Referenced by cameraModeLookAtGoal(), cameraModeLookAtGoalSetGoal(), and userTask(). |
|
Definition at line 390 of file ArServerHandlerCamera.h. Referenced by buildModePacket(), cameraModeLookAtPoint(), and userTask(). |
|
Definition at line 386 of file ArServerHandlerCamera.h. Referenced by cameraModeLookAtGoal(), cameraModeLookAtGoalClearGoal(), cameraModeLookAtGoalSetGoal(), cameraModeLookAtPoint(), cameraModePosition(), handleCameraModeUpdated(), handleGetCameraModeList(), and userTask(). |
|
Definition at line 391 of file ArServerHandlerCamera.h. Referenced by cameraModeLookAtPoint(), and userTask(). |
|
Associated robot (primarily used for locking).
Definition at line 360 of file ArServerHandlerCamera.h. Referenced by cameraInfo(), cameraUpdate(), handleGetCameraData(), handleGetCameraInfo(), handleSetCameraAbs(), resetCamera(), setCameraAbs(), setCameraPct(), setCameraRel(), and userTask(). |
|
Server from which requests are received.
Definition at line 362 of file ArServerHandlerCamera.h. Referenced by cameraModeLookAtGoal(), cameraModeLookAtPoint(), and cameraModePosition(). |
|
Definition at line 401 of file ArServerHandlerCamera.h. |