PTZ Control

Last Updated on : 2023-08-09 09:25:02

Pan-tilt-zoom (PTZ) control enables a camera to pan from left to right, tilt up and down, and zoom in and out of a scene.

Features

Feature
Description
Basic features
  • Self-check: The PTZ module performs a self-check on the PTZ coordinate for calibration. Self-check is the most important feature of a PTZ camera.
  • Key control: The camera responds to the PTZ command from the user.
Advanced features
  • Patrol:
    • Simple patrol: The user sets the patrol time. The camera performs a 360° scan when the specified time is reached.
    • Non-simple patrol:
      • Panoramic patrol: The camera performs a 360° scan.
      • Site patrol: The camera patrols continuously between the user’s site favorites.
  • Tracking: When an object triggers the motion detection rule, the camera will use the PTZ feature to lock the moving target in the center of the screen. The user can configure the motion detection parameters to set the area to be tracked.
Extended features
  • Site favorites: The user can save the current view and position of the camera as one of the site favorites. The site name can be customized.
  • Preset points: A preset point is like a simplified favorite site. Up to four preset points can be set, each with a fixed name that cannot be customized.
  • Panorama stitching: The camera uses the PTZ feature to capture images from different perspectives or angles. Then, the captured images are stitched together to create a seamless panoramic image.

Development guide

Runtime environment

  • Development framework

    The generic features provided by IPC Product Development Kit.

  • Components

    • app_user_ptz
    • app_sys_ptz
    • app_user_event

How to

Configure the PTZ capabilities with motor.config and call the initialization API.

Initialization process

TY_SYS_PTZ_PARAM_T ptz_params;
...
// Configure the PTZ capabilities as needed.
...

// Initialize PTZ.
ty_user_ptz_start();

Data structure

typedef struct {
    int max_pan_step;                   // maximal pan step
    int max_pan_angle;                  // maximal pan angle
    int max_tilt_step;                  // maximal tilt step
    int max_tilt_angle;                 // maximal tilt angle
    int horizon_tilt_step;              // horizontal tilt step
    int pan_speed;                      // default pan speed
    int tilt_speed;                     // default tilt speed
    int tilt_track;                     // tilt track support flag
    int sleep_pos_def;                  // sleep position support flag
    int defalut_patrol_tmode;           // default patrol type (non-/simple patrol)
    int pan_reverse;                    // pan motor reverse flag
    int tilt_reverse;                   // tilt motor reverse flag
    char struct_type;                                           // device structure type
    TY_GET_OBJECT_COORDINATE_CB get_object_coordinate_cb;       // determinate track source
    char drv_path[DRV_PATH_NAME_LEN];                           // path of PTZ driver
} TY_SYS_PTZ_PARAM_T;

API description

Initialize the PTZ module

/**
 * @brief NONE
 *
 * @return OPERATE_RET
 */
OPERATE_RET ty_user_ptz_start(void);

The PTZ configuration is stored in motor.config, which does not require parameter passing through a function.

Initialize the PTZ system management module

/**
 * @fn OPERATE_RET ty_sys_ptz_init(TY_SYS_PTZ_PARAM_T* params)
 * @brief initialize PTZ component with user defined parameters.
 * @param[in] params: user defined parameters' srtuct pointer.
 * @param[out] None.
 * @retval OPRT_OK: action succeed; OPRT_INVALID_PARM: invaild parameter.
 * @attention None.
 */
OPERATE_RET ty_sys_ptz_init(IN CONST TY_SYS_PTZ_PARAM_T* params);

Get the current status of PTZ movement

/**
 * @fn int ty_sys_ptz_get_check_state(void)
 * @brief check if the device is in self-check
 * @param[in] None
 * @param[out] None
 * @retval 0: is in self check; 1: not in self check.
 * @attention None
 */
int ty_sys_ptz_get_check_state(void);

Get the current coordinates of the PTZ preset point

/**
 * @fn OPERATE_RET ty_sys_ptz_linkpos_get(OUT INT_T *x, OUT INT_T *y)
 * @brief get the current target position coordinates.
 * @param[in] None.
 * @param[out] x: target pan pos.
 * @param[out] y: target tilt pos.
 * @retval OPRT_OK: succeed; OPRT_COM_ERROR: PTZ component is uninitialized.
 * @attention None.
 */
int ty_sys_ptz_linkpos_get(int *x, int *y);

Get the status of key control

/**
 * @fn int ty_sys_ptz_get_key_status(void)
 * @brief get keying task state.
 * @param[in] None.
 * @retval 0: not in keying; 1: in keying.
 * @attention None.
 */
int ty_sys_ptz_get_key_status(void);

Stop the scheduling of PTZ threads

/**
 * @fn void ty_sys_ptz_stop(void)
 * @brief stop PTZ component.
 * @param[in] None.
 * @param[out] None.
 * @retval None.
 * @attention None.
 */
void ty_sys_ptz_stop(void);

Determine if the camera is moving

/**
 * @fn OPERATE_RET ty_sys_ptz_get_motion_state(OUT UINT_T *is_move)
 * @brief check if PTZ is moving(if md event is caused by PTZ moving).
 * @param[in] None.
 * @param[out] is_move to store result, 0: still(md event to upload); 1: in move(md event to ignore).
 * @retval OPRT_OK: action succeed; OPRT_INVALID_PARM: invaild parameter.
 * @attention None.
 */
OPERATE_RET ty_sys_ptz_get_motion_state(OUT UINT_T *is_move);

Get the current coordinates

/**
 * @fn OPERATE_RET ty_sys_ptz_pos(int *pan, int *tilt)
 * @brief get PTZ position
 * @param[in] None.
 * @param[out] pan: current pan step.
 * @param[out] tilt: current tilt step.
 * @retval OPRT_OK: action succeed; OPRT_INVALID_PARM: invaild parameter.
 * @attention None.
 */
OPERATE_RET ty_sys_ptz_pos(int *pan, int *tilt);

Example

Here is an example of how to configure the montor.config file to implement a typical patrol feature.

PTZ Control
Configuration item Value Description
ENV_MOTOR_PTZ_ENABLE 0 or 1 Specify whether to enable the PTZ feature.
  • 0: Disable
  • 1: Enable
ENV_MOTOR_STRUCT_TYPE 0 or 1 The PTZ structure.
  • 1: Infinite position structure.
  • 2: Limit position structure.
ENV_MOTOR_DRV_PATH String The directory of the camera: /dev/tymotor by default.
ENV_MOTOR_MAX_PAN_STEP Integer The maximum step size of horizontal movement.
ENV_MOTOR_MAX_PAN_ANGLE Integer The maximum angle of horizontal movement.
ENV_MOTOR_MAX_TILT_STEP Integer The maximum step size of vertical movement.
ENV_MOTOR_MAX_TILT_ANGLE Integer The maximum angle of vertical movement.
ENV_MOTOR_TILT_ZERO_STEP Integer The step size of vertical movement when the tilt is 0 degrees.
ENV_MOTOR_PAN_SPEED_MAX Integer The maximum speed of horizontal movement.
ENV_MOTOR_TILT_SPEED_MAX Integer The maximum speed of vertical movement.
ENV_MOTOR_TILT_TRACK_SUPPORT 0 or 1 Specify whether vertical tracking is supported.
ENV_MOTOR_PATROL_TYPE 0 or 2 Patrol mode.
  • 0: Non-simple patrol
  • 2: Simple patrol
ENV_MOTOR_TILT_INVERSE 0 or 1 The direction of the vertical motor.
  • 0: Forward
  • 1: Reverse
ENV_MOTOR_PAN_INVERSE 0 or 1 The direction of the horizontal motor.
  • 0: Forward
  • 1: Reverse
ENV_MOTOR_MOTOR_SUP_SLEEP_POS 0 or 1 Support for physical mask (privacy mode)
  • 0: Disable
  • 1: Enable

Things to note

The PTZ component only provides business logic capabilities and does not include driver capabilities. Add the necessary driver resource if needed.

FAQs

Can the camera perform other operations during self-check?

No, it cannot.

Self-check has the highest priority and cannot be interrupted by other operations. The modules listed from highest to lowest priority:

  1. Self-check
  2. Panorama stitching
  3. Key control
  4. Preset points and site favorites
  5. Patrol
  6. Tracking

Will the camera still perform its scheduled patrol if it gets disconnected?

Yes, it will.

The camera receives the patrol schedule after the user creates it on the mobile app. Here is how the patrol schedule works:

  1. The cloud sends the created patrol schedule to the camera.
  2. The camera receives the patrol schedule and sets a timer accordingly.
  3. The PTZ module gets notified when the timer expires and performs a patrol.