Saturday, February 19, 2011

My first use of lisp on the job.

So my first opportunity to use lisp at work was while designing an electrical contractor plate for a large Gen-II display circuit. The boss told me not to spend too much time on it, since the circuit design would change before we really need to use the plate for electrical tests. So, instead of drawing the location of every contact pad, pin header location, and cutout for the arrays, I decided to write a script to quickly and accurately draw the hardware. The drafting tool I am using is, of course, AutoCAD 2011. I could have used their visual basic add-on to write the script, but going through their visual lisp tutorial was quick enough for me to finish the job in a day. So here is my first little contribution to the lisp world:



;; Current design parameters for a specific circuit layout
;; Runs on AutoCAD 2011 Visual LISP

(setq array-coordinate-list (list '((-201201.0 134712.0) (-111260.0 61650.0))
                '((-97360.5 134710.0) (-7420.0 61650.0))
                '((6479.50 134710.0) (96420.0 61650.0))
                '((110319.5 134710.0) (200260.0 61650.0))
                '((-201200.5 41160.0) (-111260.0 -31900.0))
                '((-97360.75 41160.0) (-7420.0 -31900.0))
                '((6479.25 41160.0) (96420.0 -31900.0))
                '((110319.25 41160.0) (200260.0 -31900.0))
                '((-201200.75 -52390.0) (-111259.75 -125449.75))
                '((-97360.75 -52390.0) (-7420.0 -125450.0))
                '((6479.50 -52390.0) (96419.50 -125449.75))
                '((110319.50 -52390.0) (200260.0 -125450.0))))

(setq contact-pad-list (list '(-113797.50 136778.5)
                '(-9957.5 136778.5)
                '(93882.5 136778.5)
                '(197722.5 136778.5)
                '(-113797.5 43228.5)
                '(-9957.5 43228.5)
                '(93882.5 43228.5)
                '(197722.5 43228.5)
                '(-113797.5 -50321.5)
                '(-9957.5 -50321.5)
                '(93882.5 -50321.5)
                '(197722.5 -50321.5)))

(setq pin-header-list (list '(-226518.0 -178149.0)
                '(-226518.0 -170529.0)
                '(-226518.0 -162909.0)
                '(-226518.0 -155289.0)
                '(-226518.0 -147669.0)
                '(-226518.0 -140049.0)
                '(-226518.0 -132429.0)
                '(-226518.0 -124809.0)
                '(-226518.0 -117189.0)
                '(-226518.0 -109569.0)
                '(-226518.0 -101949.0)
                '(-226518.0 -94329.0)))

(setq radius 317.5)
(setq pad-spaceing 5000.0)
(setq width 470000.0)
(setq height 370000.0)
(setq header-radius 508.0)
(setq header-spaceing 2540.0)

(defun make-panel (width height)
  ;; Current panel width is 470,000.0 um
  ;; Current panel height is 370,000.0 um
  ;; Make sure rectangle is centered on 0,0 in drawing.
  (setq top-left (list (- (/ width 2)) (/ height 2)))
  (setq bottom-right (list (/ width 2) (- (/ height 2))))
  (command "rectangle" top-left bottom-right "")
)

(defun make-array-holes (coordinate-list)
  ;; Parse coordinate list and draw rectangles representing holes in acrylic plate
  (if (/= (length coordinate-list) 0)
    (progn
      (setq pt0 (caar coordinate-list))
      (setq pt1 (cadr (car coordinate-list)))
      (command "rectangle" pt0 pt1 "")
      (make-array-holes (cdr coordinate-list))
    )
  )
)

(defun make-3contact-holes (center-pad-list radius pad-spaceing)
  ;; Parse center-pad-list and draw circles for 3 pin contact scheme
  (if (/= (length center-pad-list) 0)
    (progn
      (setq pt1 (car center-pad-list))
      (setq pt0 (list (- (car pt1) pad-spaceing) (car (cdr pt1))))
      (setq pt2 (list (+ (car pt1) pad-spaceing) (car (cdr pt1))))
      (command "circle" pt0 radius "")
      (command "circle" pt1 radius "")
      (command "circle" pt2 radius "")
      (make-3contact-holes (cdr center-pad-list) radius pad-spaceing)
    )
  )
)

(defun make-pin-headers (pin-header-list radius spacing)
  ;; Draw 3 1015 um hols spaced 2540 um apart, we need twelve of these along the edge of the contactor plate.
  (if (/= (length pin-header-list) 0)
    (progn
      (setq pt1 (car pin-header-list))
      (setq pt0 (list (car pt1) (- (car (cdr pt1)) spacing)))
      (setq pt2 (list (car pt1) (+ (car (cdr pt1)) spacing)))
      (command "circle" pt0 radius "")
      (command "circle" pt1 radius "")
      (command "circle" pt2 radius "")
      (make-pin-headers (cdr pin-header-list) radius spacing)
    )
  )
)

(defun C:draw-contactor-plate ()
    (make-panel width height)
    (make-array-holes array-coordinate-list)
    (make-3contact-holes contact-pad-list radius pad-spaceing)
      (make-pin-headers pin-header-list header-radius header-spaceing)
)


What was interesting to me was that adding "C" before a function makes it accessible from the command line without the lisp syntax. All other functions are accessible to the AutoCAD command line but only as S-expressions.

No comments:

Post a Comment