Sunday, April 5, 2015

RSS / humans?

This is a post that I had meant to publish 2 or 3 years ago and had forgotten about. Having found it in my unpublished drafts, I decided that it was still interesting, even if the "demise of Google Reader" is no longer fresh news

The original post follows

There has been some noise, since the demise of Google Reader, about whether RSS is "dead." I think much of the discussion on the topic is somewhat missing the point : even if RSS feeds are not something that normal humans want to collect, curate, subscribe to, and aggregate, RSS is still a great interchange format for computer programs that collect, curate, subscribe to, aggregate, and repackage RSS feeds.

Case in point:

A nice thing about using RSS for such a purpose is that the content emitters don't have to run the same software or the same systems or even be run by the same people as the computer program reading the RSS. Now, of course, not all content emitters want their content to be scraped, collected,curated and repackaged. But, for those that do, RSS (or Atom) provide ideal means of interchange. Note, also, that the example above is probably not anywhere near the most efficient or scalable way to repackage a feed from one source in order to re-display in another.

I believe that this is a corollary to the idea that Twitter is the ideal medium for machines to broadcast short updates to one another and to humans in a medium that is authenticated, but not private.

Homebrew solar battery charger

A neighbor of mine recently build a solar-powered battery charger out of a variety of parts, including an old computer monitor stand as the stand for the solar panel

He was particularly proud of his energy efficiency, his use of predominantly analog components, even for tasks that seem akin to "logic", and the various clever tricks he used to achieve zero quiescent current

He admitted that a more digital (and, particularly, microprocessor-based) design would have been easier and more flexible, but contended that the level of efficiency he achieved would have been impossible to reach with anything other than analog design

His device had a serious of modular adapters for different levels of power, including USB, Sony laptop, an extra laptop battery, and a household-voltage AC adapter (capable of running a fan

Unfortunately he didn't have circuit diagrams to share, having designed most of the thing primarily in his head, and directly in circuitry.

Saturday, June 28, 2014

AC / DC

I recently had a conversation with a friend, who is interested in third world economic development, "leapfrogging" technologies, and energy, about AC vs. DC for electrical power transmission and distribution. He asked me for my further thoughts on the matter, so I will put them here, along with some caveats about what things I know that I don't know. I invite readers who know more about the topic to leave corrections and additions in the comments to this post.

A bit of history

The debate about whether to transmit power as AC or DC raged in the early part of the 20th century with Thomas Edison advocating for DC transmission of electricity, and Tesla advocating for AC. At the time, AC was adequate for most household applications (many of which involved the use of electrical current to produce heat, or to produce lighting through heat, and thus didn't care about the direction in which current travelled at any given time) and was vastly easier to efficiently step up or down in voltage, allowing for efficient transmission of power over long distances. One exception was that it was easier to build a variable-speed electric motors to run on DC (it is trivial to build single-speed AC motors, especially if one has 3-phase AC power, which is generally what is transmitted over longer distances, and what is supplied to industrial facilities). Older elevator technologies (circa early 1900s) tended to use DC motors, and tended to be installed in dense urban cores, where a large number of electricity customers could be served without the need for long-distance transmission. For these reasons, small DC power grids existed in many of America's large cities for decades after AC otherwise won what was known as the "war of the currents". See, for instance

To make a long story short, one generally wants low voltages, and the capability of producing high currents, at the place where the electrical energy is used. But it is far more efficient to transmit electrical power at high voltage (and comparatively low current). AC is fairly easy to step up and down in voltage using transformers. It has not, historically, been easy to do the same thing with DC power.

Advantages of DC in the modern world

One drawback to AC power stems form the fact that modern power grids are extremely interconnected. Placing two or more AC power sources on the same network requires that the sources be synchronized. This requires some form of dynamic control. A simple thought experiment should reveal why two out-of-phase AC sources wired to one another effectively create a short. Dealing with these synchronization issues has led to some fascinating control theory papers, but I could understand why practical engineers might want to dispense with these problems altogether and transmit electrical power via DC current. I don't know how much more complicated AC synchronization problems become when individual consumers are allowed to produce their own power and feed it back into the grid.

As an extra piece of terminology (and one which might be very important to understanding other discussions of the electrical grid), power engineers divide the grid, conceptually, into two distinct sorts of networks.

  1. Transmission networks carry high-voltage electricity over long distances and interconnect different power plants on the grid. It is my impression that AC synchronization problems generally occur in the transmission network portion of the power grid.
  2. Distribution networks carry lower-voltage electricity from the transmission networks to end users, either industrial, commercial or home consumers. It is my impression that there is generally only one logical path for power to take between any two points on the distribution network (with the note that a "path" in this case might be 2, 3 or even 4 wires, depending on the form of the AC current).

Further, modern appliances are quite different from those of the days of Edison and Tesla. Computers and other digital equipment generally require DC power sources (the "power supply" of your desktop computer contains a transformer, a voltage rectifier to convert AC to DC and a voltage regulator to maintains the voltage of the supply at a steady level, while your laptop likely has the same equipment mostly embedded in its power chord). LED lighting works with DC current (any LED light that you can screw in to your conventional lighting fixtures must come with, at bare minimum, a voltage rectifier to convert the AC of your light fixture into DC for the LEDs). Today's TVs, being digital appliances, require DC power internally.

DC is of particular appeal to off-grid power systems for a variety of reasons. For one thing, solar cells naturally produce DC current. Most conventional electrical power generation (coal, oil, nuclear and the sorts of large solar installations that use mirrors to heat water) at some point heats water to turn a turbine which turns a generator. It is fairly easy to design such a system to produce 3-phrase AC power. I am not sure how difficult or easy it is to make such a system generate DC without using a rectifier. Equally important, perhaps even more important, to off-grid systems is that DC is required to charge backup batteries, and is the natural output of chemical batteries. An off-grid power system using solar for energy generation and batteries for storage will naturally want to be DC. I note here that one should be wary about using off-grid solutions with battery backup to leapfrog economic development in the developing world : the most economical rechargeable battery solution at this point is still lead-acid batteries, which come with a host of problems. I will try to see if I can dig up resources on it. One might want to ask whether solar generation with battery backup becomes more feasible when all of one's appliances become much lower power (lighting could be LED-driven, heating is less of an issue in parts of the developing world, computing and communications are becoming more efficient everyday. I still wouldn't want to run my washing machine off of batteries though). Battery technology is also rapidly improving, driven by consumer demand for things like smartphones and laptops with long battery life.

A revolution in transmission technology

One of the main advantages of AC current for electrical distribution, as mentioned above, is the ease of stepping voltages up and down, to allow transmission to occur at very high voltages, while giving end-users safe and convenient low-voltage electrical energy with high current capacity. Safety aside, giving high-voltage to end users would be infeasible for a variety of basic electrical reasons. Common materials, such as air, behave differently under high voltage and would need extra considerations.

But, because of the problem of AC generator synchronization, utilities have found it to be desirable to have their large high-voltage interconnects run on DC power, which is much easier to synchronize and coordinate.

Thankfully the technology to convert high-voltage AC (HVAC) to high-voltage DC (HVDC) and to step DC voltages up and down have improved radically during the semiconductor revolution, as technologies originally designed for lower-power applications have found their way into the world of power electronics. A good summary of the state of things is provided by Wikipedia : see http://en.wikipedia.org/wiki/High-voltage_direct_current. Photographs of some of these new pieces of equipment are spectacular in their scale and design, see http://en.wikipedia.org/wiki/File:Pole_2_Thyristor_Valve.jpg . One of the more fascinating pieces of high-voltage DC interconnect technology is the proposed Tres Amigas Superstation in Texas which plans to use superconducting wires to transmit DC current to connect the three major energy grids in the US.

Summary

Advantages of AC current

  • Ease of stepping up/down voltage (for efficiency in transmission)
  • Ease of making a single-speed motor (for instance, your coffee grinder)
  • AC is the natural output of the sort of electrical generator I would design were I to design a generator
  • Adequate for heating applications

Advantages of DC current

  • Avoids the AC synchronization problem
  • Good for variable-speed motors (anything from the motor on the Honda insight, to the stepper motor in your hard drive, to wheelchair motors, and I think even washing machine motors).
  • What batteries want to be charged with
  • What batteries output
  • What solar cells output
  • What computers and digital electronics want to work with

Technologies to watch if one is interested in these issues

  • High-voltage rectification
  • High-voltage DC - DC step-up / step-down
  • Battery technology
  • Socio-economic situations that might produce micro-grids
  • Technology that allows households to accomplish basic tasks using less power (I suspect there is little to no room for improvement in this area for things like electric stoves and electric heaters, but quite a bit of recent progress for communications, computing, lighting and entertainment. I am curious as to basic things like "can one make a significantly lower-power automatic washing machine")

One thing I have not given much thought to is which form of power is easiest for people with little electrical knowledge to effectively deploy in micro-grids, and what sorts of technologies could change this.

Wednesday, August 14, 2013

Gray Codes

Recently I was thinking about Gray codes (http://en.wikipedia.org/wiki/Gray_code).

Gray codes are, effectively, a way to count from 0 to (2n-1) on an n-bit counter while only flipping 1 bit at a time. Most simply, they are mappings of the form f : ℤ(2n) → ℤ(2n) such that for an k ∈ ℤ(2n), f(k) and f(k+1) differ by exactly 1 bit.

These have a variety of uses, for instance, in robotics one can make an n-bit encoder wheel such that a smooth rotation of the wheel only changes one bit at a time, avoiding ambiguities when multiple detectors change their state at the same angle and give wildly inconclusive readings : see https://www.google.com/search?q=gray+code+encoder+wheel&safe=off&source=lnms&tbm=isch.
More examples can be found on wikipedia
The context in which they have come up the most often in my life is when thinking about how to enumerate all possible 2n settings on an n-bit dip switch (http://en.wikipedia.org/wiki/DIP_switch). I don't like having to flip k switches to have to go from the setting corresponding to (2k-1) to 2k for every integer k ≤ n, but I would also like to be able to compute which bit to flip next without having to expend a lot of mental effort. I recently came up with a trick for this. I am likely not the first person to come up with this trick, but I couldn't find it written up anywhere else, so I am blogging about it


Method for finding the next bitstring in a Gray Code

To iterate through an n-bit Gray code do:
Starting at 0, repeat the following steps

  1. On every even iteration (we number our iterations starting at 0), flip the rightmost bit of the current number to get the next number
  2. On every odd iteration, find the rightmost 1 bit (the rightmost bit that is set to 1) in the current number. Flip the bit to the left of that to get the next number. If there is no bit to the left (if the current number is 2(n-1)) flip the remaining 1 to get back to 0
  3. .

If you get lost, simply count the number of 1s in the current number. If it is odd, you are on step 2. If it is even, you are on step 1.
Reversing the order of the steps traverses the Gray code in reverse order.


Background on "reflected binary Gray codes"

One of the earliest examples of a Gray code is what seems to be called a "reflected binary Gray code".
Here is how it works :
We will construct it on n bits recursively as a sequence of 2n bitstrings each of n bits. The kth bitstring in the sequence will be the number mapped to by k.

  1. The reflected binary Gray code on 1 bit is just the sequence [0, 1].
  2. To get the reflected binary Gray code on n bits, compute the code on (n-1) bits, add a leading 0 to each bitstring, then compute the code on (n-1) bits in reverse order, adding a leading 1 to each bitstring. Concatenate the resulting sequences (putting the "reflected" (or reversed) sequence after the forward sequence)
This yields a Gray code because : (we induct on the number of bits in the code)
  • Each n-bit number is included once in the n-bit code. Inductively the rightmost (n-1) bits of this number must occur in the code on (n-1) bits. Either a given number starts with a leading 1, putting it in the second half of the sequence, or it starts with a leading 0, putting it in the first half of the sequence.
  • Each two consecutive numbers in the n-bit code differ by one bit. Either their leading (leftmost) digits are the same, in which case they differ by 1 bit in their rightmost (n-1) bits (by induction), or their leading (leftmost) digits differ, in which case the bitstrings differ by 1 bit (by construction).

It is well-known that translating from the kth bitstring in this form of Gray code to the integer k can be done by recognizing that the ith bit of the number k is equal to the xor (sum modulo 2) of the leftmost n-i bits (assuming the rightmost bit is bit 0) of the kth bitstring in the Gray Code. TODO : replicate proof(s) here : Proof via matching to above construction, and proof by showing this to be a bijection, and showing that succ only filps one bit at a time


Proof that the algorithm presented here works

Reversing the order of operations reverses the order of traversal

Because each operation is just a "flip" (addition modulo 2) of a bit, each operation is it's own inverse. Since there is one unique "rightmost bit set to 1" in any number, repeating the two steps in reverse order will apply the inverses to the last sequence of steps required to get to the current number, which should reverse the iteration. ∎

The algorithm described at the top of this post ("Method for finding the next bitstring in a Gray Code") replicates the "reflected binary Gray code" described above.

Assume this is true for m-bit Gray codes for any m < n. Show for n by induction.

  • The first 2(n-1) steps are identical to the steps in the case for (n-1) bits. These match the first 2(n-1) steps of the reflected binary Gray code (by induction).
  • After this we are left with a single bit set to 1 in the next-to-leftmost bit. Since we've taken an odd number of steps, the next step is to flip the leftmost bit to 1. From here on, we are replicating the case for (n-1) bits, but in reverse (see above) and with the leftmost bit set to 1.

Proof by XOR

You can also prove this using the XOR fact stated in the section on reflected binary Gray codes. Incrementing a regular binary number involves either
  • If the rightmost bit is 0, flip it to 1. In the Graycode version, this corresponds to "If there are an even number of 1 bits, flip the rightmost bit".
  • Otherwise (if the rightmost bit of the number is 1) flip the rightmost 0 to 1, and flip all 1s to the right of it to 0 (i.e. ripple-carry). In the Graycode version, this corresponds to "If there are an odd number of 1 bits, flip the bit 1 to the left of the rightmost 1."



Example

Start with
0 0 1 0 1 1 0
Since there are an odd number of 1s, we are at the "odd" step of the iteration.

So we find the rightmost 1 bit.
0 0 1 0 1 1 0
          ^
find the bit 1 to the left of it
0 0 1 0 1 1 0
        ^
and flip that
0 0 1 0 0 1 0


Then we flip the rightmost bit (even iteration).
0 0 1 0 0 1 1


Now find the rightmost 1 bit.
0 0 1 0 0 1 1
            ^
and flip the bit 1 to the left of it.
0 0 1 0 0 0 1


Then we flip the rightmost bit again.
0 0 1 0 0 0 0
and so on.

Monday, April 15, 2013

Tuesday, October 23, 2012

Saturday, October 20, 2012

Sphere-based drive trains

During a recent idle moment, I started thinking about spherical wheels, spherical gears (I think that one might want to use 3 spheres in order to transmit rotational motion from one sphere to another, as opposed to 1 conventional gear for the same purpose) and (most interestingly) omni-directional electromagnetic motors with spherical (rather than cylindrical) shafts.

Here is (roughly) how the motor would work :

 Make the "shaft" a sphere (d'uh) and cover the surface with a pseudo-random pattern of permanent magnets.

 Put the sphere-shaft in spherical bearings, and surround it with a regular pattern of controllable electromagnets.

 At every time-step, solve for the set of magnetic fluxes (or electric currents) on the pattern of electromagnets to best apply the appropriate delta rotation to the shaft. Or, simpler yet, render (draw) the pseudo-random pattern of magnets on the shaft, rotated by the desired amount, using the controllable electromagnets.

Presumably some clever electrical engineering could measure and/or estimate the orientation of the spherical-shaft by the induced current on the outer electromagnet coils (at least while the shaft is moving). Or, hey, one could just draw a recognizable pattern on the sphere-shaft and use light sensors/emitters to estimate shaft orientation.