Skip to content

PTZ auto-tracking causes position loss when hitting physical limits — soft limit proposal #217

@w35m17h

Description

@w35m17h

Model: GK-200MP2B
Sonoff-hack version: 0.2.0
Frigate with ONVIF auto-tracking enabled

Problem

When using Frigate's PTZ auto-tracking, the camera will occasionally
track a subject past its physical hard stops. Since the GK-200MP2B uses
an open-loop stepper system with no limit switches, once the motor stalls
against the hard stop the firmware loses its position reference. All
presets then become inaccurate until the camera is rehomed (ptz_drv.ko
unload/reload).

This makes auto-tracking unreliable for production use — it works well
until it doesn't, and recovery requires manual intervention.

Proposed Solution

Implement soft limits in the ONVIF server. After a rehome the position
is known. Track position with every move command. Before executing a move,
check if the new position would exceed configurable soft limits (set just
inside the physical hard stops). If the move would exceed the limit, ACK
the command but don't send it to the motors. Position reference stays valid.

Example logic:

  • LIMIT_X = 3400 (just inside Horizontal=3500)
  • LIMIT_Y = 850 (just inside Vertical=900)
  • On move command: if (current_pos + requested_move) > LIMIT then ACK
    without moving

Current position is already available via: ptz -a get_coord

The intercept point should be in onvif_simple_server since all PTZ
clients (Frigate, web UI, MQTT) go through ONVIF. Intercepting at the
ptz binary or ptz.sh layer would miss direct ONVIF calls from Frigate.

Would you be open to implementing this? Happy to test on GK-200MP2B
with Frigate auto-tracking if you build it.

Current Workaround

As a workaround, I have implemented a "Rehome Camera" button in the
PTZ web UI that reloads the PTZ kernel module (unload/reload ptz_drv.ko)
without a full reboot. The stream stays up during rehome.

This was confirmed working in Discussion #200 by ZeynepKlc.

This involves three files:

  • www/cgi-bin/rehome.sh — CGI script that unloads/reloads ptz_drv.ko
  • www/pages/ptz.html — adds Rehome Camera section with button
  • www/js/all.js — adds click handler for the rehome button

Happy to submit a PR for these files if you are interested — they
address the symptom while the soft limits fix addresses the root cause.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions