]> git.earman.xyz Git - lisp/workenv.git/commitdiff
Initial commit
authorrearman <rearman@r717.net>
Tue, 9 Sep 2025 14:02:43 +0000 (10:02 -0400)
committerrearman <rearman@r717.net>
Tue, 9 Sep 2025 14:02:43 +0000 (10:02 -0400)
electrical.lisp [new file with mode: 0644]
math.lisp [new file with mode: 0644]
plc.lisp [new file with mode: 0644]
refrigeration.lisp [new file with mode: 0644]
unit-conv.lisp [new file with mode: 0644]

diff --git a/electrical.lisp b/electrical.lisp
new file mode 100644 (file)
index 0000000..a25cee7
--- /dev/null
@@ -0,0 +1,5 @@
+(defun eff-imp (r1 r2) (/ (+ (inv r1) (inv r2))))
+
+(defun amps->volts (amps imp) (* amps imp))
+
+(defun volts->amps (volts imp) (/ volts imp))
diff --git a/math.lisp b/math.lisp
new file mode 100644 (file)
index 0000000..c3b3bea
--- /dev/null
+++ b/math.lisp
@@ -0,0 +1,9 @@
+(defalias ^ expt)
+
+(defmacro square (x) `(^ ,x 2))
+
+(defmacro cube (x) `(^ ,x 3))
+
+(defmacro inv (x) `(/ (float ,x)))
+
+(defmacro E (number exponent) `(* (float ,number) (^ 10 ,exponent)))
diff --git a/plc.lisp b/plc.lisp
new file mode 100644 (file)
index 0000000..277ea5f
--- /dev/null
+++ b/plc.lisp
@@ -0,0 +1,43 @@
+(defparameter *volt-max* 10.0)
+(defparameter *resolution* 16)
+(defparameter *impedance* 249)
+
+(defun 13B () (setq *resolution* 13 *volt-max* 10.0))
+(defun 16B () (setq *resolution* 16 *volt-max* 10.0))
+
+(defalias P3K 16B)
+(defalias SLC 16B)
+(defalias P1K 13B)
+(defalias DL4 13B)
+
+(defun max-counts (resolution) (- (^ 2 resolution) 1))
+
+(defun volts->counts (vin)
+  (float (* (/ vin *volt-max*) (max-counts *resolution*))))
+
+(defun counts->volts (cin)
+  (float (* (/ cin (max-counts *resolution*)) *volt-max*)))
+
+(defun amps->counts (amps imp) (volts->counts (amps->volts amps imp)))
+
+(defun count-range (upper lower)
+  (list (volts->counts upper) (volts->counts lower)))
+
+(defun volt-range (upper lower)
+  (list (counts->volts upper) (counts->volts lower)))
+
+(defun divisor (count-max count-min scaled-max scaled-min)
+  (/ (float (- count-max count-min)) (- scaled-max scaled-min)))
+
+(defun offset (count-min scaled-min divisor)
+  (- scaled-min (/ count-min divisor)))
+
+(defun scale (count-max count-min scaled-max scaled-min)
+  (let ((div (divisor count-max count-min scaled-max scaled-min)))
+    (list div (offset count-min scaled-min div))))
+
+(defun final (analog-input divisor offset)
+  (+ offset (/ analog-input divisor)))
+
+(defun input (scaled-value divisor offset)
+  (* divisor (- scaled-value offset)))
diff --git a/refrigeration.lisp b/refrigeration.lisp
new file mode 100644 (file)
index 0000000..c5cad72
--- /dev/null
@@ -0,0 +1,20 @@
+(defun cfm-circ (fpm radius) (float (* pi fpm (square (/ radius 12)))))
+
+(defun cfm-rect (fpm width height) (float (* fpm (/ width 12) (/ height 12))))
+
+(defun sat-water-press (temp)
+       (+ 0.0182795
+               (* temp 0.001029904)
+               (* (square temp) 2.579408e-05)
+               (* (cube temp) 2.400493e-07)
+               (* (^ temp 4) 8.100939e-10)
+               (* (^ temp 5) 3.256805e-11)
+               (* (^ temp 6) -1.001922e-13)
+               (* (^ temp 7) 2.44161e-16)))
+
+(defun hum-ratio (humidity swp)
+       (let ((hum-press (* (/ humidity 100.0) swp)))
+               (/ (* hum-press 0.62198) (- 14.7 hum-press))))
+
+(defun gn-water-per-lb (humidity temp)
+       (* 7000 (hum-ratio humidity (sat-water-press temp))))
diff --git a/unit-conv.lisp b/unit-conv.lisp
new file mode 100644 (file)
index 0000000..76bfa1d
--- /dev/null
@@ -0,0 +1,15 @@
+(defun mm->in (mm) (/ mm 25.4))
+
+(defun in->mm (in) (* in 25.4))
+
+(defun k->c (tempk) (- tempk 273.15))
+
+(defun c->k (tempc) (+ tempc 273.15))
+
+(defun c->f (tempc) (+ (* tempc 1.8) 32))
+
+(defun f->c (tempf) (/ (- tempf 32) 1.8))
+
+(defun k->f (tempk) (c->f (k->c tempk)))
+
+(defun f->k (tempf) (c->k (f->c tempf)))