away (on both the x86 Ubuntu and Raspbian Jessie),
however, I did not like the names assigned to the
joysticks and buttons of the Rock Candy controller. To
make a long story short, I modified the test code until I
could use it like a simple library. JsLib.py implements a
joystick class which implements:
Init(device_name) Initialize joystick
Name() Return joystick and manufacturer
Read() Return next joystick event
The events are returned as a list with two
where event identifies the joystick event (one of 12
joystick axe, or one of 11 buttons) and value gives the
new value of the axis or button. You will be able to see
how this library is used to implement an RC style remote
control later in this article.
USB Wi-Fi and Rock Candy adapters mounted on
While this simple approach to steering does not
explicitly provide proportional steering, varying the speed of
the motors using the left joystick provides for a similar
effect. In the future, I intend to provide proper proportional
steering. Now that I could see that Hobbit was responding
correctly (with speed and direction of motors) to the
joystick, it was time to cut the tether and let him loose.
It’s not perfect since it waits for the next joystick event
(i.e., it is blocking), but it suffices for the RC control demo
program I wrote for driving Hobbit around. I’ll write a nonblocking multi-threaded library in the future.
A Fly in the Ointment
I ended up using both analog sticks and emulated a
standard two-channel RC remote:
• Left analog joystick Y axis (up/down): Forward/reverse
• Right analog joystick X axis (left/right): Turn left/turn
After shutting Hobbit down properly, I disconnected
the Ethernet cable and USB adapter, then connected a USB
power bank and plugged the Wi-Fi adapter in (I had
previously connected a 4xAA battery pack to power the
motors). Unfortunately, Hobbit would no longer boot.
I could have used just one joystick, but I wanted it to
work just like an RC remote.
The combination of the SG90 micro servo, Wi-Fi
adapter, and Rock Candy USB adapter was a bit too much
for the Raspberry Pi Model B to be able to handle.
This leaves the two D-pads — HOME/SELECT/START
and L1/L2/R1/R2 — unused. However, I have plans for them
in the future; for example, switching modes between RC
control, random walk, line following, etc. Refer to Listing 1.
The fix was simple: temporarily disconnecting the SG90
servo allowed Hobbit to boot.
The left analog stick worked well for controlling the
speed and forward/reverse motion. It felt very natural, and
when the stick snaps back to the center, Hobbit stops.
Steering with the right analog joystick also worked great. I
implemented the following simple steering functionality:
- if x < -0.9, spin Hobbit to the left (in
- if x < -0.1 and x > -0.9, stop the left motor,
causing a left turn
- if x > 0.9, spin Hobbit to the right (in
- if x > 0.1 and x < 0.9, stop the right motor,
The Pi Droid Alpha controller used on Hobbit can select
an external power input for powering servos, so I will just
power servo 1-4 connectors from the external battery pack,
and servo 5-8 connectors from the Pi’s 5V by setting the
power select jumpers. Long term, I will likely feed power to
Hobbit directly on the 5V/GND pins of the GPIO connector,
as this will bypass the current limit of the polyfuse.
Alternately, I can switch out the Model B for a
Raspberry Pi A+/B+/Zero/2/3 and keep powering it with a
micro USB cable.
With the power issue taken care of, Hobbit can now be
driven around just like any RC car. My nephews will have a
lot of fun with this. I’ll pick up a couple more controllers, so
they can drive bots around at the same time. For more on
Hobbit, visit www.mikronauts.com/robot-zoo/hobbit.
In the next article, I will add another sensor or two,
showcase a new chassis, and start implementing robotic
SERVO 06.2016 33