Module AxisNetcam::Camera::PTZ
In: lib/axis-netcam/camera.rb

Functionality related to the camera‘s point, zoom, and tilt. Not all camera models support this.

Methods

Public Instance methods

Tries to ‘calibrate’ the camera by rotating to all extremes.

This may be useful when the camera is shifted by some external force and looses its place. Running the calibration should reset things so that the camera‘s absolute point and tilt co-ordinates are consistent relative to the camera‘s base.

[Source]

# File lib/axis-netcam/camera.rb, line 197
      def calibrate
        @log.info("Starting camera calibration...")
        
        pos = get_position
        limits = get_ptz_limits(:auto)
        
        zoom(limits['MinZoom'])
        (1..2).each do # do it twice, just to be safe...
          sleep(3)
          ptz(:pan => limits['MinPan'], :tilt => limits['MinTilt'])
          sleep(7)
          ptz(:pan => limits['MinPan'], :tilt => limits['MaxTilt'])
          sleep(7)
          ptz(:pan => limits['MaxPan'], :tilt => limits['MaxTilt'])
          sleep(7)
          ptz(:pan => limits['MaxPan'], :tilt => limits['MinTilt'])
          sleep(7)
        end
        
        ptz(pos)
        
        @log.info("Finished camera calibration.")
      end

Zooms the camera (in/out) to the given zoom factor.

[Source]

# File lib/axis-netcam/camera.rb, line 122
      def center_on(x,y)
        axis_action("com/ptz.cgi", {'center'  => "#{x},#{y}"})
      end

Returns the camera‘s current absolute position as a hash with :pan, :tilt, and :zoom elements.

:tilt and :pan are specified in degrees from center (for example, -170 to 170 for :pan, depending on your camera‘s physical capabilities), and zoom is an integer factor, with 0 being no zoom (widest possible viewing angle) and 10000 approaching a camera‘s maximum zoom. Again, this depends on your camera‘s capabilities.

[Source]

# File lib/axis-netcam/camera.rb, line 78
      def get_position
        raw = axis_action("com/ptz.cgi", {'query' => 'position'})
        str = raw.split
        pan = str[0].split("=").last.to_f
        tilt = str[1].split("=").last.to_f
        zoom = str[2].split("=").last.to_i
        
        {:pan => pan, :tilt => tilt, :zoom => zoom}
      end

Returns and array with the names of the preset positions saved in the camera.

[Source]

# File lib/axis-netcam/camera.rb, line 127
      def get_preset_positions
        str = axis_action("com/ptz.cgi", {'query' => 'presetposall'})
        positions = []
        str.each do |line|
          line =~ /presetposno\d+=(.*)/
          positions << $~[1].strip if $~ && $~[1]
        end
        positions
      end

Returns a hash with info about the camera‘s point-tilt-zoom limits.

The returned hash will look something like:

  {'MinPan' => "-169",
   'MaxPan' => "169",
   'MinTilt' => "-90",
   'MaxTilt' => "10",
   'MinZoom' => "1",
   'MaxZoom' => "19999"}

The pan and tilt limit values assume that your camera‘s image is not rotated. If you want to use these values in ptz calls and your image is configured to be rotated, then you should also specify :imagerotation => 0 as one of your parameters to ptz. For example:

  limits = c.get_ptz_limits
  c.ptz(:tilt => limits['MaxTilt'], :imagerotation => 0)

Alternatively, you can specify a rotation argument. This will automatically adjust the returned pan and tilt values to match the given rotation. You can also specify :auto instead of providing a numeric value, in which case the system will try to fetch the rotation value for you (but be careful, because this can slow things down, since the camera must be queried first).

[Source]

# File lib/axis-netcam/camera.rb, line 163
      def get_ptz_limits(rotation = nil)
        l = get_parameters("PTZ.Limit.L1")
        return l unless rotation
        
        rotation = get_current_image_rotation if rotation == :auto
        
        # TODO: this only works for the 0, 90, 180, 270 rotations but not arbitrary values
        case rotation
        when 90
          l['MinPan'], l['MaxPan'], l['MinTilt'], l['MaxTilt'] =
          l['MinTilt'], l['MaxTilt'], l['MinPan'], l['MaxPan']
        when 180
          l['MinPan'], l['MaxPan'], l['MinTilt'], l['MaxTilt'] =
          l['MinPan'], l['MaxPan'], l['MaxTilt']*-1, l['MinTilt']*-1
        when 270
          # FIXME: This transformation appears to be busted :(
          l['MinPan'], l['MaxPan'], l['MinTilt'], l['MaxTilt'] =
          l['MinTilt'], l['MaxTilt'], l['MinPan']*-1, l['MaxPan']*-1
        end
        
        l
      end

Move the camera one ‘tick’ in the given direction. Possible values are ‘up’, ‘down’, ‘left’, ‘right‘

[Source]

# File lib/axis-netcam/camera.rb, line 112
      def move(direction)
        axis_action("com/ptz.cgi", {'move' => direction})
      end

Pans the camera (left/right) to the given absolute position in degrees.

[Source]

# File lib/axis-netcam/camera.rb, line 106
      def pan(d)
        axis_action("com/ptz.cgi", {'pan'  => d})
      end

Points the camera at the given preset.

[Source]

# File lib/axis-netcam/camera.rb, line 187
      def point_at_preset_name(preset_name)
        axis_action("com/ptz.cgi", {'gotoserverpresetname' => preset_name})
      end

Simultanously pans, tilts, and zooms the camera. The argument is a hash that can have any of ‘pan’, ‘tilt’, and ‘zoom’ elements, each specifying the desired value for the movement.

Example:

  camera.ptz(:pan => 60, :zoom => 8000)

[Source]

# File lib/axis-netcam/camera.rb, line 96
      def ptz(ptz = {})
        axis_action('com/ptz.cgi', ptz)
      end

Tilts the camera (up/down) to the given absolute position in degrees.

[Source]

# File lib/axis-netcam/camera.rb, line 101
      def tilt(d)
        axis_action("com/ptz.cgi", {'tilt'  => d})
      end

Zooms the camera (in/out) to the given zoom factor.

[Source]

# File lib/axis-netcam/camera.rb, line 117
      def zoom(n)
        axis_action("com/ptz.cgi", {'zoom'  => n})
      end

[Validate]