Linksys WVC-210 PTZ working
Posted: Thu Apr 09, 2009 1:14 am
The control file is still a work in progress but does the job. I am waiting for the cgi map mode and the stop command to finish the script.
Continuous and relative moves are operational, and so are the presets.
I had a look at the GPL licensed firmware code and am sure that the camera can do map mode but it may not be available through the cgi in its current firmware 1.0
The camera has a nasty habit of going blurry when overexposed by reflected sunshine and takes 5 minutes to recover.
# ==========================================================================
#
# ZoneMinder iLinksys WVC-210 Control Protocol Module, $Date: 2009-04-06, $Revision: 001 $
# Copyright (C) 2008 Peter K (pklinux@SPAMiol.ie)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# ==========================================================================
#
# This module contains the implementation of the Linksys WVC-210 Pan and Tilt Webcam
#
package ZoneMinder::Control::WVC210;
use 5.006;
#use strict;
use warnings;
require ZoneMinder::Base;
require ZoneMinder::Control;
our @ISA = qw(ZoneMinder::Control);
our $VERSION = $ZoneMinder::Base::VERSION;
# ==========================================================================
#
# Linksys WVC-210 Control Protocol
#
# ==========================================================================
use ZoneMinder::Debug qw(:all);
use ZoneMinder::Config qw(:all);
use Time::HiRes qw( usleep );
sub new
{
my $class = shift;
my $id = shift;
my $self = ZoneMinder::Control->new( $id );
bless( $self, $class );
srand( time() );
return $self;
}
our $AUTOLOAD;
sub AUTOLOAD
{
my $self = shift;
my $class = ref($self) || croak( "$self not object" );
my $name = $AUTOLOAD;
$name =~ s/.*://;
if ( exists($self->{$name}) )
{
return( $self->{$name} );
}
Fatal( "Can't access $name member of object of class $class" );
}
sub open
{
my $self = shift;
$self->loadMonitor();
use LWP::UserAgent;
$self->{ua} = LWP::UserAgent->new;
$self->{ua}->agent( "ZoneMinder Control Agent/".ZM_VERSION );
$self->{state} = 'open';
}
sub close
{
my $self = shift;
$self->{state} = 'closed';
}
sub printMsg
{
my $self = shift;
my $msg = shift;
my $msg_len = length($msg);
Debug( $msg."[".$msg_len."]" );
}
sub sendCmd
{
my $self = shift;
my $cmd = shift;
my $result = undef;
printMsg( $cmd, "Tx" );
print( "http://$address/$cmd\n" );
my $req = HTTP::Request->new( GET=>"http://".$self->{Monitor}->{ControlAddress}."$cmd" );
my $res = $self->{ua}->request($req);
if ( $res->is_success )
{
$result = !undef;
}
else
{
Error( "Error check failed: '".$res->status_line()."'" );
}
return( $result );
}
sub cameraReset
{
my $self = shift;
Debug( "Camera Reset" );
my $cmd = "/pt/ptctrl.cgi?mv=H";
$self->sendCmd( $cmd );
}
sub moveConUp
{
my $self = shift;
Debug( "Move Up" );
my $cmd = "/pt/ptctrl.cgi?mv=U,5";
$self->sendCmd( $cmd );
}
sub moveConDown
{
my $self = shift;
Debug( "Move Down" );
my $cmd = "/pt/ptctrl.cgi?mv=D,5";
$self->sendCmd( $cmd );
}
sub moveConLeft
{
my $self = shift;
Debug( "Move Left" );
my $cmd = "/pt/ptctrl.cgi?mv=L,5";
$self->sendCmd( $cmd );
}
sub moveConRight
{
my $self = shift;
Debug( "Move Right" );
my $cmd = "/pt/ptctrl.cgi?mv=R,5";
$self->sendCmd( $cmd );
}
sub moveConUpRight
{
my $self = shift;
Debug( "Move Up/Right" );
my $cmd = "/pt/ptctrl.cgi?mv=UR,5";
$self->sendCmd( $cmd );
}
sub moveConUpLeft
{
my $self = shift;
Debug( "Move Up/Left" );
my $cmd = "/pt/ptctrl.cgi?mv=UL,5";
$self->sendCmd( $cmd );
}
sub moveConDownRight
{
my $self = shift;
Debug( "Move Down/Right" );
my $cmd = "/pt/ptctrl.cgi?mv=DR,5";
$self->sendCmd( $cmd );
}
sub moveConDownLeft
{
my $self = shift;
Debug( "Move Down/Left" );
my $cmd = "/pt/ptctrl.cgi?mv=DL,5";
$self->sendCmd( $cmd );
}
sub moveRelUp
{
my $self = shift;
my $params = shift;
my $step = $self->getParam( $params, 'tiltstep' );
Debug( "Step Up $step" );
my $cmd = "/pt/ptctrl.cgi?position=0,$step";
$self->sendCmd( $cmd );
}
sub moveRelDown
{
my $self = shift;
my $params = shift;
my $step = $self->getParam( $params, 'tiltstep' );
Debug( "Step Down $step" );
my $cmd = "/pt/ptctrl.cgi?position=0,-$step";
$self->sendCmd( $cmd );
}
sub moveRelLeft
{
my $self = shift;
my $params = shift;
my $step = $self->getParam( $params, 'panstep' );
Debug( "Step Left $step" );
my $cmd = "/pt/ptctrl.cgi?position=-$step,0";
$self->sendCmd( $cmd );
}
sub moveRelRight
{
my $self = shift;
my $params = shift;
my $step = $self->getParam( $params, 'panstep' );
Debug( "Step Right $step" );
my $cmd = "/pt/ptctrl.cgi?position=$step,0";
$self->sendCmd( $cmd );
}
# Diagonal movements were hacked as zmcontrol.pl does not pass panstep and tiltstep
sub moveRelUpRight
{
my $self = shift;
my $params = shift;
my $panstep = $self->getParam( $params, 'panspeed' );
my $tiltstep = $self->getParam( $params, 'tiltspeed' );
Debug( "Step Up/Right $tiltstep/$panstep" );
my $cmd = "/pt/ptctrl.cgi?position=$panstep,$tiltstep";
$self->sendCmd( $cmd );
}
sub moveRelUpLeft
{
my $self = shift;
my $params = shift;
my $panstep = $self->getParam( $params, 'panspeed' );
my $tiltstep = $self->getParam( $params, 'tiltspeed' );
Debug( "Step Up/Left $tiltstep/$panstep" );
my $cmd = "/pt/ptctrl.cgi?position=-$panstep,$tiltstep";
$self->sendCmd( $cmd );
}
sub moveRelDownRight
{
my $self = shift;
my $params = shift;
my $panstep = $self->getParam( $params, 'panspeed' );
my $tiltstep = $self->getParam( $params, 'tiltspeed' );
Debug( "Step Down/Right $tiltstep/$panstep" );
my $cmd = "/pt/ptctrl.cgi?position=$panstep,-$tiltstep";
$self->sendCmd( $cmd );
}
sub moveRelDownLeft
{
my $self = shift;
my $params = shift;
my $panstep = $self->getParam( $params, 'panspeed' );
my $tiltstep = $self->getParam( $params, 'tiltspeed' );
Debug( "Step Down/Left $tiltstep/$panstep" );
my $cmd = "/pt/ptctrl.cgi?position=-$panstep,-$tiltstep";
$self->sendCmd( $cmd );
}
sub moveMap
{
my $self = shift;
my $params = shift;
my $xcoord = $self->getParam( $params, 'xcoord' );
my $ycoord = $self->getParam( $params, 'ycoord' );
Debug( "Move Map to $xcoord,$ycoord" );
my $cmd = "/pt/ptctrl.cgi?mv=$xcoord,$ycoord";
$self->sendCmd( $cmd );
}
sub moveStop
{
my $self = shift;
Debug( "Stop Movement" );
my $cmd = "/pt/ptctrl.cgi";
$self->sendCmd( $cmd );
}
sub presetSet
{
my $self = shift;
my $params = shift;
my $preset = $self->getParam( $params, 'preset' );
Debug( "Set Preset $preset" );
my $cmd = "/pt/ptctrl.cgi?preset=save,$preset";
$self->sendCmd( $cmd );
}
sub presetGoto
{
my $self = shift;
my $params = shift;
my $preset = $self->getParam( $params, 'preset' );
Debug( "Goto Preset $preset" );
my $cmd = "/pt/ptctrl.cgi?preset=move,$preset";
$self->sendCmd( $cmd );
}
sub presetHome
{
my $self = shift;
Debug( "Home Preset" );
my $cmd = "/pt/ptctrl.cgi?preset=move,103";
$self->sendCmd( $cmd );
}
1;
__END__
# Below is stub documentation for your module. You'd better edit it!
=head1 NAME
ZoneMinder::Database - Perl extension for WVC-210
=head1 SYNOPSIS
use ZoneMinder::Database;
=head1 DESCRIPTION
Stub documentation for ZoneMinder, created by PK.
Linksys WVC-210
=head2 EXPORT
None by default.
=head1 SEE ALSO
See Linksys Website for details.
=head1 AUTHOR
Peter K
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2008-2009 Peter K
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.3 or,
at your option, any later version of Perl 5 you may have available.
Continuous and relative moves are operational, and so are the presets.
I had a look at the GPL licensed firmware code and am sure that the camera can do map mode but it may not be available through the cgi in its current firmware 1.0
The camera has a nasty habit of going blurry when overexposed by reflected sunshine and takes 5 minutes to recover.
# ==========================================================================
#
# ZoneMinder iLinksys WVC-210 Control Protocol Module, $Date: 2009-04-06, $Revision: 001 $
# Copyright (C) 2008 Peter K (pklinux@SPAMiol.ie)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# ==========================================================================
#
# This module contains the implementation of the Linksys WVC-210 Pan and Tilt Webcam
#
package ZoneMinder::Control::WVC210;
use 5.006;
#use strict;
use warnings;
require ZoneMinder::Base;
require ZoneMinder::Control;
our @ISA = qw(ZoneMinder::Control);
our $VERSION = $ZoneMinder::Base::VERSION;
# ==========================================================================
#
# Linksys WVC-210 Control Protocol
#
# ==========================================================================
use ZoneMinder::Debug qw(:all);
use ZoneMinder::Config qw(:all);
use Time::HiRes qw( usleep );
sub new
{
my $class = shift;
my $id = shift;
my $self = ZoneMinder::Control->new( $id );
bless( $self, $class );
srand( time() );
return $self;
}
our $AUTOLOAD;
sub AUTOLOAD
{
my $self = shift;
my $class = ref($self) || croak( "$self not object" );
my $name = $AUTOLOAD;
$name =~ s/.*://;
if ( exists($self->{$name}) )
{
return( $self->{$name} );
}
Fatal( "Can't access $name member of object of class $class" );
}
sub open
{
my $self = shift;
$self->loadMonitor();
use LWP::UserAgent;
$self->{ua} = LWP::UserAgent->new;
$self->{ua}->agent( "ZoneMinder Control Agent/".ZM_VERSION );
$self->{state} = 'open';
}
sub close
{
my $self = shift;
$self->{state} = 'closed';
}
sub printMsg
{
my $self = shift;
my $msg = shift;
my $msg_len = length($msg);
Debug( $msg."[".$msg_len."]" );
}
sub sendCmd
{
my $self = shift;
my $cmd = shift;
my $result = undef;
printMsg( $cmd, "Tx" );
print( "http://$address/$cmd\n" );
my $req = HTTP::Request->new( GET=>"http://".$self->{Monitor}->{ControlAddress}."$cmd" );
my $res = $self->{ua}->request($req);
if ( $res->is_success )
{
$result = !undef;
}
else
{
Error( "Error check failed: '".$res->status_line()."'" );
}
return( $result );
}
sub cameraReset
{
my $self = shift;
Debug( "Camera Reset" );
my $cmd = "/pt/ptctrl.cgi?mv=H";
$self->sendCmd( $cmd );
}
sub moveConUp
{
my $self = shift;
Debug( "Move Up" );
my $cmd = "/pt/ptctrl.cgi?mv=U,5";
$self->sendCmd( $cmd );
}
sub moveConDown
{
my $self = shift;
Debug( "Move Down" );
my $cmd = "/pt/ptctrl.cgi?mv=D,5";
$self->sendCmd( $cmd );
}
sub moveConLeft
{
my $self = shift;
Debug( "Move Left" );
my $cmd = "/pt/ptctrl.cgi?mv=L,5";
$self->sendCmd( $cmd );
}
sub moveConRight
{
my $self = shift;
Debug( "Move Right" );
my $cmd = "/pt/ptctrl.cgi?mv=R,5";
$self->sendCmd( $cmd );
}
sub moveConUpRight
{
my $self = shift;
Debug( "Move Up/Right" );
my $cmd = "/pt/ptctrl.cgi?mv=UR,5";
$self->sendCmd( $cmd );
}
sub moveConUpLeft
{
my $self = shift;
Debug( "Move Up/Left" );
my $cmd = "/pt/ptctrl.cgi?mv=UL,5";
$self->sendCmd( $cmd );
}
sub moveConDownRight
{
my $self = shift;
Debug( "Move Down/Right" );
my $cmd = "/pt/ptctrl.cgi?mv=DR,5";
$self->sendCmd( $cmd );
}
sub moveConDownLeft
{
my $self = shift;
Debug( "Move Down/Left" );
my $cmd = "/pt/ptctrl.cgi?mv=DL,5";
$self->sendCmd( $cmd );
}
sub moveRelUp
{
my $self = shift;
my $params = shift;
my $step = $self->getParam( $params, 'tiltstep' );
Debug( "Step Up $step" );
my $cmd = "/pt/ptctrl.cgi?position=0,$step";
$self->sendCmd( $cmd );
}
sub moveRelDown
{
my $self = shift;
my $params = shift;
my $step = $self->getParam( $params, 'tiltstep' );
Debug( "Step Down $step" );
my $cmd = "/pt/ptctrl.cgi?position=0,-$step";
$self->sendCmd( $cmd );
}
sub moveRelLeft
{
my $self = shift;
my $params = shift;
my $step = $self->getParam( $params, 'panstep' );
Debug( "Step Left $step" );
my $cmd = "/pt/ptctrl.cgi?position=-$step,0";
$self->sendCmd( $cmd );
}
sub moveRelRight
{
my $self = shift;
my $params = shift;
my $step = $self->getParam( $params, 'panstep' );
Debug( "Step Right $step" );
my $cmd = "/pt/ptctrl.cgi?position=$step,0";
$self->sendCmd( $cmd );
}
# Diagonal movements were hacked as zmcontrol.pl does not pass panstep and tiltstep
sub moveRelUpRight
{
my $self = shift;
my $params = shift;
my $panstep = $self->getParam( $params, 'panspeed' );
my $tiltstep = $self->getParam( $params, 'tiltspeed' );
Debug( "Step Up/Right $tiltstep/$panstep" );
my $cmd = "/pt/ptctrl.cgi?position=$panstep,$tiltstep";
$self->sendCmd( $cmd );
}
sub moveRelUpLeft
{
my $self = shift;
my $params = shift;
my $panstep = $self->getParam( $params, 'panspeed' );
my $tiltstep = $self->getParam( $params, 'tiltspeed' );
Debug( "Step Up/Left $tiltstep/$panstep" );
my $cmd = "/pt/ptctrl.cgi?position=-$panstep,$tiltstep";
$self->sendCmd( $cmd );
}
sub moveRelDownRight
{
my $self = shift;
my $params = shift;
my $panstep = $self->getParam( $params, 'panspeed' );
my $tiltstep = $self->getParam( $params, 'tiltspeed' );
Debug( "Step Down/Right $tiltstep/$panstep" );
my $cmd = "/pt/ptctrl.cgi?position=$panstep,-$tiltstep";
$self->sendCmd( $cmd );
}
sub moveRelDownLeft
{
my $self = shift;
my $params = shift;
my $panstep = $self->getParam( $params, 'panspeed' );
my $tiltstep = $self->getParam( $params, 'tiltspeed' );
Debug( "Step Down/Left $tiltstep/$panstep" );
my $cmd = "/pt/ptctrl.cgi?position=-$panstep,-$tiltstep";
$self->sendCmd( $cmd );
}
sub moveMap
{
my $self = shift;
my $params = shift;
my $xcoord = $self->getParam( $params, 'xcoord' );
my $ycoord = $self->getParam( $params, 'ycoord' );
Debug( "Move Map to $xcoord,$ycoord" );
my $cmd = "/pt/ptctrl.cgi?mv=$xcoord,$ycoord";
$self->sendCmd( $cmd );
}
sub moveStop
{
my $self = shift;
Debug( "Stop Movement" );
my $cmd = "/pt/ptctrl.cgi";
$self->sendCmd( $cmd );
}
sub presetSet
{
my $self = shift;
my $params = shift;
my $preset = $self->getParam( $params, 'preset' );
Debug( "Set Preset $preset" );
my $cmd = "/pt/ptctrl.cgi?preset=save,$preset";
$self->sendCmd( $cmd );
}
sub presetGoto
{
my $self = shift;
my $params = shift;
my $preset = $self->getParam( $params, 'preset' );
Debug( "Goto Preset $preset" );
my $cmd = "/pt/ptctrl.cgi?preset=move,$preset";
$self->sendCmd( $cmd );
}
sub presetHome
{
my $self = shift;
Debug( "Home Preset" );
my $cmd = "/pt/ptctrl.cgi?preset=move,103";
$self->sendCmd( $cmd );
}
1;
__END__
# Below is stub documentation for your module. You'd better edit it!
=head1 NAME
ZoneMinder::Database - Perl extension for WVC-210
=head1 SYNOPSIS
use ZoneMinder::Database;
=head1 DESCRIPTION
Stub documentation for ZoneMinder, created by PK.
Linksys WVC-210
=head2 EXPORT
None by default.
=head1 SEE ALSO
See Linksys Website for details.
=head1 AUTHOR
Peter K
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2008-2009 Peter K
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.3 or,
at your option, any later version of Perl 5 you may have available.