OK, so as discussed, my brother is going to build a mini-display that showcases the differences between 3 different kinds of wall insulation. This will be used at kiosks, at various Home Shows. My involvement, is that I want to use some sensors, and write an application that manages and displays the temperature/humidity/ and pressure (p.s.i.) on a flat-monitor, attached to this display. The design of the physical structure, is still not complete, but there are certain concepts that can be assumed. Here are my starting assumptions:
- Input Sensors: we’ll need sensors for temperature, humidity, and air pressure
- Output Controls: we’ll need the ability to turn AC outlets on and off, inside the structure (to control the heat and cold).
- Motors: we’ll likely need servo or small stepper motors to control air diverters.
This is just for starters. As mentioned, there are certainly other ways that input or output devices can be used. So, I ordered a Starter Kit from phidgets.com. It’s coming from Canada, so shipping takes like 9 days – so it will be here Wednesday of this week.
First, I downloaded the documentation and samples for the kit and sensors that come with it. The .NET API is straight-forward enough. If there is one glaring issue, it’s that there aren’t any interfaces or base classes. That means it will be difficult to unit-test or create simulated equipment.So, that makes me think that I should write an interface for “devices”, and then that will give me the ability to “plug-in” phidgets or other devices, or even mock devices for the purposes of unit testing. For example:
If I write my application to work with some device interfaces (literally, an “interface” type, in .NET) – then I could simply write a thin adapter for Phidgets to work with the interface. Additionally, that would mean I could also swap out technologies later too. If I decided to replace, or even just add on devices from a different vendor, it would only require me to write an adapter for each vendor API.
Perhaps the biggest benefit though, is that I could also create a set of mock sensors, so that I could run unit tests against my code.
This is my approach going in – to try to come up with an interface that is powerful enough for what I want to do, but generic enough so that it will work with just about anything.
In school, I took a Computer Ethics class where I actually learned quite a bit. One of them is that when you are writing code that has anything to do with human safety, it really needs to be written well. You should code defensively, err on the side of caution, and plan for failure. In fact, one might argue that you should first write your code that handles all of the failure conditions, then cut a tiny path to cover the “happy path”. This is opposed to just writing a happy path application, and having it explode horribly if the tiniest thing breaks.
In this situation, I intend on working with controlling A/C power, as well as portable heater, in an enclosure. There are some very real potentials for human danger.
With that said, this will be the most strict program I’ve yet written in my career. It really needs to be 100% bullet-proof and capable for graceful degradation, even if a meteor hits the box! So this in itself will be a challenge, but I am really looking forward to it!
As of now, there are two things on my radar: 1) get the phidgets kit in on Wednesday, try out some of the sample code, and make sure my theoretical understanding of the code is the same as how it really works. 2) to try to refine and stabilize the “device interface”, as described above. Once that is done, I can use a combination of real and virtual sensors and controls, which will make development easier. I don’t know what I will actually need for the final product, so my intention with the starter kit was just to get familiar with some of the common devices.
Until we can stabilize a final parts list, I would like to have virtual, emulated devices for the whole setup – then simply place the order to replace the virtual devices with their real counter-parts.
After mid-terms this week, there are 4 more weeks of school, then I plan to dig into this much, much more when I have more time. Between now and then, I hope to make some progress, and update this blog series with some milestones and lessons, as I learn them.