My pick this week is something that many of us could find useful and have likely thought about at some point during the standard workday: a simple design for the controller behind an automatically flushing toilet.
Techsource's Technical Team has put together a collection of simple Simulink models to showcase getting started with Simulink and an Arduino Board, a low cost embedded target.
This particular one caught my attention for two reasons. First, the main model is called 'UltraSonic_Pee.slx'. If you want to grab someone's attention, well, a model name like this is a good way to do it. Second, this simple model is extensible so that I can include my own sensor input and simulate different flushing scenarios. Let's see how this is done.
Here's the original model:
For my Arduino board, I only have the LEDs and a simple DC motor. However, I have a Lego NXT that has an ultrasonic distance sensor and a DC motor that I can use. I don't know if the DC motor is actually powerful enough to pull down the handle on the urinal, but I'm going to try.
The first thing I am going to do is replace the two Arduino Blocks with a Lego Motor block from the Lego Support Package. Support packages are additional functionality you can freely download to allow MATLAB and Simulink to take advantage of your hardware.
One of the beautiful things about Simulink is the ability to have Variant Subsystems. These allow you to either have different fidelity models or to substitute in different components. My second step is going to be to make the Signal Builder block into a variant subsystem so I can have my Lego distance sensor as an input instead. This is really important for the modeling aspect. I'm fortunate enough right now to have access to the hardware. But if I did not, I could still develop and test my algorithms by simulating the hardware with other signals that I could build or historical data from other tests.
Next I'm going to simulate this in External Mode. This means that the model will be running in Simulink but be grabbing data from the sensors and controlling the motor. By running in External Mode we can use the full power of the MATLAB and Simulink platforms to analyze the results of the model and see it running in semi-real-time. By doing this, I discovered that I needed a couple of gains on the signals to control how close one needs to get to trip the sensor.
Once the model has been tested, we can then embed the controller onto the Lego. One button click in Simulink generates the equivalent C-code, compiles it, and moves it onto the Lego.
Now we're ready to put this to the test!
The looks we got from fellow restroom patrons and the cleaning staff were pretty priceless.
Next I got my friend Adam, who is relocating from Massachusetts to California shortly, to test it out. The control algorithm that Techsource used is to have a preflush and a postflush - not the most environmentally friendly of algorithms but we waste no water in simulation. Since this is no longer simulation, I figured Adam should enjoy this luxury while still being on the east coast.
Unfortunately, the Lego motor was not strong enough to pull the handle down and instead lifted the whole robot up. But hey, not too shabby for an hour's worth of work.
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.