Linux Format - UK (2020-03)

(Antfer) #1
40 LXF260 March 2020 http://www.linuxformat.com

Raspberry Pi projects


Raspberry Pi robots


Building robots to drive around precariously, intimidating


unwanted guests or just tell bad jokes. It’s all in a day’s “work”.


ROBOT PROJECTS


Web control
A roundabout way to control your Pi is to have it run a small
webserver with an HTML form to control it. If your robot has a
camera attached too, then you can stream the video to this
webpage for a delightful first-person video driving experience.
A streaming video processor in Python is less complicated than
you’d think, but more complicated than we’d like to get into in this
summary. Study the DiddyBorg web UI example at http://bit.ly/
LXF260diddy to see how the magic happens. If you are lucky
enough to have a DiddyBorg then you can copy that script to it.

Gamepad control
Controlling your robot with a gamepad is a little easier to get along
with. We ran into some difficulties with our Bluetooth controller when
we tried this back in LXF236 and had to resort to SSHing into our
robot to manually pair it via the bluetoothctl command. A wireless
USB controller requires zero configuration and can be picked up for
around £10. We quite like the retro PS2-style ones, but that’s just us.

Ball following
OpenCV is an astoundingly powerful computer vision framework that
includes Python bindings. It’s actually used to draw the image in the
earlier Web UI example, but we can use it for more advanced
purposes too. It’s capable of detecting objects within an image,
which means we can make our robot drive towards them. If those
objects move, then it will follow them. For this to work, those objects
will need to be fairly distinct, such as a brightly coloured ball. You will
find just such an example at http://www.piborg.org/blog/diddyborg-v2-
examples-ball-following.

obotics doesn’t need to be about building
intimidating humanoid automatons. We can
build much less intimidating machines that can
perform all kinds of useful, instructive or fun functions.
Even better, you can power them with Linux. What’s
more, we don’t need costly, state-of-the-art electronics
to build these devices – a Raspberry Pi and will do just
fine. It doesn’t need to be any more advanced than
putting Lego together. There are all manner of off-the-
shelf kits suitable for any electronics enthusiast.

R


The 6WD DiddyBorgV2 in all its glory, eat your collective hearts out
SUV drivers.

A Pi robot can run the same Raspbian Linux we all
know and love. It can connect to wireless networks, so
you can SSH in and perform diagnostics while it’s on the
move. You can even run apt upgrade etc. while it’s
driving around, which is vaguely analogous to replacing
a car’s engine while it’s moving. Maybe that’s not such a
good idea. Nevermind. A Pi-powered robot might also
take pictures, zoom around your house quoting
Shakespeare or even take to the skies to admire the city
below. With the aid of the OpenCV library and a little bit
of image processing (of which the Pi is more than
capable), we can give our robot computer vision, so that
it can target and follow objects, or (with the help of
some machine learning trickery) recognise objects or
even people.
One of our favourite toys at LXF Towers is our
DiddyBorg v2 robot, which may resemble a dinky
radio-controlled car but is actually an incredibly
powerful robot. The Borg series was designed by
PiBorg, brainchild of Kim Freeburn, who explains,
“The DiddyBorg is the six-wheel-drive robot that is a
homage to the Sojourner Mars Rover”. Check out the
rest of the Borg range at http://www.piborg.org/shop.
The DiddyBorg features six powerful 12V 100rpm
motors and is powered by ten AA batteries. Power is
distributed by the custom ThunderBorg board, which
can handle 5A per motor, has a multicolour LED (useful
for monitoring battery status) and we’re sure you agree
it looks the business. Rather than using some
complicated servo arrangement for steering, the
DiddyBorg rotates by turning its wheels at different
speeds. By turning the right wheels in the opposite
direction to those on the left, it is also capable of
spinning on the spot. It’s equipped with the Pi Camera
(which is a great thing to own even if you’re not building

We need to convert the image to HSV
so that OpenCV can better detect any
red ball-like objects to follow.

40 LXF260March 2020 3332March 0Sens2i0e

Raspberry Pi projects


Raspberry Pi robots


Building robots to drive around precariously, intimidating


unwanted guests or just tell bad jokes. It’s all in a day’s “work”.


ROBOTPROJECTS


Webcontrol
AroundaboutwaytocontrolyourPiistohaveitrunasmall
webserverwithanHTMLformtocontrolit.Ifyourrobothasa
cameraattachedtoo,thenyoucanstreamthevideotothis
webpageforadelightfulfirst-personvideodrivingexperience.
AstreamingvideoprocessorinPythonislesscomplicatedthan
you’dthink,butmorecomplicatedthanwe’dliketogetintointhis
summary.StudytheDiddyBorgwebUIexampleathttp://bit.ly/
LXF260diddytoseehowthemagichappens.Ifyouarelucky
enoughtohaveaDiddyBorgthenyoucancopythatscripttoit.

Gamepadcontrol
Controllingyourrobotwithagamepadisalittleeasiertogetalong
with.WeranintosomedifficultieswithourBluetoothcontrollerwhen
wetriedthisbackinLXF236andhadtoresorttoSSHingintoour
robottomanuallypairitviathebluetoothctl command.Awireless
USBcontrollerrequireszeroconfigurationandcanbepickedupfor
around£10.WequiteliketheretroPS2-styleones,butthat’sjustus.

Ballfollowing
OpenCVisanastoundinglypowerfulcomputervisionframeworkthat
includesPythonbindings.It’sactuallyusedtodrawtheimageinthe
earlierWebUIexample,butwecanuseitformoreadvanced
purposestoo.It’scapableofdetectingobjectswithinanimage,
whichmeanswecanmakeourrobotdrivetowardsthem.Ifthose
objectsmove,thenitwillfollowthem.Forthistowork,thoseobjects
willneedtobefairlydistinct,suchasabrightlycolouredball.Youwill
findjustsuchanexampleatwww.piborg.org/blog/diddyborg-v2-
examples-ball-following.

oboticsdoesn’tneedtobeaboutbuilding
intimidatinghumanoidautomatons.Wecan
buildmuchlessintimidatingmachinesthatcan
performallkindsofuseful,instructiveorfunfunctions.
Evenbetter,youcanpowerthemwithLinux.What’s
more,wedon’tneedcostly,state-of-the-artelectronics
tobuildthesedevices–aRaspberryPiandwilldojust
fine.Itdoesn’tneedtobeanymoreadvancedthan
puttingLegotogether.Thereareallmannerofoff-the-
shelfkitssuitableforanyelectronicsenthusiast.

R


The6WDDiddyBorgV2inallitsglory,eatyourcollectiveheartsout
SUVdrivers.

A Pi robot can run the same Raspbian Linux we all
know and love. It can connect to wireless networks, so
you can SSH in and perform diagnostics while it’s on the
move. You can even run apt upgrade etc. while it’s
driving around, which is vaguely analogous to replacing
a car’s engine while it’s moving. Maybe that’s not such a
good idea. Nevermind. A Pi-powered robot might also
take pictures, zoom around your house quoting
Shakespeare or even take to the skies to admire the city
below. With the aid of the OpenCV library and a little bit
of image processing (of which the Pi is more than
capable), we can give our robot computer vision, so that
it can target and follow objects, or (with the help of
some machine learning trickery) recognise objects or
even people.
One of our favourite toys at LXF Towers is our
DiddyBorg v2 robot, which may resemble a dinky
radio-controlled car but is actually an incredibly
powerful robot. The Borg series was designed by
PiBorg, brainchild of Kim Freeburn, who explains,
“The DiddyBorg is the six-wheel-drive robot that is a
homage to the Sojourner Mars Rover”. Check out the
rest of the Borg range at http://www.piborg.org/shop.
The DiddyBorg features six powerful 12V 100rpm
motors and is powered by ten AA batteries. Power is
distributed by the custom ThunderBorg board, which
can handle 5A per motor, has a multicolour LED (useful
for monitoring battery status) and we’re sure you agree
it looks the business. Rather than using some
complicated servo arrangement for steering, the
DiddyBorg rotates by turning its wheels at different
speeds. By turning the right wheels in the opposite
direction to those on the left, it is also capable of
spinning on the spot. It’s equipped with the Pi Camera
(which is a great thing to own even if you’re not building

We need to convert the image to HSV
so that OpenCV can better detect any
red ball-like objects to follow.
Free download pdf