## Friday, September 8, 2017

### MTPA, MTPF, and Speed Range, Part 2

Previously on Motor Diddlers, we learned that interior PM motors spend most of their time under field weakening; namely, the maximum attainable torque is limited by inductance and available voltage, not necessarily by maximum allowable current. This post will cover the basic case of computing the MPTF trajectory in the absence of saturation and higher-order back EMF components.

Starting from the motor equations $$\begin{array}{lcl} \tau=\frac{3}{2}n_p(\lambda I_q+(L_d-L_q)I_d I_q)\\ V_d=R_s I_d-\omega L_q I_q\\ V_q=R_s I_q+\omega L_d I_d+\omega\lambda\\ V_s=\sqrt{V_d^2+V_q^2}\\ I_s=\sqrt{I_d^2+I_q^2} \end{array}$$ we note that in the voltage limited operating regime, maximum torque must be achieved when the voltage vector is on the boundary of the allowable area, in which case the optimization problem becomes an equality: $$\begin{cases} \frac{3}{2}n_p(\lambda I_q+(L_d-L_q)I_d I_q) = \tau_0\\ (R_s I_d-\omega L_q I_q)^2 + (R_s I_q+\omega L_d I_d+\omega\lambda)^2 = V_0^2 \end{cases}$$ If we ignore saturation, this system is the intersection of a constant-torque hyperbola (which is independent of speed) and a series of shrinking ellipses.

This system is polynomial (and in fact only a quartic) and can be solved in many ways. For example, one element of the reduced Groebner basis of the ideal generated by the two equations is the very long $$(L_d-L_q)^2(R_s^2+L_q^2w^2)I_q^4 + (L_q^2\lambda^2\omega^2+R_s^2\lambda^2+(L_d-L_q)^2(2R_s\tau_0\omega-V_0^2))I_q^2- 2\lambda\tau_0(R_s^2+L_d L_q\omega^2)+ R_s^2\tau_0^2+L_d^2\tau_0^2\omega^2$$ where we have included the factor of $$3/2n_p$$ in $$\tau_0$$ for brevity's sake. The roots of this polynomial are easily found with a variety of numeric or analytic methods; in the case of multiple real solutions the correct one is the $$(I_d,I_q)$$ vector with the shortest length.
Unfortunately, the system is no longer polynomial if the motor saturates (that is, $$L_d$$ and $$L_q$$ are functions $$l_d(I_d,I_q)$$, $$l_q(I_d,I_q)$$ of the axis currents). In order to solve the system in this case, we will have to turn to more complicated (and less reliable) numeric methods, the nature of which will be the subject of the next post in this series.

## Sunday, September 3, 2017

### Focusing on the Ground

Suppose we have a view camera and we wish to focus on a horizontal plane. More precisely, let the center of the lens $$O$$ be $$a$$ above the ground, and suppose the rear standard makes an angle $$\theta$$ with respect to the horizontal. We wish to find the angle $$\alpha$$ that the front standard must be tilted at to focus on the ground.

By the Scheimpflug rule. the rear standard, front standard, and horizontal intersect at a point $$S$$. By the hinge rule, the front focal plane, the horizontal, and the plane through $$O$$ parallel to the rear standard are concurrent; this is true if and only if the intersection point $$H$$ of the horizontal and the plane parallel to the rear standard lies at a distance $$f$$ from the front standard, where $$f$$ is the focal length of the lens.

We have:
\begin{array}{lcl}
O'S = a / \tan{\alpha}\\
O'H = a / \tan{\theta}\\
SH = O'S - O'H = a(1/\tan{\alpha} - 1/\tan{\theta}) = a \left( \frac{\cos{\alpha}}{\sin{\alpha}} - \frac{\cos{\theta}}{\sin{\theta}} \right)
\end{array}
This means:
\begin{array}{lcl}
f = SH\sin{\alpha} = a\sin{\alpha} \left( \frac{\cos{\alpha}}{\sin{\alpha}} - \frac{\cos{\theta}}{\sin{\theta}} \right)\\
\frac{f}{a} = \cos{\alpha}-\frac{\cos{\theta}}{\sin{\theta}}\sin{\alpha}\\
\frac{f}{a}\sin{\theta} = \cos{\alpha}\sin{\theta} - \sin{\alpha}\cos{\theta} = \sin{(\theta-\alpha)}\\
\theta-\alpha = \arcsin{(\frac{f}{a}\sin{\theta})}\\
\alpha = \theta-\arcsin{(\frac{f}{a}\sin{\theta})}
\end{array}
In other words, the angle between the front and rear standards is $$\arcsin{(\frac{f}{a}\sin{\theta})}$$. This is pretty neat; in particular, for small magifications we can say the ratio of  of the sines of the angles is approximately equal to the magnification of the camera.

## Tuesday, August 22, 2017

### Obligatory 2017 Eclipse GIF

Somehow this endeavor went better than planned, I was able to not only get to the site successfully and make it through traffic, but also get the tracking mount to track.

There was an "urp" moment when I fumbled and disconnected my A7II from the remote shutter app during totality, and another "urp" moment when I panicked and complete forgot about proper exposure times and such, but 1/80 turned out OK and the raw files have enough exposure latitude to do a bit of HDR if need be...

 A7II and Celestron C5 w/0.63x focal reducer (~750mm f/6.3), Spectrum glass filter, 1/80s ISO 100

## Sunday, August 13, 2017

### Super Plumbing

The cadet racing kart chassis we were working with had no front brakes. This was a problem, because our stopping power was already traction-limited at the rear wheels, and more time spent stopping meant less time accelerating.

Front brake conversion kits exist, but are rather expensive. Undaunted, we bought some generic moped calipers, proclaiming that "we'll figure out a way to mount them".

Ben came up with a pretty good way to mount them:

The stock direct spindle mount front wheels were replaced with a set of hub-mount rear wheels, and new hubs with 17mm bearings were made to mount them to the spindles. The arm that holds the caliper is centered using the precision-machined spindle shaft (which is the only precision surface in the kingpin assembly). Finally, a cross-piece is made which bolts to the arm and prevents it from rotating around the spindle.

Everything was made on the MITERS CNC (a mid-90's Dyna-Myte converted to LinuxCNC), and the mounts worked great.

The next step was to fill the brakes. Initial attempts were made to drive the two front calipers and the rear caliper (which had two pistons) using a single master cylinder:

 Nope

This proved to be exceedingly unsuccessful; not only did the master cylinder have borderline displacement to drive four pistons, getting the air out of the loop and matching the piston travels proved to be nearly impossible. A day and a half into the ordeal, standards were lowered, and we decided to run the front and rear brakes off separate master cylinders actuated by a single pedal.

A word on the hoses: moped calipers take banjo bolts (hollow bolts sealed with crush washers). We used Earl's Performance braided lines to turn these into -3AN flares:

These connect to a 1/8" NPT tee:

The third arm of the tee is fitted with an NPT-to-compression adapter, which then goes to the master cylinder. A very unconventional setup, as compression fittings are not typically rated to brake line pressures. Go-karts get away with it with a combination of low pressures (hundreds, instead of thousands, of PSI) and short maintenance cycles (typically a couple dozen hours of runtime per season).

## Wednesday, August 9, 2017

### MTPA, MTPF, and Speed Range, Part 1

I had mentioned in a previous post that IPM's are almost always running in the field weakened regime. That is to say, $$I_d$$ and $$I_q$$ are injected not to maximize torque per amp, but to achieve a certain torque setpoint without exceeding the maximum available stator voltage.

Recall that a sinusoidally-varying motor is modeled by:$$\begin{array}{lcl} \tau=\frac{3}{2}n_p(\lambda I_q+(L_d-L_q)I_d I_q)\\ V_d=R_s I_d-\omega L_q I_q\\ V_q=R_s I_q+\omega L_d I_d+\omega\lambda\\ V_s=\sqrt{V_d^2+V_q^2}\\ I_s=\sqrt{I_d^2+I_q^2} \end{array}$$ Suppose we have unlimited back EMF, and we wish to optimize torque per amp. There are two ways to look at this. Firstly, we could $$\mbox{minimize } \begin{cases} I_d^2+I_q^2\mbox{ subject to}\\ \lambda I_q+(L_d-L_q)I_d I_q=\tau_0 \end{cases}$$ Or, we could $$\mbox{maximize } \begin{cases} \lambda I_q+(L_d-L_q)I_d I_q\mbox{ subject to}\\ I_d^2+I_q^2=I_0^2 \end{cases}$$ As it turns out, the second current-first approach results in much easier math (we only need to solve a quadratic, not a quartic) at the expense of being somewhat less intuitive (it is unclear what current corresponds to what torque).

There are several ways to solve the second problem; we use Lagrange multipliers here. The Lagrangian is $$L(I_d,I_q,u)=\lambda I_q+(L_d-L_q)I_d I_q-u(I_d^2+I_q^2-I_0^2)$$ where $$u$$, not $$\lambda$$, is the multiplier.
The system of partial derivatives is $$\begin{cases} \frac{\partial L}{\partial I_d}=(L_d-L_q)I_q-2I_d u=0\\ \frac{\partial L}{\partial I_q}=(L_d-L_q)I_d-2I_q u+\lambda=0\\ \frac{\partial L}{\partial u}=I_0^2-I_d^2-I_q^2=0 \end{cases}$$ This system is easily solved by a computer algebra system or by multiplying the first equation by $$I_q$$ and the second by $$I_d$$, giving $$\begin{array}{lcl} I_d=\frac{-\lambda+\sqrt{\lambda^2+8(L_d-L_q)^2I_0^2}}{4(L_d-L_q)}\\ I_q=\sqrt{I_0^2-I_d^2} \end{array}$$ where we have picked the signs knowing that $$I_d$$ is negative and $$I_q$$ is positive.

Armed with this information we can make some plots. Plugging in the HSG data $$L_d=0.0006$$, $$L_q=0.0015$$. and $$\lambda=0.053$$ (units: Henries, Volt-seconds), we have the following plot:

As expected, $$I_d$$ is about the same magnitude as $$I_q$$ at high currents.

Perhaps more interestingly, we can get a sense of how quickly the back EMF grows in an IPM. Using the MTPA setpoints computed above, we can plot back EMF vs stator current and speed:

 Worth noting: the hump in the blue region is caused by d-axis current on the MTPA trajectory canceling rotor flux
Roughly speaking, the blue region corresponds to back EMF's achievable on a 150V bus. It is evident at high currents, most speeds in the operating range are unachievable:

A slice of the graph at 180A shows that we are forced to exit the MTPA regime at about 800 rad/s (about 2500RPM on a 3-pole-pair motor).

Even more telling is a plot of maximum achievable current versus speed:

Speeds much above 1500 rad/s are straight-up unattainable, and between 800 and 1500 rad/s, available current rapidly falls off.

We conclude that at high currents (and therefore high torques), the maximum achievable speed is highly limited (the HSG is rated to 9000 RPM at 150V). In order to achieve high speeds (and therefore high powers) we must move off the MTPA trajectory and onto a "maximum torque per flux" trajectory.

This is also why IPM voltage and current scaling cannot be treated naively! I cannot emphasize this enough - a motor rated to 50Nm and 10000RPM on a given bus voltage cannot physically achieve both at the same time. On the other hand, increasing the bus voltage not only increases the maximum achievable speed, it increases the amount of torque available at lower speeds.

The next post in this series will tackle the problem of computing the MTPF trajectory, which, as we will see, is much harder and cannot be solved analytically.

## Tuesday, August 8, 2017

### Plumbing Electrons

"Wiring is like plumbing, but for electrons"
-me, 2017

One of the things I've come to dread in any project is wiring. This particular wiring job is by no means stellar, but works well enough to be worth writing about.

Starting at the front:

The steering wheel controls consist of an e-stop and a key switch. The e-stop is wired in series with the +12V line going to the logic and by extension, the 12V supply for the internal gate drives on the power module. Hitting the e-stop shuts down the microcontroller and gate drive, which safely floats the inverter phases.
The key is wired in series with the 12V going to the contactor control line - contactor power does not go through the e-stop. As interrupting high DC link currents damages the contactor, this switch is intended to act as a last line of defense in case the inverter has failed short or otherwise stopped responding to gate drive. In normal fault situations (throttle failure, firmware error) the e-stop suffices.

From the steering wheel, two runs of McMaster 8082K37 shielded cable connect the switches to a power distribution board...

...which I swear is the only reason the go-kart thinks about working at all. The sketchy CNC'ed board replaces what would be an even sketchier mass of wire junctions.

The HV contactor is a Kilovac Csonka EV200:

The datasheet claims it is rated for dozens of interruptions at 500+A but I don't believe it. The precharge resistor is bolted directly across the contactor, which has the benefit of precharging the DC link capacitor whenever the HV connector is plugged in, and the downside of slowly draining the traction pack should the HV connector be left unplugged.

The motors are wired to the inverter via 10AWG silicone wire stuffed inside a copper braid finger-trap shield:

I am not convinced the shield is doing much (it isn't terminated on either end, and terminating it didn't seem to affect noise), but keeping the phase leads in as small of a bundle as possible is important for reducing radiated noise.The shield is sealed to the wire bundle with 3M EPS-300 adhesive backed heatshrink, which upon heating forms a tough, watertight seal glued to the shield and wires.

Moving back to the inverter:

The phase lead bundles are attached to the bus capacitor tabs by zip-ties. As much of the exposed bus bar as possible is covered in liquid electrical tape to reduce the chance of inverter-induced incidents.

The capacitor itself is mounted via standoffs and slotted tabs to the inverter block:

The image above also shows the power module control cable, which is cut short and terminated in a DB-15 connector, then run through a 20" commercial shielded DB-15 cable to the logic board:

The Phoenix Contact cable was irritatingly expensive (~\$50 on eBay), but it was rather difficult to find good shielded 15-wire cable.

Finally, the throttle is actuated through a bowden cable attached to the original go-kart throttle pedal (which operated a mechanical throttle on a carbureted engine). The throttle sensor is a GM brake position sensor:

The bowden cable is crimped to a standard copper ring terminal; please don't do this for an actual brake! It is only acceptable here because a cable failure causes the throttle to return to an off-position.

### Sonata Pack Module Testing

 I'd upload a 3-angle view if Blogger had a working gallery function
Dane was kind enough to run some tests on an 8S submodule from the Hyundai Sonata pack using is datalogging-enabled Hyperion charger.

This pack is quite aged, showing only 4Ah out of the 5.3 rated amp-hours.

However, pack impedance is promising, hovering between 10 and 15mohm for most of the SOC - not bad at all for a 5.3Ah 8S pack.

The module under test was also extremely well-balanced:

As would be expected from an automotive vendor with access to millions of cells.

The conclusion: you probably want an A-grade pack, but a B-grade pack is completely usable, albeit with degraded performance.