servo / Servo / Axis.pm

#!/usr/bin/perl
package Servo::Axis;
use warnings;
use strict;
use Time::HiRes 'usleep';

sub new
{
	my $class = shift;
	my %args = (
		-min		=> -700,
		-max		=> +700,
		@_
	);

	bless {
		dev		=> $args{-dev},
		channel		=> $args{-channel},
		min		=> $args{-min},
		max		=> $args{-max},
	}, $class;
}

sub go
{
	my $self = shift;
	my $position = shift;

	$self->{dev}->position($self->{channel}, $position);
}


sub home
{
	my $self = shift;
	my $eps = 400;
	my $destination;

	while (1)
	{
		my @counts = $self->{dev}->counters()
			or next;

		my $cur = $counts[$self->{channel} - 1];

		if (defined $destination)
		{
			$destination *= 0.99;
		} else {
			# Convert for scale factor from counters
			$destination = $cur/20;
		}

		last if (-$eps < $cur and $cur < $eps);

		print "$self->{channel}: $cur\n";

		$self->go($destination);
		usleep 10000;
	}
}
		


"0, but true";
__END__
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.