Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

JVM Languages

Mixing ActiveX with Java


July, 2004: Mixing ActiveX With Java

Robots and Servos

The robot used in this article is a model of simplicity. The frame is made from Radio Shack perf boards and a small piece of bass wood (available from almost any hobby shop). The large wheels are also from a hobby shop and are made for model airplanes. A few angle braces and a small caster from Home Depot complete the mechanical construction.

The two drive wheels are inexpensive servo motors made for radio-control vehicles. These make motor drive very simple. Each motor shaft connects internally to a potentiometer that controls a pulse-generating circuit. To move the motor, you send a pulse to it approximately every 20 ms. The motor generates its own pulse and compares the two pulses. Suppose the potentiometer in the motor (which is connected to the shaft) is set so that the internal circuit generates a 1-ms pulse. If you send a 1-ms pulse, the motor will not move. However, if you send, for example, a 1.2-ms pulse, the motor will move until the internal circuit is also generating a 1.2-ms pulse. Or, if you sent a 0.8-ms pulse, the motor would move in the opposite direction to make the internal pulse match the pulse you supply.

Normally, these servos don't rotate. They simply move in an arc (useful for an airplane's control surface or a car's steering wheel, for example). However, it is possible to modify the servo so that its potentiometer is not connected to the shaft (you also have to remove the stops that prevent it from rotating through 360 degrees). If you adjust the potentiometer so that the servo generates a 1.5-ms pulse, you can easily control the motor. A 1.5-ms pulse makes the servo hold position. A shorter pulse makes the motor rotate in one direction and a longer pulse makes the motor rotate in the opposite direction.

You can even control the speed of the motor by controlling the length of the input pulse. A 1.6-ms pulse makes the motor move more slowly than a 2-ms pulse because the motor perceives more error with a 2-ms pulse. Of course, with the potentiometer disconnected from the shaft, the motor can never correct the perceived error, so the motor just continues to turn as long as you keep supplying pulses.

This is perfect for controlling a small robot. Since the two servos are mounted back to back, if you feed the same pulse to both motors, the robot will spin in place. That's because if you rotate both motors clockwise (for example), they will spin in opposite directions since they are back to back.

The solution is to turn one wheel clockwise and the other one counterclockwise. This requires two separate signals, one to drive each wheel. Of course, if you want the robot to turn, you can send identical pulses to each wheel.

—A.W.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.