Pi-Cam

I was unable to find a suitable pan and tilt solution for Raspberry-Pi so I decided to create one. The object is 3D printable and provides a stable platform to develop remote surveillance, time lapse and computer vision projects. I wanted it to look well polished and feel like a commercial product so I put some extra effort in the aesthetic and functionality.

The hardware part is developed using OpenScad, an opensource CAD system based on command line rather than graphical point-and-click instructions. The software is sometimes referred as “the programmer” CAD as you effectively have to write code to generate 3D models. I believe this approach is much better for mechanical design as it allows easy model parameterisation.

1 2
Exploded view of the pan and tilt enclosure for raspberry Pi 2Cam-Pi assembled

The software of choise is Node.js, JavaScript and Foundation to create a web application that runs well on mobiles, tablets or desktops.

At the moment functionalities are limited to video streaming and time lapse, but the platform can be used in conjunction with OpenCV for more advanced computer vision applications. For the moment I have used it to do some timelapses from my balcony.

You can find some more assembly information on the Thinghiverse post or the source code on Github.

The balancing act of the one-eyed robot

During the last 9 months I have been busy working on my latest robotic project: a two wheeled self-balancing robot. I previously wrote about the reasons; in essence I think it is a great way to better understand the technologies that surround us and also a good personal development to derive some teachings about management and leadership on which I will soon write.

In the beginning I thought it would have been a few week-ends project; now almost one year in the process I just started scratching the surface of it. I thought that I had most of the necessary knowledge, instead I had to learn new tools, new programming languages and new engineering concepts.

The purpose of this article is to outline particular aspects of the design of the robot with special regards to some tricky issues I solved long the way, not to be a step-by-step guide. In case you are interested in missing details just drop me a line and I will do my best to provide you the information.

Continue reading

Bailey: the almost-self balancing robot

They should have also added "...hope for the best"

They should have also added “… and hope for the best”

I decided to start building robots for several reasons, firstly I have always been keen on technology, when I was a kid I spent a lot of hours programming and hacking the Commodore 64. Secondly as designing and programming these things is not a trivial tasks, I hope this can teach me patience and tenacity.

My first design is a self-balancing robot; the idea is to have a system that can sense if it is falling and act consequently. Something like balancing a broom from the tip. I will describe the details of the physical model “inverted pendulum” and the construction of the robot in another post. There are various examples, the most known most-likely being the Segway personal transporter. Inverted pendulum concept

The robot utilizes fairly complex algorithms and hardware. The core is the microprocessor that fuses data from the Inertial Measurement Unit to evaluate the tilting angle in a similar set-up used for missile guidance systems: gyroscope, accelerometer and magnetometer. Once the data is available the next step is to translate the information into instructions for the motor: “we are falling forward, move the motor to catchup” and so on. This is done by a control method called proportional-integral-derivative (PID).

I started designing an building this about six months ago and made countless revision of the software and hardware: today, for the first time, I got something that works. Below the first video of my self balancing robot. Bailey makes a lot of efforts to balance but still seems a bit drunk (hence the name). I guess there is still much to do in terms of tuning the control mechanism (PID) as usually, after a while, it crashes full throttle against the nearest wall. You can see an hit of this self-destructive tendency at the end of this video…

Nevertheless I am very happy with these first results after so many attempts. The next steps will be to add some wireless communication facility so I can adjust the controller parameters remotely without resetting the robot.

 

References

 

 

One day in Zurich gone in seconds: time-lapse with Raspberry

Time-lapse videos are a great dramatic feature of many TV shows and movies; for example the entire opening titles of House of Cards is made using this technique.

Experiments like the one described in this post are easy to do with little equipment and still the final result is pleasing.

In its simplest form time-lapse consists in a series of snapshots put together to create a movie, more complex productions create a dynamic effect by having the camera moving while shooting. One important tip to remember is to choose a scene with many moving items. for this reason my short sunset video above is more interesting than the second one at the end of this article. Also, remember to check if you need any permissions to shoot in public places.

The Raspberry Pi (inside its original packaging) is powered by a USB portable power bank and the camera is held still by using helping hands (better than tape).

The Raspberry Pi (inside its original packaging) is powered by a USB portable power bank and the camera is held still by using helping hands (better than tape).

My set-up is improvised: a raspberry Pi, a USB power-bank, a Wi-Fi antenna, the camera module and “helping hands” to hold the camera steady (you can find these in any electronics shop). This setup can be also used to create a IP cam using a software called motion.

As mentioned the process is divided in two steps:

1) take pictures
You just need to open an ssh terminal in the Raspberry and digit the following code

raspistill -o myimage2_%04d.jpg -tl 30000 -t 43200000

where 30000 is the time in milliseconds between shots and 43200000 is the the duration of the session (12 hours). “&” at the end of the command tell Linux to run it in background. Alternatively you can use VNC and log in the Raspberry and open the command prompt.

2) put them together in a movie
After the pictures are taken we need to copy them in a more powerful computer for further processing. Naturally it is possible to use ssh or other methods such as ftp or telnet but I think the fastest method is to slot the SD card of the Raspberry into a reader connected to a Linux machine.

Next step is to create the video and to do that I used mencoder (see the Wikipedia entry for alternatives). Using the command prompt you have to position yourself into the folder where you saved the images and first create a text file containing the names of the images to stitch together:

ls -1tr > frames.txt

After that let the mencoder to the magic. One notable parameter is
fps frame per second. The higher the value the faster the scene will move and the shorter the move will be. I normally use 10 fps. You can try different values for example 20 fps for faster action.

mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell:autoaspect:vqscale=3 -mf type=jpeg:fps=10 mf://@frames.txt -o time-lapse.avi

Although this setup is bare-bone it allows to get some nice results. Further improvements can be to use better hardware and add features such as  a system to move the camera. Look for the  David Hunt time lapse controller for the best example I was able to find.

 

 References

RobotPi Part 2 – The remote

The robot remote runs on Android and allows to control many functionality of the robot
The remote control can allow a stable interface across different improvements of the robot. Feedback on the status is is provided as well.

I want to be able in the future to connect the robot with Internet, so I think a good starting point is to design a remote control running on my Android tablet. The target is to create something that can be used for different missions, so I took some time to develop a generic design to cater for different needs. Continue reading

RobotPi Part 1 – Key concepts

The idea is to build a robot and use it in various experiments such as autonomous navigation. The ambition is to try to do something more rewarding that a simple “go forward, detect obstacle and turn left” type of programs and use as much as possible open source elements (a great game changer, on which I will write later on).

osi_standard_logo

Open Source Software and Hardware will change the way we interact with technology (http://opensource.org/)

I think it is worthy to spend some time on this project, as it goes beyond a pastime and helps to understand how different technologies can interact to shape our  future. Continue reading

How to master any recipe and cook delicious food with Design of Experiments (DoE)

I love to cook. It is a good way to relax and, at the same time, to know what you are going to eat… The technique explained below allows to create delicious recipes and master new culinary treats very quickly.

Many dishes I love are simple. The tricky part is that, unless you know the right proportions and the right cooking process, the outcome can go disastrously wrong, like rock solid or bound with the pan. The difficult part is to learn recipes quickly.

The Design of Experiments or DoE methodology is used in a vast array of applications ranging from drug and medical trials to virtually any engineering domain and… cooking.

A rather academic definition of DoE is “scientific approach to reach the target of a design in a multivariate problem achieved with the minimum number of trials“.

The informal definition is what happen when you are in front of a complex device like a audio mixer or a stereo and – not having read the manual – you want to achieve a specific result, say having the voice of the singer emphasized. People in these circumstances normally start experimenting with various settings by changing the configuration of knobs and button to achieve the target.

Another example is when trying to tune one of the old TV set with dipole antennas: the target is to be able to watch the desired channel and you do so by changing the variables (the tuning knob and the antenna) until you’re satisfied.

Process wise, DoE mostly about: a) what I want to achieve (target function), b) the variables under control,  c) experiments and d) measure and reiteration (ok, I night have oversimplified here).

So how this can help the cooking?

Let’s say that the target function is to do something delicious (needs to be tasteful, look and texture) and the variables are the ingredients. All you need to do is:

  1. Define factors (variables, inputs) and set the levels (a good staring is the original recipe)
  2. Experiment (cook)
  3. Examine the results
  4. Repeat the process until satisfied
 Picture1

A good graphical representation

from moresteam.com

Finally the trick is to record the experiment and its results in a simple way to link the variables with the result. See below an example recipe:

Recipe: Farinata Experiments
#1 #2 #3 #4
Chickpea flour [g] 130 110 180 130
Water [ml] 400 300 450 400
Oil [ml] 110 150 110 80
Oven [C] 230 250/3 250/2 250/2
Notes
#1 Oily and not crispy (more like pudding)
#2 Too dry, oily
#3 Too thick and oily
#4 Perfect! (500ml per pan)

This recipe is a good example as the basic ingredients are very simple but a slight variation will lead to a very different (and most-likely not tasteful) result.  One difficult parameter to control is the thickness of the farinata, that ultimately depends on the amount of ingredients poured in the pan (the recipe above is optimized for a pan diameter of 25cm).

All of this might seems complex, but it is really simple when applied practically, the only difficulty is to be diligent in logging the experiment.

References:

Source of the DoE factors picture above: https://www.moresteam.com/toolbox/design-of-experiments.cfm

For everything you will possibly need on statistics and much more try the National Institute of Standard and Technology (NIST) Handbook: http://www.itl.nist.gov/div898/handbook/index.htm

Farinata recipe http://italianfood.about.com/od/fritterssnacks/r/Ligurian-Chick-Pea-Farinata-Farinata-Ligure.htm