Created
July 25, 2010 19:17
-
-
Save martymcguire/489805 to your computer and use it in GitHub Desktop.
Adds M150/151 camera-trigger codes to a MakerBot G-code build file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# Usage: | |
# $ cat my.gcode | ./add_camera_events.pl > my_camera.gcode | |
my $x_pose = "0.0"; | |
my $y_pose = "-45.0"; | |
my $move_speed = "3300.0"; | |
my $last_g1 = undef; | |
my $last_was_m103 = 0; | |
my $delay = 2000; # 2 seconds total wait time | |
my $trigger_time = 700; # 700ms | |
my $wait_to_move = $delay - $trigger_time; | |
my $g1rx = "^G1 X([-.0-9]+) Y([-.0-9]+) Z([-.0-9]+) F([-.0-9]+)\$"; | |
while(<STDIN>){ | |
my $line = $_; | |
chomp($line); | |
if($line =~ m/^G1/){ | |
$last_g1 = $line | |
} | |
elsif($line =~ m/^M103/){ | |
$last_was_m103 = 1; | |
} | |
elsif($line =~ m/<\/layer>/){ | |
if($last_was_m103){ | |
my ($x, $y, $z, $f) = $last_g1 =~ /$g1rx/; | |
print "(<photo>)\n"; | |
print "G1 X$x_pose Y$y_pose Z$z F$move_speed\n"; | |
print "M150\n"; | |
print "G4 P$trigger_time\n"; | |
print "M151\n"; | |
print "G4 P$wait_to_move\n"; | |
print "G1 X$x Y$y Z$z F$move_speed\n"; | |
print "(</photo>)\n"; | |
} | |
} | |
else { | |
$last_was_m103 = 0; | |
} | |
print "$line\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment