# Can my Tesla Model S be charged daily by the Solar on my roof?

Note: I don’t actually own a Tesla Model S and all I really care about is honesty. I want this question answered honestly so that people can stop lying to each other.

I was reading a brilliant post that pretended that the Electric car had been released first and that the Petrol car was trying to attract its first buyers; I highly recommend that you read that article. But the whole article raised one really important question about how much energy it would take to run your house and car on solar. In it’s distilled form the question is essentially:

How many Solar panels and Tesla Powerwalls would I need to take my Household energy usage and Tesla Model S off the grid? (Such that I don’t need to rely on the Grid and fossil fuels ever again)

To fill in that spreadsheet you only need two pieces of information:

• How much energy your home consumes per day (in kWh).
• How much you drive per day (in km)

With that information you can work out how many solar panels you would need on your roof and how many Tesla Powerwalls you would need to store all of the energy that they generate. I think that you should give it a shot.

However, my conclusion is this: most people that drive close to or under the average for Australian drivers (<= 43km per day) will find that they don’t need significantly bigger Solar Systems and power packs to cover the costs of their Tesla car. And every single home owner on the planet should be able to get enough Solar panels and Powerwalls to cover their household and car energy usage.  Good news!

Note: Currently there is no cost analysis here of how much those components will cost. But I will add that companies like Solar City and Sun Edison make getting solar panels a breeze. Also the Gigafactories being build in America right now should dramatically bring down the price of Solar Panels and Powerwalls.

Hopefully this helps somebody and, if you have any questions then please let me know in the comments.

# Making a printable Cam

In this post we are going to explain the process of making a 3D printable Cam with OpenSCAD and a little bit of code I wrote.

In a nutshell, the code I wrote takes in a standard displacement diagram used to describe the increase and decrease in displacement of a Cam over time. Something that looks like this:

And uses that information to create a 3D model like this:

A cam on a cylinder (known as a disc cam).

A cam on a ramp (also known as an end cam).

If you don’t know what a Cam is then please read the previously linked Wikipedia page. But just because you know what it is does not explain why you would want to make one.

A Cam is an device that turns rotational motion into linear motion an many different ways; this is extremely powerful. In mechanical engineering is is pretty easy to create rotational motion (Electric Motor, Steam, Windmill, Treadmill with mice, etc). This is great and already useful but, in many cases, we then want to perform some kind of linear movement based on this rotation. For example, maybe we want to use the rotational motion to trigger a button a certain number of times per second (like an odometer). In this scenario the rotational motion needs to be turned into the linear motion of pushing the button up and down. This conversion is extremely useful and almost every modern petrol based engine uses a Cam via the aptly named Camshaft; the thing in your car which make the engine pistons go up and down.

However, I am personally very excited by the combination of combining a cam with a spring follower. This allows you to slowly store more and more energy in a spring and then release it all at once explosively, letting you create an automatic catapult. For a rudimentary example of what I mean please see this olive slinging device:

So, with that in mind I wrote a quick program in OpenSCAD to generate Cam for you. At this point in time you can generate two different types of Cam’s: a disc cam and an end cam. The two methods that allow that let you specify:

• The displacement diagram of the Cam
Given as a list of points from (0, 0) -> (1, 1) with linear interpolation between the points and points that retain the same displacement to infinity on either end of the diagram.
• The number of segments
Ultimately the Cam will not have a smooth surface but rather be built from a number of segments. The more segments then the more precision your Cam will have and the smoother the finish will be
• The dimensions of the Cam
How high should it be? How big should the radii be?

Lets run through a quick example to show you how it works. With these variables under your control you can then write openscad code that looks like this:

```end_cam(displacement = [ [0, 0], [0.2, 0.8], [0.6, 0.5], [1, 1] ],
segments = 360,
baseHeight = 1,
peakHeight = 3,
width = 0.5);
```

And it would produce a Cam that looked like this:

And here is an even more complex example where we made the displacement diagram be the (sin(x)) ^ 2 function.

```[ for(i = [0 : 360]) [i / 360, sin(i) * sin(i)] ]
```

It looks great:

An edge cam generated with the sin(x) ^ 2 function.

And this is very very powerful, you can now create a cam for your own hobby purposes. Here is the full example of test Cams that you can view just by loading up the test-cam.scad file that exists in the source code:

If you wish to add extra fixtures to the Cam’s so that you can attach them to your motors or rotating mechanical devices then the union and difference functions from OpenSCAD are your friends. Good luck. I hope that this helps you on your mechanical endeavours and please post your creations made using this code in the comments section below. I can’t wait to see them!

Interesting

# Collecting audio samples of the English Alphabet

### What are you collecting?

At the moment I am working on a project to create “The English Alphabet Audio Database” which aims to be the largest (completely free) collection of people speaking the English Alphabet on the planet.

### How do I contribute my beautiful voice?

View or contribute to it here: http://robertmassaioli.bitbucket.org/alphabet-upload.html

Note: All submissions have everything but the sound of your voice stripped from them (like filename), ensuring that you remain anonymous except for your voice. And even then, your voice will be in a database of hundreds or more of other voices.

### Why are you collecting these audio samples?

I am collecting this data for the purpose of aiding some speech recognition work that I am doing and thought that, while I was at it, I may as well make a big collection of audio samples than anybody can use for any purpose. I hope that you submit to the audio database.

At 100 samples collected I will release the first version of this database for public consumption, at the moment I only have 6 samples collected so we could use all of the help that we could get! Please contribute. Your voice may be what helps us to bring speech recognition forwards.

### How big could this get?

There are roughly 335 million English speakers on the planet. I think it is completely reasonable to hope that you will be one of the awesome english speakers that will submit to the database. With your help we could get submissions in the thousands. I hope to eventually fill this database with 100,000 samples.

# How to control a Quartz Clock Mechanism

In the past I have spoken about the Internals of a Quartz Clock Mechanism explaining how it works and how it all comes together with a handy video. However, even though I explained how the solenoid spins the pinion gear I did not explain very precisely how you might go about manipulating a Quartz Clock Mechanism.

In this blog post I present you with another video that explains “How to control a Quartz Clock Mechanism”. In the video I explain and show how to connect the clock to a custom electric circuit that you construct and I then provide a method to speed up and slow down a regular quartz clock. I hope you enjoy the video, if you like the video then please let me know in the comments or share it around:

## Recommended Resources

In the video I run through a number of concepts and I want to provide you the links to those concepts here in one convenient location:

Hopefully you can use these resources to control you own Quartz Clock Mechanisms or other electronic circuits.

## Concluding Words

I have attempted to explain clearly how to control a Quartz Clock Mechanism in the hope that other people might follow suit. With any luck you can now go out there and do something really interesting with Quartz Clock Mechanisms. If you do then please let me know about it. If you have any comments at all, or would like to see me do something else that is interesting with Quartz Clock Mechanisms then please let me know!

# Setdown: the best tool for fast and repeatable line based set operations

## Introducing setdown

Have you ever been on the command line and tried to perform set operations? Have you ever followed crazy cli guides on the internet that suggest complicated commands to try and perform set operations on files. I have. And I did not like it; I think that we can do better.

Over the weekend I wrote a pretty nifty program that I am calling: Setdown. Setdown requires you to specify the set operations that you wish to perform as a definitions in a set definitions file (often suffixed with ‘.setdown’). The setdown language definitions are written in a very similar format to Makefiles; except that it performs set operations.

If you want to install setdown right now or checkout the code then you can follow these links:

If you want to learn how to use setdown and write set operations in it’s language then you should read the README file provided in the source code. However, to show you how easy the language is to read you I have provided an example .setdown file right here:

```-- All of the letters of the alphabet
alphabet: &quot;alphabet.txt.unsorted&quot;

-- Calculating the consonants with a set difference
consonants: alphabet - &quot;vowels.txt.unsorted&quot;

-- Getting any letter than is e-sounding or a vowel
e-or-vowels: &quot;e-letters.txt.unsorted&quot; / &quot;vowels.txt.unsorted&quot;

-- Get any letter that is e-sounding and a vowel
e-and-vowel: &quot;e-letters.txt.unsorted&quot; / &quot;vowels.txt.unsorted&quot;

-- Get all of the e-sounding letters, the vowels and the consonants
e-or-vowels-or-consonants: (&quot;e-letters.txt.unsorted&quot; / &quot;vowels.txt.unsorted&quot;) / consonants
```

You should install setdown and then check out the setdown-examples project to give it a try right now!

## Can you show me an example?

By this point in time you are probably wondering “I love the look of it but show me an example”. So I will. Here is the output of a full running example by checking out the first example in the setdown-examples repository and running it:

```\$ setdown ex1.setdown
==> Creating the environment...
Base Directory: ./
Output Directory: ./output

==> Parsed original definitions...
e-or-vowels-or-consonants: ("e-letters.txt.unsorted" / "vowels.txt.unsorted") / consonants

e-and-vowel: "e-letters.txt.unsorted" / "vowels.txt.unsorted"

e-or-vowels: "e-letters.txt.unsorted" / "vowels.txt.unsorted"

consonants: alphabet - "vowels.txt.unsorted"

alphabet: "alphabet.txt.unsorted"

==> Verification (Ensuring correctness in the set definitions file)
OK: No duplicate definitions found.
OK: No unknown identifiers found.
OK: All files in the definitions could be found.

==> Simplifying and eliminating duplicates from set definitions...DONE:
alphabet: "alphabet.txt.unsorted"

consonants: alphabet - "vowels.txt.unsorted"

e-and-vowel: "e-letters.txt.unsorted" / "vowels.txt.unsorted"

e-or-vowels: "e-letters.txt.unsorted" / "vowels.txt.unsorted"

e-or-vowels-or-consonants: e-or-vowels / consonants

==> Checking for cycles in the simplified definitions...DONE:
OK: No cycles were found in the definitions.

==> Copying and Sorting all input files from the definitions...
"alphabet.txt.unsorted" (unsorted) => "./output/alphabet.txt.unsorted.1.split.sorted" (sorted)
"e-letters.txt.unsorted" (unsorted) => "./output/e-letters.txt.unsorted.1.split.sorted" (sorted)
"vowels.txt.unsorted" (unsorted) => "./output/vowels.txt.unsorted.1.split.sorted" (sorted)

==> Computing set operations between the files...
Required results:
alphabet: ./output/alphabet.txt.unsorted.1.split.sorted

consonants: ./output/c989d1cf-b860-41cc-a52c-e2afc1e6a235

e-and-vowel: ./output/a8bd5974-22d5-4fdb-b269-0c09a1eeeb18

e-or-vowels: ./output/c3a8cc7c-f246-4eb4-b321-57f900964960

e-or-vowels-or-consonants: ./output/493ca813-7e3c-4259-9435-e2d5ddb4d6a5
\$
```

As you can see we have ended up with a number of output files. Just to pick one example lets see the contents of the consonants file:

```\$ cat ./output/c989d1cf-b860-41cc-a52c-e2afc1e6a235
b
c
d
f
g
h
j
k
l
m
n
p
q
r
s
t
v
w
x
y
z
\$
```

And look at that, we have computed the consonants when we were given the vowels and the rest of the alphabet. Hopefully you can see that this is very powerful and will let you write increasingly more correct set operations from the command line.

## The benefits of setdown

Depending on your command line bent you may have used other tools in the past to perform set operations on files, like comm or fgrep, but these tools are quite lacking. Instead let me show you the full range of features that setdown gives you:

• Maintainability
If you get more set data to add to your collection (as often happens) then it is trivial to edit the setdown definitions to include it.
• Repeatability
Even if the data changes you run one single command and all of your set operations are performed again.
• Sorted input is not required!
Programs like comm require that you have sorted input if you want to do efficient set operations on files. This make sense because sorted files make set operations very efficient. However, we don’t put the onus on you to provide us with sorted input. Setdown will sort any files that you give it itself. We even use External Sort so that you can give us truly massive files and expect that we will still be able to perform your set operations.
• Simplification of definitions
If you write the same definition twice then setdown will factor that out and only perform the set operation once. This makes setdown run as efficiently as possible:

```==> Parsed original definitions...
C: "b-1.out" - ("a-1.out" / "a-2.out")
B: "a-1.out" / "a-2.out"
A: ("a-1.out" / "a-2.out") / "b-1.out"

==> Verification (Ensuring correctness in the set definitions file)
OK: No duplicate definitions found.
OK: No unknown identifiers found.
OK: All files in the definitions could be found.

==> Simplifying and eliminating duplicates from set definitions...DONE:
A: "b-1.out" / B
B: "a-1.out" / "a-2.out"
C: "b-1.out" - B```
• Dependencies and cyclic dependency detection
Since you can write set definitions that depend on other set definitions it is possible to write a cyclic dependency. We will spot this for you and also tell you exactly where the cycle is in your file, meaning that you don’t have to search for it yourself!

```==> Simplifying and eliminating duplicates from set definitions...DONE:
A: C
B: D
C: B
D: A

==> Checking for cycles in the simplified definitions...DONE:
[Error 20] found cyclic dependencies in the definitions!
We found the following cycles:
A -> C -> B -> D -> A```
• Validation
We verify that your set description only references files that exist and that if you reference dependencies that do not exist then you will get an error.
• Works nicely with version control
You check your .setdown file and your input files into the repository and share them with your co-workers. Everybody can use setdown to get the same results! To prove it, I have written three examples in a setdown-examples repository. Check it out and give it a try!
This makes the program very fast and efficient while, in my opinion, reducing the chances of having bugs.

I think that this is a much more compelling set operations tool for the command line than anything else that exists out there and I am really happy to share it with you today for free. I also really hope that you get some great usage out of this tool and that it makes your life easier.

## Concluding words

From experience I can say, without this tool, dealing with complicated set operations on the command line and sharing your results with your co-workers is much more difficult than it should be.

At any rate I hope that you get a great deal of value from this tool and if you have any comments or suggestions then please ask them here on this blog or raise them as issues. If you have any questions then ask them here or on Stack Overflow.

Thanks for reading and I hope this makes somebodies like a little bit easier.

# The Hailgun library

Very recently I was writing a shared service in Haskell and we realised that we would need to integrate with an email service provider. After a little bit of research I concluded that Mailgun was a great service for developers to send their emails so I looked for Mailgun integration libraries that looked like they were being groomed to be “the” Mailgun library for Haskell and I was disappointed to find that the existing libraries did not seem to be very comprehensive or did not make use of type safety.

I believe this library to be better because:

• It supports simple email sending just like the existing libraries.
• The type system is stricter, leaving less room for incorrect usage of the API. Giving you the assurance that you will be sending emails correctly.
• There is a backlog of issues that has been roadmapped such that the library will have full Mailgun API support. It just needs time to develop it.
• The support for the various parts of the API is being implimented and released incrementally so that people can get the benefits of the hailgun library now.
• It comes with the hailgun-send executable out of the box. This executable can be used on the command line to send emails through the Mailgun API.
• This library has been written in pure Haskell and does not use any FFI wrappers around another Mailgun library: the goal of this library is to work on any platform.

And this is just for version 0.1.0.0. To people that read this in the future, you should check out the library on hackage to see what it impiliments now.

## Sending a test email

I’m going to explain here how to send a test email using hailgun-send so that you can quickly see that the library works and can be used to send your emails in pure Haskell code.

If you don’t have a Mailgun account and a sandbox for it then go sign up for one. Once you have created your account you should have been given an API key and have a sandbox domain name. Please create a file called ‘hailgun.send.conf’ in the current directory and make the contents of the file:

``````mailgun-domain    = "sandbox-mailgun-domain.com"
mailgun-api-key   = "key-thatmailgungaveme9234uoah234"``````

Once you have that file in place you should then be able to use hailgun-send. For example, this is one invocation that I used:

``````hailgun-send
--from 'postmaster@sandbox17bd032a44ea44f5b540470a8ab4787f.mailgun.org'
--to 'robertmassaioli@massaioli.com'
--subject 'Hailgun v0.1.0 test email'
-x data/email.text
-m data/email.html``````

You will notice that I provided a from and to address, an email subject and the content of the email in two files. You should create the email.text and email.html files yourself or you could simply use the ones that are avaliable in the repository. Please note that the HTML version of the email is optional but the text version is always required.

You should see something like the following email appear in your inbox:

## Concluding Words

In short you should now be able to send emails, via Mailgun, with Haskell and the library should be improved to have more API support as time goes by. I hope this is useful to some peoplee and, if a Mailgun developer should happen to swing by this post then please feel free to review my code.

# Wavy over WAVE

Playing with audio data is a ton of fun and something that I believe that Haskell could do very well. Processing audio data safely and efficiently seems to fit very well into Haskell’s model so, overy a year ago, I started working on and off on a WAVE file format parser. I have been working on it very infrequently (bus trips and other spare time) and I rewrote it once but today I am pleased to announce the release of the very first version of my ‘wavy’ package that lets you extract data from WAVE files in Haskell. The features of this release include:

• Methods to Parse and Assemble Wave Files
• Support for different orderings of RIFF chunks (via the riff library I wrote previously)
• A split between the parsers for the container format and the data allowing efficient metadata parsing.
• The ability to pase the data into Int64 or Float formats so that you can handle the data in whichever way that you please.
• Example programs that make use of the library for your perusal and use.

Things which the library is currently missing include:

• RIFX support
• Direct support for maintaining RIFF chunks that are not mentioned in the WAVE specification.

## Getting the Code

The code is on hackage as the wavy library so you can install it by:

``````cabal update
cabal install wavy``````

Please feel free to give it a try. Probably the best way to quickly see it working is by finding a WAVE file on your machine:

``locate '*.wav'``

And then passing that wave file as the first argument into wave-info. For example:

``````\$ wave-info /Applications/Steam.app/Contents/MacOS/Friends/friend_join.wav
File: /Applications/Steam.app/Contents/MacOS/Friends/friend_join.wav - 2s
Format
Audio Format:  Microsoft PCM
Channels:      2
Sample Rate:   44100
Bits Per Sample:  16
Byte Rate:  176400
Block Alignment:  4

Creation Date: 2010-03-11
Engineers:       - Kelly Thornton
Creation Software: Sony Sound Forge 9.0
\$``````

As you can see it can parse an audio file very quickly. The wave-info program is very efficient because the library is lazy and does not parse the data chunk unless you specifically require it.

## Using the Library

I would recommend that you start by looking at the executables in the libraries source code for examples of how this library can be used in your applications. The wave-info source code can be found on BitBucket.

Once you have finished doing that then you can have a read throug the documentation on Hackage to get a full understanding of what methods the library provides.

If you have any questions then please do not hesitate to contact me or comment on the blog.

(This blog post was produced using pandoc)