Long time no see

So hello again. Thought it was past time to make another post.
Current projects that have been happening/ happened are:
-A motor winding pattern generator for an arbitrary  number of phases.
It was written in python and was made in a fairly awkward form, but I ended up deleting some of it in frustration while rewriting it.

Idea behind a pattern generator for a motor:
A permanent magnet motor consists of magnets and solenoids in some circular configuration. In order to produce torque the solenoids must be turned on when they are in the proper position. This is where the winding pattern generator comes in it creates the winding 'pattern' so that when voltage is applied to any particular phase of the motor each pole on that phase produces a force in the same direction  this goes back to one of my last posts when I made a motor. This bring about babble of electrical angles which I talked about for a moment in this post. 2pi rads of electrical angle per pair of magnet poles (or you can think about it in degrees if you like), this gives a whole crap load of radians per motor but since our magnets are tessellate (positive pole up, then negative, then positive.....repeat) we really only care about how things line up within a single 2pi rads interval. So when talking about electrical angles it is useful to think of them as electrical angle mod(2pi), I kind of like to think of it as walking off the right edge of a TV screen and coming back on the left side.

This makes things easier to count and think about positionaly and bring up the question:
When do we actually want to turn on a phase?
And depending on what the goal iswant to do that answer can actually not be that straight forward. However in most cases you probably only care about getting maximum torque out of your motor. In order to produce the maximum amount of torque you want to turn your motor on when it is directly between the pole of two magnets.

This corresponds to an angle of either 0 or pi depending how you want to look at it. So how do you get all of your poles in one phase to produce torque in the same direction? By applying voltage to all of the poles in a certain interval at the same time. Ideally all of the poles in the phase would be at the same electrical angle when turned on. This ensures that they all push in the same direction.  By defining a certain window of electrical degrees where sum((nth pole torque) for 0 to n poles)>0 at all times in that interval. i.e. the motor will always be pushing in the same direction.

This pattern can be calculated without too much work below is some fake code I wrote to calculate the winding pattern for an arbitrary phase motor of n even poles, and an arbitrary number of slots.
Please forgive the bastardization of code, it was really an organizational exercise to make sure the motor winder is written properly next time it gets written...hopefully this is not too nonsensical looking.

Psuedo code for motor winder:
#pretend the person already entered the number of poles, number of phases and number of slots(stator poles) and they make physical sense:

#find the amount of electrical degrees to alot to each phase interval
#and the electrical degrees per slot
phase_slice = 180 / phase_num
slot_slice = pole_num * 180 /slot_num

#map the values out over all the slots and phases so you have each phase interval
#and the electrical and of each slot
slot_angles = map(lambda(n): (n * slot_slice) % 360): range(slot_num))
#phase intervals mapping not needed but good to look at sometimes to make sure everything makes sense
#phase_intervals = map(lambda(n): ( n * phase_slice) % 180):  range(phase_num))

#this is the heart of the program it decides the phase number and the direction in which to wind each phase slot

defun pattern_picker (slot_angle[n], phase_slice)(
    #makes and integer of each slot corresponding to the phase interval it lies on
    phase = floor(slot_angle[n] % 180 /phase_slice)
    #decides the direction of each slot winding on the stator
    (if even?(slot_angles[n])
   then (if (slot_angle[n] > 180)
       then (case = "-") else(case = "+")))
    (if odd?(slot_angles[n])
    then (if (slot_angles[n] > 180)
       then (case = "+") else(case = "-")))

#outputs the direction and phase for a given stator slot
return( string(case)+string(phase))

#gets the direction/phase for each slot
winding_pattern = map(pattern_picker(slot_angles[n], phase_slice): slot_angles, repeat(phase_slice))

print("Behold! Your winding pattern sir: \n")
for slot in range(len(slots)):
(if (slot != len(slots)) then (print(winding_pattern[slot] + ", ")
    else (print(winding_pattern[slot] + "... the end"))

I'll babble more about this later and potentially post some code which will actually calculate a winding pattern.

Edit: I tweaked the code upon realizing I made a few mistakes in the pattern picker funtion with regards to the variables being passed in as well as the definition of the phase number.