LESTER looks up, spins its wheels: The Register’s beer-butler can see ...
No beer will be left unbothered
British hip-hopsters The Streets memorably sang "It was supposed to be so easy", and that was our expectation when we approached the task of getting LESTER to "see" and trundle towards an object.
After all, there are innumerable ready-made robot kits, and the Raspberry Pi is ostensibly a tool to get children interested in computing, right?
LESTER gets ready to trundle: The Register's beer-bot has a nameREAD MORE
Getting a stock camera up and running on the Pi was straightforward enough using a fresh install of Raspbian. A few lines of Python, an import of the PiCamera library, and LESTER's single unblinking eye came to life.
Team LESTER planned to use OpenCV to allow LESTER to identify and follow a tag attached to a PFY. A swift
apt-get should have been all we needed to import the cv2 library and commence rocking and rolling.
Sadly, it was not to be the case. After staring at a helpful “
Import Error: No module named cv2” message for far longer than we should have, a bit of investigation revealed that Python 3.0, which we were running, was not happy with the repository, which needed Python 2.7.
In hindsight, maybe we should have found a way of reverting to Python 2.7, but no. This is Linux, the source is in
git, so if we recompiled the OpenCV code on our Pi, everything would be shiny and golden.
Armed with innumerable helpful guides on the subject, and having tracked down all dependencies after a bit of trial and error, we hit "make" and waited...
It took quite a while, and we later learned that we could have used multi-threading to save time. That isn't to say we didn't make good use of the hours of CPU churning, and demolished an impressive number of barbecued sausages along with copious amounts of delicious, delicious beer.
After fixing a missing symlink, the original error was gone. It was replaced by a slew of new ones, related to OpenCV's camera capture functions. According to the programmer's standby, StackOverflow, the solution was that the camera had somehow broken.
However, firing up PiCamera again showed LESTER's eye was working perfectly.
We then had the idea of simply taking the working PiCamera capture and converting it into something that OpenCV could understand. This is how we did it:
stream = io.BytesIO() camera.capture(stream, format='jpeg', use_video_port=True) image = np.fromstring(stream.getvalue(), dtype=np.uint8) frame = cv2.imdecode(image,1)
After a bit of configuration using the Range Detector utility LESTER was able to track a nice, bright, red ball.
LESTER team member and bearded shonk-botherer Mark Wheeler takes a break from removing rust from Opel Monzas to wave a ball at LESTER's eye...
With the optics running, we attempted a first run at motor control. GPIO – the connection between the Pi and the outside world – is considerably simpler to use than anything involving OpenCV, and after a couple of minutes LESTER was turning its motors left and right in response to the motion of the ball.
The next step will be to add proximity detection to stop LESTER from enthusiastically ramming the PFY and mounting the whole assembly onto a frame to allow the prototype to demonstrate it can roll around.
LESTER undressed... pic: El Reg
Then we can start scaling things up in a most alarming way. ®
Sponsored: Becoming a Pragmatic Security Leader