Source

servo / sweep

Full commit
#!/usr/bin/perl
use warnings;
use strict;
use Servo::RobotEQ;
use Time::HiRes 'usleep';

# /dev/tty.usbmodemfd1231 1 == 0 spin, 2 == 1 shoulder
# /dev/tty.usbmodemfd1211 1 == 4 wrist twist, 2 == 3 forearm
# /dev/tty.usbmodemfd1221 1 == 5 wrist tilt, 2 == 6 tool spin

my @filenames = qw(
	/dev/tty.usbmodemfd1231
	/dev/tty.usbmodemfd1211
	/dev/tty.usbmodemfd1221
);


my @limits = (
	[-800, +800],  # 1 == spin
	[-800, +800],  # 2 == shoulder
	[-800, +800],  # 3 == forearm
	[-800, +800],  # 4 == wrist twist
	[-400, +400],  # 5 == wrist tilt
	[-800, +800],  # 6 == tool spin
);

my @devs = map { Servo::RobotEQ->new($_) } @filenames;

my $t = 0;
my $dt = 0.01;

while (1)
{
	my @pos;
	my $pos = int(800 * sin($t += $dt));

	for my $dev (@devs)
	{
		for my $channel (1..2)
		{
			$dev->position($channel, $pos);
		}

		push @pos, $dev->counters();
	}

	print "$pos: @pos\n";
	usleep 100000;
}