Gcode-Interpreter

 view release on metacpan or  search on metacpan

scripts/Gin/Calibrate/GcodeGenerator.pm  view on Meta::CPAN

    "G1 Z$z F9000",     # Move Z down a bit
    "G1 X$x Y$y",       # Move to a suitable playground
    "G92 X0 Y0 Z0 E0",  # Make the current position zero
    "G91",              # Relative positioning
  );

  return \@gcode;
}

sub waggle {
  my ($self, $directions, $distance, $iterations) = @_;

  my @gcode = ();

  for(my $i = 0; $i < $iterations; $i++) {
    foreach my $direction (1, -1) {
      my $moves = {
        'X' => 0,
        'Y' => 0,
        'Z' => 0,
      };

      foreach my $dir (@$directions) {
        $moves->{$dir} = $direction * $distance;
      }

scripts/calibrate.pl  view on Meta::CPAN

    $port = '/dev/ttyUSB0';
  } else {
    die "Could not find a suitable serial port to use\n";
  }

  $serial->open_serial($port, 250000);

  my $generator = Gin::Calibrate::GcodeGenerator->new();

  my @waggle_parameters = (
    { 'distance' => 0.1, 'iterations' => 100 },
    { 'distance' => 0.5, 'iterations' => 100 },
    { 'distance' => 1, 'iterations' => 100 },
    { 'distance' => 2, 'iterations' => 100 },
    { 'distance' => 3, 'iterations' => 100 },
    { 'distance' => 4, 'iterations' => 100 },
    { 'distance' => 5, 'iterations' => 50 },
    { 'distance' => 10, 'iterations' => 10 },
    { 'distance' => 50, 'iterations' => 5 },
    { 'distance' => 100, 'iterations' => 2 },
  );

  my @tests = ();

  foreach my $params (@waggle_parameters) {
    push @tests, {
      'name' => 'x',
      'distance' => $params->{'distance'},
      'gcode' => $generator->waggle(['X'], $params->{'distance'}, $params->{'iterations'}),
      'iterations' => $params->{'iterations'},
    };
    push @tests, {
      'name' => 'y',
      'distance' => $params->{'distance'},
      'gcode' => $generator->waggle(['Y'], $params->{'distance'}, $params->{'iterations'}),
      'iterations' => $params->{'iterations'},
    };
  }

  @waggle_parameters = (
    {'distance' => 0.1, 'iterations' => 50 },
    {'distance' => 0.5, 'iterations' => 50 },
    {'distance' => 1, 'iterations' => 10 },
    {'distance' => 2, 'iterations' => 5 },
    {'distance' => 5, 'iterations' => 2 },
    {'distance' => 10, 'iterations' => 1 },
    {'distance' => 50, 'iterations' => 1 },
  );

  foreach my $params (@waggle_parameters) {
    push @tests, {
      'name' => 'z',
      'distance' => $params->{'distance'},
      'gcode' => $generator->waggle(['Z'], $params->{'distance'}, $params->{'iterations'}),
      'iterations' => $params->{'iterations'},
    };
  }

  print "Waiting for printer...\n";
  sleep(2);

  print "Starting...\n";
  my $start_gcode = $generator->start_gcode();
  &send_gcode($serial, (@$start_gcode)); 

scripts/calibrate.pl  view on Meta::CPAN

  my $totals = {};

  foreach my $test (@tests) {
    my @gcode = @{$test->{'gcode'}};
    my $start = [gettimeofday];
    &send_gcode($serial, @gcode);
    my $end = [gettimeofday];

    my $diff = tv_interval($start, $end);
    # When we test, we go there and back, so distance * 2
    my $speed = ($test->{'distance'} * 2 * $test->{'iterations'}) / $diff;
    printf("Test '%s(%.1f)' executed %d iterations in %.4f seconds -> %.4fmm/s\n",
      $test->{'name'},
      $test->{'distance'},
      $test->{'iterations'},
      $diff,
      $speed);
    $test->{'time'} = $diff;

    my $test_type = 'z';
    if($test->{'name'} eq 'x' || $test->{'name'} eq 'y' || $test->{'name'} eq 'xy') {
      $test_type = 'xy';
    }
    if(!exists($totals->{$test_type})) {
      $totals->{$test_type} = {};

scripts/results  view on Meta::CPAN

Test 'x(1.0)' executed 100 iterations in 5.5740 seconds -> 35.8809mm/s
Test 'y(1.0)' executed 100 iterations in 5.5743 seconds -> 35.8788mm/s
Test 'xy(1.0)' executed 100 iterations in 5.5333 seconds -> 36.1451mm/s
Test 'x(2.0)' executed 100 iterations in 8.4578 seconds -> 47.2937mm/s
Test 'y(2.0)' executed 100 iterations in 8.4619 seconds -> 47.2707mm/s
Test 'xy(2.0)' executed 100 iterations in 8.2571 seconds -> 48.4430mm/s
Test 'x(3.0)' executed 100 iterations in 10.8495 seconds -> 55.3019mm/s
Test 'y(3.0)' executed 100 iterations in 10.8496 seconds -> 55.3018mm/s
Test 'xy(3.0)' executed 100 iterations in 10.5263 seconds -> 57.0002mm/s
Test 'x(4.0)' executed 100 iterations in 12.6683 seconds -> 63.1498mm/s
Test 'y(4.0)' executed 100 iterations in 12.6682 seconds -> 63.1503mm/s
Test 'xy(4.0)' executed 100 iterations in 12.4470 seconds -> 64.2726mm/s
Test 'x(5.0)' executed 50 iterations in 7.2492 seconds -> 68.9727mm/s
Test 'y(5.0)' executed 50 iterations in 7.2493 seconds -> 68.9720mm/s
Test 'xy(5.0)' executed 50 iterations in 7.0774 seconds -> 70.6471mm/s
Test 'x(10.0)' executed 10 iterations in 2.1667 seconds -> 92.3058mm/s
Test 'y(10.0)' executed 10 iterations in 2.1666 seconds -> 92.3112mm/s
Test 'xy(10.0)' executed 10 iterations in 2.1379 seconds -> 93.5517mm/s
Test 'x(50.0)' executed 5 iterations in 3.7598 seconds -> 132.9859mm/s
Test 'y(50.0)' executed 5 iterations in 3.7598 seconds -> 132.9841mm/s
Test 'xy(50.0)' executed 5 iterations in 3.7476 seconds -> 133.4205mm/s
Test 'x(100.0)' executed 2 iterations in 2.8423 seconds -> 140.7287mm/s
Test 'y(100.0)' executed 2 iterations in 2.8424 seconds -> 140.7281mm/s
Test 'xy(100.0)' executed 2 iterations in 2.8383 seconds -> 140.9290mm/s
Test 'z(0.1)' executed 50 iterations in 2.9159 seconds -> 3.4294mm/s
Test 'z(0.5)' executed 50 iterations in 8.6913 seconds -> 5.7529mm/s
Test 'z(1.0)' executed 10 iterations in 2.7400 seconds -> 7.2993mm/s
Test 'z(2.0)' executed 5 iterations in 2.3754 seconds -> 8.4196mm/s
Test 'z(5.0)' executed 2 iterations in 2.1542 seconds -> 9.2844mm/s
Test 'z(10.0)' executed 1 iterations in 2.0805 seconds -> 9.6132mm/s
Test 'z(50.0)' executed 1 iterations in 10.0880 seconds -> 9.9128mm/s



( run in 1.349 second using v1.01-cache-2.11-cpan-5511b514fd6 )