Trammell Hudson avatar Trammell Hudson committed 732d1b8 Draft

sweep the servos through a sine wave

Comments (0)

Files changed (1)

+#!/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;
+}
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.