diff --git a/lib/App/common/deviceNodeCamera.cpp b/lib/App/common/deviceNodeCamera.cpp index bf6c4bb4..028792af 100644 --- a/lib/App/common/deviceNodeCamera.cpp +++ b/lib/App/common/deviceNodeCamera.cpp @@ -1930,10 +1930,14 @@ void deviceNodeCamera::m_fThreadProc(void) m_fCP_Zoom = m_pCurrentROI->cam_orientation.zoom; // Do Movement { - char tB[CTEXT * 2]; - snprintf(tB, sizeof(tB), "Go to ROI (%u targets): pan=%0.6f tilt=%0.6f zoom=%0.6f (x zoom correction %0.4f = %0.6f)", (unsigned) m_pCurrentROI->targets.size(), - m_pCurrentROI->cam_orientation.pan, m_pCurrentROI->cam_orientation.tilt, m_pCurrentROI->cam_orientation.zoom, m_fZoomCorrection, - m_pCurrentROI->cam_orientation.zoom * m_fZoomCorrection); + char tB[CTEXT * 3]; + snprintf(tB, sizeof(tB), + "Go to ROI (%u targets): pan=%0.6f tilt=%0.6f zoom=%0.6f (x zoom correction %0.4f = %0.6f); target fi=%0.2f tetta=%0.2f r=%0.1f; " + "camera pan model %u / %u deg, tilt model %u / %u deg", + (unsigned) m_pCurrentROI->targets.size(), m_pCurrentROI->cam_orientation.pan, m_pCurrentROI->cam_orientation.tilt, + m_pCurrentROI->cam_orientation.zoom, m_fZoomCorrection, m_pCurrentROI->cam_orientation.zoom * m_fZoomCorrection, + m_pCurrentROI->cam_position.fi, m_pCurrentROI->cam_position.tetta, m_pCurrentROI->cam_position.r, (unsigned) m_sCamData.pan_model, + (unsigned) m_sCamData.pan_angles, (unsigned) m_sCamData.tilt_model, (unsigned) m_sCamData.tilt_angles); LOG(tB); } if (! m_pProtocol->goAbsolute(m_pCurrentROI->cam_orientation.pan, m_pCurrentROI->cam_orientation.tilt, m_pCurrentROI->cam_orientation.zoom * m_fZoomCorrection)) diff --git a/lib/alg/generic/Transform.cpp b/lib/alg/generic/Transform.cpp index 233de3b6..16398754 100644 --- a/lib/alg/generic/Transform.cpp +++ b/lib/alg/generic/Transform.cpp @@ -141,6 +141,16 @@ void spherical2onvif(C3D_SPH_DEGREES in, C3D_ORIENT_ONVIF & out, float maxR, uin out.zoom = .0f; } + // Endless pan: the azimuth may come as -180..180 or above 360, bring it into 0..360 + if (panAngles >= 360.0f) + { + in.fi = fmodf(in.fi, 360.0f); + if (in.fi < 0.0f) + { + in.fi += 360.0f; + }; + }; + switch (panMode) { case 1: @@ -174,6 +184,13 @@ void spherical2onvif(C3D_SPH_DEGREES in, C3D_ORIENT_ONVIF & out, float maxR, uin break; }; }; + // A target is accepted up to half a field of view outside the mechanical range (isInRange), and a camera + // that can tilt 90 degrees accepts any elevation: the camera must then go to its end position, where the + // target is still in the picture. A value outside -1..1 (generic ONVIF space) is rejected by the camera + // with ter:InvalidPosition ("The requested destination is out of bounds"). + out.pan = (out.pan < -1.0f) ? -1.0f : ((out.pan > 1.0f) ? 1.0f : out.pan); + out.tilt = (out.tilt < -1.0f) ? -1.0f : ((out.tilt > 1.0f) ? 1.0f : out.tilt); + out.zoom = (out.zoom < 0.0f) ? 0.0f : ((out.zoom > 1.0f) ? 1.0f : out.zoom); } void spherical2onvif(C3D_SPH_RADIANS inr, C3D_ORIENT_ONVIF & out, float maxR, uint8_t panMode, float panAngles, uint8_t tiltMode, float tiltAngles) diff --git a/lib/data/ponvif/ponvif.cpp b/lib/data/ponvif/ponvif.cpp index ed6b3e91..6dca68e1 100644 --- a/lib/data/ponvif/ponvif.cpp +++ b/lib/data/ponvif/ponvif.cpp @@ -2338,19 +2338,29 @@ bool pOnvif::ptz_AbsoluteMove(CSTR profileToken, float position_pantilt_x, float { tLen += snprintf(tOut + tLen, sizeof(tOut) - tLen, " ZOOM"); }; - char tMove[CTEXT * 2]; - snprintf(tMove, sizeof(tMove), "AbsoluteMove pan=%0.6f tilt=%0.6f zoom=%0.6f (speed pt=%0.4f zoom=%0.4f)", position_pantilt_x, position_pantilt_y, zoom, tPT, tZM); if (tOut[0] != 0) { - char tB[CTEXT * 4]; - snprintf(tB, sizeof(tB), "%s: OUT OF CAMERA LIMITS:%s", tMove, tOut); + char tB[CTEXT * 2]; + snprintf(tB, sizeof(tB), "AbsoluteMove pan=%0.6f tilt=%0.6f zoom=%0.6f: OUT OF CAMERA LIMITS:%s - clamped to the limits", position_pantilt_x, position_pantilt_y, + zoom, tOut); LOG_ERROR(tB); - } -#ifdef DEBUG_PONVIF_PTZ - else - { - LOG(tMove); + if (tPTR.valid) + { + position_pantilt_x = (position_pantilt_x < tPTR.xmin) ? tPTR.xmin : ((position_pantilt_x > tPTR.xmax) ? tPTR.xmax : position_pantilt_x); + if (tPTR.hasY) + { + position_pantilt_y = (position_pantilt_y < tPTR.ymin) ? tPTR.ymin : ((position_pantilt_y > tPTR.ymax) ? tPTR.ymax : position_pantilt_y); + }; + }; + if (tZR.valid) + { + zoom = (zoom < tZR.xmin) ? tZR.xmin : ((zoom > tZR.xmax) ? tZR.xmax : zoom); + }; }; + char tMove[CTEXT * 2]; + snprintf(tMove, sizeof(tMove), "AbsoluteMove pan=%0.6f tilt=%0.6f zoom=%0.6f (speed pt=%0.4f zoom=%0.4f)", position_pantilt_x, position_pantilt_y, zoom, tPT, tZM); +#ifdef DEBUG_PONVIF_PTZ + LOG(tMove); #endif char tBuffer[DEFAULT_BUFFER_SIZE]; _buildRequest(tBuffer, sizeof(tBuffer), PONVIF_BODY_ABSOLUTE_MOVE, xesc(profileToken).c_str(), position_pantilt_x, position_pantilt_y, zoom, tPT, tPT,