Source

puma / demo

#!/usr/bin/perl
use warnings;
use strict;
use IO::Handle;

my @pos;
STDOUT->autoflush(1);

sub puma_goto
{
	my $speed = shift;

	print "go,$speed,", join(",", @_), "\n";
	return;

	# If there is an old position, compute the delta
	my $max_delta = 0;

	for my $axis (1..6)
	{
		my $new_pos = $_[$axis-1];
		my $old_pos = $pos[$axis-1];
		next unless defined $old_pos;

		my $delta = $new_pos - $pos[$axis-1];
		$delta = -$delta if $delta < 0;
		$max_delta = $delta if $delta > $max_delta;
	}

	for my $axis (1..6)
	{
		my $new_pos = $_[$axis-1];
		my $old_pos = $pos[$axis-1];
		my $per_speed = $speed;

		if (defined $old_pos)
		{
			my $delta = $new_pos - $pos[$axis-1];
			$delta = -$delta if $delta < 0;
			$per_speed = int($speed * $delta / $max_delta);
			$per_speed = 1 if $per_speed <= 0;
		}

		print "$axis,$new_pos,$per_speed\n";
		$pos[$axis-1] = $new_pos;
	}
}

my %points = (
s1 => [-285,19207,-5754,-8279,5092,10644],
s2 => [3095,19028,-7029,-10738,4645,10668],
s3 => [-1614,19330,-5274,-6498,4767,10638],
1 => [-12745,-9431,13189,16345,-11436,39],
2 => [-6992,-16587,2803,13675,-6883,-2997],
3 => [-12731,-8874,17593,17647,-11193,2494],
4 => [-5312,-12877,7840,12894,-8353,-1358],
5 => [-4696,-9015,17452,11052,-11639,1353],
6 => [-2348,-12512,8310,11063,-7544,-889],
7 => [1136,-9278,15824,8642,-10698,768],
8 => [480,-14648,5391,7813,-5300,602],
home => [ 0,0,0,0,0,0],
);

my $speed = 500;

while(<>)
{
	chomp;
	my $points = $points{$_};
	unless(defined $points)
	{
		warn "$_: No such point\n";
		next;
	}


	puma_goto($speed, @$points);
}

__END__
#puma_goto(200, -9151,-16071,11215,-3172,8414,-7495);
puma_goto(200, -8809,-18058,8488,5522,7492,4690);

<>;

#puma_goto(1000, -1243,-15991,11385,-8759,9184,-7525);
puma_goto(1000, 3511,-19555,4057,-3160,7096,2968);
__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.