How many poles is my motor? A simple method using LISP scripts.

Full disclosure, I didnt make this. It was sent to me by a fellow named Austin (WhoGene) who is working on some VESC EUC stuff. I believe he wrote the script, but i’m not certain. Uploading this here since I see people asking this very question when they have a unique (or hub) motor setup

Script is below. This will do a complete rotation of your motor. If your motor stops at the same place you started (Full 360 degree rotation), your pole count is correct. If your motor doesnt, your pole count is wrong. Keep changing it till it’s right. That’s all. Have fun.

Note: If you are running a setup with a gear reduction (i.e not direct drive/hub esk8), watch your motor for rotation, not the wheels.

Requirement: VESC Firmware 6 and above

Script
(def amps 20)
(def dist-st (get-dist))
(def dist (- (get-dist) dist-st))
(def erpm 0)
(def last-dist 0)
(def circ 0.7979)


(defun startup ()
(progn
(foc-openloop (* amps 0.25) 0)
(sleep 0.5)
(foc-openloop (* amps 0.25) 0)
(sleep 0.5)
(foc-openloop (* amps 0.5) 0)
(sleep 0.5)
(foc-openloop amps 0)
(sleep 0.5)
(def ready 1)))
(startup)

(spawn (fn () (loopwhile (= ready 1)
    (progn
    (if (<= dist circ) 
            (if (or (> 0.02 dist) (> dist (- circ 0.03)))
                (foc-openloop amps 50) 
                (foc-openloop amps 600))
            (progn 
                (foc-openloop amps 0)
                (sleep 0.5)
                (foc-openloop amps 0)
                (sleep 0.5)
                (foc-openloop amps 0)
                (sleep 0.5)
                (foc-openloop amps 0)
                (sleep 0.5)
                (foc-openloop amps 0)
                (sleep 0.5)
                (foc-openloop amps 0)
                (def dist-st (get-dist))
                    (def dist (- (get-dist) dist-st))
                    (def erpm 0)
                    (def last-dist 0)))
    (def dist (- (get-dist) dist-st))
    (if (not-eq dist last-dist)
        (progn
            (def erpm (+ erpm 1))
            (def last-dist dist)
        ))
    (sleep 0.001)
    ))))
2 Likes

yeah thanks
poles

1 Like