git.haldean.org plotter / 7565488
make a command-line runner haldean 4 years ago
1 changed file(s) with 2 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
11 (:use :common-lisp)
22 (:export
33 :init
4 :get-pen
5 :set-pen-rel
6 :set-pen-abs
74 :disable-motors
85 :set-zero
9 :center-x
10 :center-y
11 :rel-x
12 :rel-y
13 :abs-x
14 :abs-y
15 :draw-circle
16 :start-buffer
17 :flush-buffer))
6 :run-gcode-file))
187
198 (in-package :so3-cnc)
209
2817
2918 (setf *width* 0)
3019 (setf *height* 0)
20 (setf *units-per-mm* 50)
3121 (setq *pen-states* '("up" "draw"))
3222
3323 (defun api-url (e) (format nil "http://saito:4242/~a" e))
4434 settings
4535 ))
4636
47 (defun center-x () (when (= *width* 0) (init)) (/ *width* 2))
48 (defun center-y () (when (= *width* 0) (init)) (/ *height* 2))
4937 (defun rel-x (x) (when (= *width* 0) (init)) (* 100 (/ x *width*)))
5038 (defun rel-y (y) (when (= *width* 0) (init)) (* 100 (/ y *height*)))
5139 (defun abs-x (x) (when (= *width* 0) (init)) (/ (* x *width*) 100))
5240 (defun abs-y (y) (when (= *width* 0) (init)) (/ (* y *height*) 100))
5341
5442 (defun get-pen-raw () (cdr (jsown:parse (s-http-client:do-http-request (api-url "v1/pen")))))
55
5643 (defun get-pen ()
5744 (let* ((pen-data (get-pen-raw))
5845 (extract-xyz
6855 (defun set-pen-rel (x y z &key (wait-time 0))
6956 (send-put-request (api-url "v1/pen") (jsown:new-js ("state" (nth z *pen-states*))))
7057 (send-put-request (api-url "v1/pen") (jsown:new-js ("x" x) ("y" y))))
71 (defun set-pen-abs (x y z &key (wait-time 0)) (set-pen-rel (rel-x x) (rel-y y) z :wait-time wait-time))
7258
7359 (defun disable-motors ()
7460 (s-http-client:do-http-request (api-url "v1/motors") :method :DELETE))
7561
7662 (defun set-zero ()
7763 (send-put-request (api-url "v1/motors") (jsown:new-js ("reset" 1))))
78
79 (defun draw-circle (cx cy r &key (seg 30))
80 (set-pen-abs cx (+ cy r) 0)
81 (set-pen-abs cx (+ cy r) 1)
82 (loop for theta from 0 to tau by (/ tau seg)
83 do (let ((x (+ cx (* r (sin theta))))
84 (y (+ cy (* r (cos theta)))))
85 (set-pen-abs x y 1)))
86 (set-pen-abs cx (+ cy r) 1)
87 )
8864
8965 (defun start-buffer ()
9066 (send-put-request (api-url "v1/buffer") (jsown:new-js ("paused" t))))
134110 (z "unknown" :type string)
135111 (dummy-file nil)
136112 )
137
138 (setf *units-per-mm* 50)
139113
140114 (defun x-from-gcode (x-mm) (- 100 (rel-x (* x-mm *units-per-mm*))))
141115 (defun y-from-gcode (y-mm) (rel-y (* y-mm *units-per-mm*)))