puma / demo

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82``` ```#!/usr/bin/perl use warnings; use strict; use IO::Handle; my @pos; STDOUT->autoflush(1); sub puma_goto { my \$speed = shift; # 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 = ( 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 = 200; 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__ ```