Browse Source

ONVIF absolute move: keep the position inside the camera limits

The ROI orientation was not limited: a target accepted up to half a field of view
outside the mechanical range (or any elevation with a 90 deg tilt camera) gave e.g.
tilt=1.344, which the camera rejects with ter:InvalidPosition.

- spherical2onvif: endless pan wraps the azimuth into 0..360; pan/tilt are clamped
  to -1..1 and zoom to 0..1 (the camera goes to its end position).
- pOnvif::ptz_AbsoluteMove clamps to the profile limits / node position space as a
  last safety (covers operator absolute moves too) and logs it.
- The "Go to ROI" log also shows the target's fi/tetta/r and the pan/tilt models.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
pull/26/head
Claude 2 hours ago
parent
commit
5dc051623a
Failed to extract signature
  1. 12
      lib/App/common/deviceNodeCamera.cpp
  2. 17
      lib/alg/generic/Transform.cpp
  3. 28
      lib/data/ponvif/ponvif.cpp

12
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))

17
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)

28
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,

Loading…
Cancel
Save