Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Adds M150/151 camera-trigger codes to a MakerBot G-code build file
#!/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
You can’t perform that action at this time.