Jeff Epler's blog

19 August 2016, 14:38 UTC

Will an Electric Vehicle save on CO₂ emissions anyway?

Warning: Betteridge's Law Applies

tl;dr: Compared to a hybrid like the Toyota Prius, the incremental emissions for a Tesla using typical US electricity sources are higher. They just don't occur at the car's tailpipe.

After recently asking whether a person with my habits could ever save money driving a Tesla instead of a Prius, I also wondered about per-mile emissions. Others have investigated the extra costs of EV manufacture and disposal (many elements of which apply to a hybrid as well), while my research is only about the incremental CO₂ emissions created by whatever energy inputs the vehicle needs.

Here's the spreadsheet itself, which includes links to sources for each number.

The top result is that the source of electricity makes a huge difference: China (major electricity source: coal) has 9x the emissions per kWh than France (major electricity source: nuclear). Canada has under 50% the emissions of the US, and I was happy to see that my local electrical utility is 10% under the US national average.

Using EPA fuel economy and the 2015 US mix, I calculate 47.7 lb CO₂/100 miles in the Tesla, and 40.0 in the Prius.

Of course, if you're comparing the Tesla to an "average" US car, it's a different story: The 2014 fleet economy for passenger cars is 31.5MPG, leading to emissions of 71.11 lb CO₂/100 miles.

If you're living in a country that has more nuclear or "renewable" energy, like France, you'll also come out ahead: with only 0.26 lb CO₂/kWh in 2008, a Tesla would put only 21% as much CO₂ into the atmosphere as a Prius running on gasoline.

I also took a stab at how Clinton's clean energy plan would change the numbers. My first guess is that it woud lower the lb CO₂/kWh by around 1/3, which still doesn't make us as clean as Canada's 2008 mix.

Finally, I checked how a Prius would do running on E85, assuming that carbon-neutral ethanol production were actually possible. This brings the prius down to 8.34 lb CO₂/100mi, within spitting distance of the cleanest electricity of countries I surveyed, 8.21 lb CO₂/100mi running a Tesla off the French grid.


17 August 2016, 12:51 UTC

Imagine (software developer version)

Imagine there's no malloc,
It's easy if you try
No free below us,
Above us only sky
Imagine all the software
Working right today

Imagine there's no build step
It isn't hard to do
Nothing to cause link errors
No compiler flags too
Imagine all the software
Passing its testsuite

You may say I'm a dreamer
but I'm not the only one
I hope some day you'll join us
And the world will live as one

Imagine no mutexes
I wonder if you can
No atomic intrinsics
Threadsafe data structures
Sharing all the world

You may say I'm a dreamer
but I'm not the only one
I hope some day you'll join us
And the world will live as one

With apologies to John Lennon


11 August 2016, 22:07 UTC

Does an electric car make economic sense?

Warning: Betteridge's Law Applies

I drive 8000 miles a year in a car with 45MPG actual fuel efficiency (2013 Prius). We paid somewhere around $23000 for it. If I drive this car for 15 years, I'll buy around 2700 gallons of gas.

Compare this to the (discontinued) Prius Plugin Hybrid with MSRP of about $30000. Imagine that I could have done all my driving in electric mode, and that its efficiency is ∞MPGe. I'd break even on the $7000 higher initial price if the average gas price is $2.56. Sounds plausible that I could save money that way, right?

But of course I couldn't go everywhere in "all-electric" / "charge depletion" mode, probably only about 2000 miles/year out of my 8000 miles/year would fall into this category (in-city driving 200 days a year at 10 miles/day). So now I'm only saving only about 670 gallons of gas *OVER THE COURSE OF OWNING THE CAR FOR 15 YEARS*. This is only break-even if gas is $10/gallon.

But of course, the plug-in hybrid is not ∞MPGe, it's 110MPGe, so I'm still buying electricity equivalent to 270 gallons of gas over the course of owning the car to drive those 30000 miles, meaning I only saved 400 gallons of gas, making the break-even gas price $17.50/gallon.

But MPGe is actually "miles per 33.7kWh". 33.7kWh of electricity costs $3.17 in my local market at summer rates, or $1.88 at winter rates, an average of $2.31 (only 4 months are "summer"). So that's $623 in electricity to operate the thing in electric mode for 30,000 miles, pushing the break-even gasoline price up to $19.

And don't get me started on the all-electric Tesla Model S, the car that costs as much as two or three priuses and still can't drive from Lincoln to Denver. Or rather, I could, if I stop to use charging stations at a few key locations on I-80, which from what I read can charge a car at a rate of about 30 miles per hour...


10 August 2016, 11:56 UTC

LinuxCNC on Beagle Bone Black

Last month, I worked on Xenomai support in LinuxCNC just so I could list it as a feature bullet. What should happen this month but a visit from old-time LinuxCNC developer jmk, who was trying to get a HAL-based virtual control panel running on a Beagle Bone Black, for which there's a quite decent Xenomai kernel build available. (I think we have the MachineKit folks to thank for that)

By my standards, the Beagle Bone Black is quite under-powered; for instance, its 512MB RAM is too little to even build some of the source files in LinuxCNC; and even if it did (with an added swap file, for instance) the build times can be nigh-intolerable.

So starting with a wheezy image with xenomai kernel intended to run MachineKit, together we've hacked together a configure time flag to add the configure flag "--hal-only", and ported the MachineKit hardware driver "hal_bb_gpio" over to LinuxCNC. For the moment this lives in the branch jepler/master/halonly but hopefully it can be cleaned up and merged to master branch before long.

And what is jmk working on? Apparently it's something that will be used by the Tesla Orchestra in an upcoming performance.


9 August 2016, 1:54 UTC

LinuxCNC: Which kernel, which package?

It's getting complicated to decide how to install LinuxCNC! With the upcoming 2.8 release, you will have your choice of support for three realtime kernels (and generic/vanilla kernels for simulator mode):

  1. RTAI
  3. Xenomai

Like LinuxCNC 2.7, there are two package flavors:

  1. linuxcnc (kernel-module-based)
  2. linuxcnc-uspace (userspace-based)

And here's a matrix of kernel support vs package flavor that we hope to have in 2.8:

Kernel flavor
LinuxCNC PackageRTAIPREEMPT-RTXenomaiGeneric

.. there are two main caveats to that list:

  1. Running kernel version must exactly match what LinuxCNC was compiled for (one of the biggest hassles with RTAI using the kernel module model)
  2. linuxcnc-uspace Packages from buildbot don't actually have RTAI support now, but self-built packages will, as long as the package with lxrt development files is installed (rtai-modules-*)

As you can see, linuxcnc-uspace is better (at least on paper) than the old rtai-kernel-based approach, it's more versatile in terms of RTOS support, and it's never tied to a specific kernel version.

One thing we don't know yet is: how much additional latency or jitter is introduced by using LXRT ABI instead of kernel module ABI? I hope it's little enough that we can consider dropping the kernel module realtime model altogether for LinuxCNC 2.9 or so.

So I propose the following steps for deciding which flavor of LinuxCNC to use, if you're building our master branch:

  1. Choose linuxcnc-uspace with the realtime kernel of your choice
but if you experience that linuxcnc-uspace + RTAI gives substantially worse performance than linuxcnc kernel-mode + RTAI, please drop us a note about it before we go dropping that functionality.


26 July 2016, 16:23 UTC

Star Trek: Beyond as a 4-episode mini arc

Warning: Spoilers for the recently-released Star Trek: Beyond movie

S3E9: Toxic Humanity

Cold open: Same as in ST:B.

One of the Teenax who attacks Kirk becomes ill after the attack, because human blood is toxic to Teenax. McCoy places Teenax (all the Teenax are called Teenax; they insist that as they speak it, each name is distinct) in stasis but cannot cure it. However, the Fabona (who look like 9' tall sunflower plants) offer a second artifact with healing powers. This time, the Teenax choose to overlook the fact that the artifact may be "stolen" in order to save the life of their countryman.

B plot: Scotty plays a practical joke on Keenser, but its race is unfamiliar with the concept. Keenser takes it in stride, but an attempt to reciprocate the practical joke goes awry.

B2 plot: Kirk's upcoming birthday; subspace communication with Commodore Paris about promotion to a desk job.

S3E10: Starbase Boondoggle

Main plot: Commander Spock learns of the death of Admiral Spock. Nyota prepares Plomeek soup for him, but the gesture enrages Spock who loses control of his emotions for a moment. Nyota forgives him, but Spock decides that he must end his romantic relationship with her and rededicate himself to Vulcan cultural principles and the creation of a New Vulcan. She offers to return the necklace, but he refuses it.

B plot: Billed as the Federation's largest engineering effort to date, Yorktown Station is not all it is hyped to be. Problems range from wonky comms to broken replicators. "At least the gravity stayed on this time!" quips Sulu's partner (whose name we actually learn) when the lights fail during a romantic dinner.

S3E11: Altamid Part 1

More or less follows the movie from Kalara's arrival at Yorktown Station to Krall's "Cut her throat" or maybe the saucer section impact depending on pacing. Makes clear a couple of things in my headcanon, the foremost being that Enterprise only recalled a partial crew for the mission, since it was to be of short duration.

S3E12: Altamid Part 2

More or less follows the movie until Krall's attempted deployment of the bioweapon in Yorktown. Commander Finnegan, who has been dealing with its broken systems for months, knows how to shut down the supposedly failsafe life support system: just change the settings to specify earth-standard atmosphere (21%), instead of the current oxygen-rich (28%) mixture. Krall, trapped in the circulation chamber, commits suicide by alien bioweapon rather than receive Federation "therapy".

As we watch the time-lapse construction of NCC-1701-1, voice overs:

Kirk: That ship is beautiful. Too bad I'll never fly her.
Paris: She's is yours if you want her. Perhaps your promotion was just a glitch in the Yorktown's computers

Spock: [stilted language that he was "illogical" to dump Nyota]
Nyota: If that's an apology, I accept.

(My friend Michael wants me to add: and then they find out the new Enterprise is too big to fit in the passage from the construction dock to space)

Here ends season 3


23 June 2016, 11:50 UTC

Installing and testing jessie-backports realtime kernels from debian archive


Kernel 4.1, 4.4, and 4.6 all give similar latency on my i7-4790k system running in 64-bit mode, at least for short (<10 minute) tests.

How to use backports

Or, rather, how *I* used backports..

First, find the kernels (or other packages) in the search interface at In the case of jessie-backports, look for versions that say ".bpo" or ".bpo8".

I found 3 realtime kernels that seemed interesting, based on 4.1, 4.4, and 4.6, so I came up with these lines for a file in /etc/apt/sources.list.d:

# Kernel 4.1
deb jessie-backports main
deb-src jessie-backports main

# Kernel 4.4
deb jessie-backports main
deb-src jessie-backports main

# Kernel 4.6
deb jessie-backports main
deb-src jessie-backports main

Then, update without checking whether the packages are out of date:

sudo apt-get  -o Acquire::Check-Valid-Until=false  update

and request that the packages get installed, e.g., for 4.6:

sudo apt-get install -t jessie-backports  linux-image-4.6.0-0.bpo.1-rt-amd64 linux-headers-4.6.0-0.bpo.1-rt-amd64

(you can omit -headers if you don't use any nonstandard kernel modules)

Now you have to remove or comment out the backports lines, because otherwise subsequent apt-get updates without special flags will (rightfully) error right out:

E: Release file for is expired (invalid since 279d 3h 56min 3s). Updates for this repository will not be applied.
It looks like everything installed, so now to reboot and try my new kernels...

Latency results

Kernel 4.1 (4.1.0-0.bpo.2-rt-amd64)

nvidia X driver failed to automatically load. This may affect (improve) realtime results.

linuxcnc latency-histogram --nobase: 11.5us max latency in 3 minutes

Kernel 4.4 (4.4.0-trunk-rt-amd64)

(I believe this kernel is self-built and so may differ slightly from the one on bpo)

nvidia X driver loaded. This may harm realtime results.

linuxcnc latency-histogram --nobase: 135.2us max latency in 2 minutes

(this is perfectly adquate latency for mesa hardware, by the way!)

Kernel 4.6 (4.6.0-0.bpo.1-rt-amd64)

nvidia X driver loaded. This may harm realtime results.

linuxcnc latency-histogram --nobase: 126us max latency in 11 hours

nvidia kernel driver temporarily blacklisted.

linuxcnc latency-histogram --nobase: 9.4us max latency in 2 minutes

(note to self: why does the size and layout of the latency window change when my desktop resolution changes?)


18 June 2016, 17:13 UTC

Saturday Software Project: VIC 20 Incremental Game

First game I've written in ages, the first incremental game I've written, and it also runs on the 1980 VIC 20:

License: GPLv2+


19 March 2016, 23:35 UTC

New Desktop 2016

16 January 2016, 22:15 UTC

Ancho Reyes Hot Chocolate

30 December 2015, 19:38 UTC

Coolest C Preprocessor Trick of the Year

All older entries
Website Copyright © 2004-2014 Jeff Epler