Virtual Sensors
Virtual Sensors
Part 2 - Virtual Motor Interfaces
www.servomagazine.com/index.php?/magazine/article/august2012_Blankenship
by John Blankenship and Samuel Mishal
Discuss this article in the SERVO Magazine forums at http://forum.servomagazine.com
Some robot controllers have an integrated motor controller capable of
powering small DC motors. When projects require servomotors or large DC
motors though, most people assume the onboard controller is a waste — as
you will see, it does not have to be.
Last month, we examined how the virtual sensor techniques we developed for our RobotBASIC Robot Operating System (RROS) can be utilized in on-RobotBASIC projects. This month, we want to do the same for virtual motor interfaces.
When we began development of our RROS, we wanted
it to be able to manage the robot’s drive system no matter
what type of motors were used. Unfortunately, the
hardware being used did not have enough I/O pins to
handle all three of the motor options we wished to
support. We also knew that any solution we came up with
had to make each of the motor interfaces indistinguishable
from each other to other modules in the RROS. We hope a
summary of how we resolved our problems can benefit
others in similar situations.
Some robot controllers — such as Pololu’s Baby
Orangutan — contain integrated hardware to directly
control low current DC motors. When your robot is small
enough to use such motors, this feature can be very cost-effective. Hobbyists that wish to use larger DC motors or
even continuous-rotation
servomotors to power their
robot generally must use
other I/O pins to create a
serial interface to drive an
external controller for larger
DC motors, or to pulse the
control lines of their
servomotors. It would be
great if the pins associated
with the onboard motor
controller could be used for FIGURE 1.
these purposes, but usually the pins interfaced with the
controller are dedicated and not made available to the user.
Since the onboard motor controller used on most robot
controllers is typically a commercial IC, most hobbyists
assume that it can only be used for its designed purpose.
Our RROS needed every available I/O pin, so we had to find
ways to use the output from a DC motor controller to
control servomotors and to communicate with external
motor controllers.
We will use Pololu’s Baby Orangutan to illustrate our
points. It uses an ATmega328P as its core processor and a
TB6612FNG motor controller, enabling small DC motors to
be powered without additional hardware. In general, a
motor controller is just four transistors acting as switches
that are connected in an H-bridge as shown in Figure 1. If
we turn on switches (transistors) S1 and S4, the motor
turns one direction. Closing S2 and S3 reverses the current
through the motor and turns the motor in the opposite
direction. Both motor leads are shorted to ground if S3 and
S4 are closed, creating a brake condition due to the motor’s
back EMF. If all switches are open, the motor will coast
because both motor leads are effectively unconnected. The
nice thing about using a controller such as the TB6612FNG
is that it is easy to select the various states as described
above. For purposes of this article, we will assume we have
a Motor() function that can produce all of these states by
passing it one of these parameters: FORWARD, REVERSE,
BRAKE, or COAST.
Small DC Motors
In order to use the motor controller to power a small
SERVO 08.2012 67