Created
March 30, 2015 17:46
-
-
Save jkominek/0b4bd93e3ada4b19bf7d to your computer and use it in GitHub Desktop.
gcode hole patterns in racket
This file contains hidden or 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
#lang racket | |
(define (distance a b) | |
(sqrt (for/sum ([a a] [b b]) | |
(expt (- a b) 2)))) | |
(define (greedy-tsp data #:start [start #f]) | |
(if (null? data) | |
'() | |
(if start | |
(let ([next (car (sort data < | |
#:key (lambda (p) (distance start p)) | |
#:cache-keys? #t))]) | |
(cons next (greedy-tsp (filter (lambda (v) (not (equal? v next))) data) | |
#:start next))) | |
(cons (car data) (greedy-tsp (cdr data) #:start (car data)))))) | |
(define data | |
(for*/list ([x '(10 20 30 40 50 60 70)] | |
[y '(9.5)]) | |
(vector x y))) | |
(define (generate-gcode-visit points | |
[drill-generator (lambda (p i) "")] | |
#:origin [origin (vector 0.0 0.0)] | |
#:feed [feed 150] #:vertical-clearance [vertical-clearance 2]) | |
(for ([p (greedy-tsp points)] | |
[i (in-naturals)]) | |
(printf "G0 X~a Y~a~n" | |
(- (vector-ref p 0) (vector-ref origin 0)) | |
(- (vector-ref p 1) (vector-ref origin 1))) | |
(printf "G1 X~a Y~a Z0.0 F~a~n" | |
(- (vector-ref p 0) (vector-ref origin 0)) | |
(- (vector-ref p 1) (vector-ref origin 1)) feed) | |
(printf "~a~n" (drill-generator p i)) | |
(printf "G0 Z~a~n" vertical-clearance)) | |
(printf "M2~n") | |
) | |
(define (helical-bore p i) | |
(define circles 15) | |
(define depth-per 0.25) | |
(define radius 1.91250) | |
(define feed 100) | |
(string-join | |
(append | |
(list "G91" | |
; surface | |
(format "G1 X~a F~a" radius feed) | |
(format "G2 X~a I~a F~a" (* -2 radius) (* -1 radius) feed) | |
(format "G2 X~a I~a F~a" (* 2 radius) (* 1 radius) feed) | |
) | |
(for/list ([circuit (in-range 0 circles)]) | |
(format "G2 X~a I~a Z~a F~a~nG2 X~a I~a Z~a F~a" | |
(* -2 radius) (* -1 radius) (- (/ depth-per 2)) feed | |
(* 2 radius) (* 1 radius) (- (/ depth-per 2)) feed)) | |
(list | |
; bottom | |
(format "G2 X~a I~a F~a" (* -2 radius) (* -1 radius) feed) | |
(format "G2 X~a I~a F~a" (* 2 radius) (* 1 radius) feed) | |
"G90") | |
) "\n")) | |
(generate-gcode-visit data | |
helical-bore | |
#:vertical-clearance 2) | |
#;(printf "~a~nM2~n" | |
(helical-bore #(0 0) 5) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment