|
Build a PC to
Servo Interface

I have been asked many times. "How can I connect my
PC to a servo" Their are many ways to accomplish this.
You can use servo controllers like the Kronos Robotics
EZServo. However
I was looking for a project to demonstrate the getpacket command
that the Athena chip has. This command makes it ultra simple
to create a PC interface to the Athena Chip.
How does the getpacket command work?
The getpacket command is placed inside a loop.
It automatically checks the Athena's built-in 80 byte buffer and
loads data variables with the collected data. Once all the
defined data has been collected the command falls through so that
you can process the data.
In this project we want the getpacket command to
collect 2 values. We call them servonum and servodata.
servonum represents the servo number to modify and the servodata is
the value to set that servo.
Using the servo command makes it easy. The
servo command will send a servo pulse (in 10us increments) to any of
the IO ports.
Hookup

We show two servos connected but the program can adjust servos on IO
ports 0-5.

We used a few three pin headers to make the connection of the servo
to the breadboard.
Program
(download it here)
'simple PC to Servo Interface
'Maximum servos 6 for Athena, 9 for AthenaHS
const lastservo 5
dim tSERVO0
dim tSERVO1
dim tSERVO2
dim tSERVO3
dim tSERVO4
dim tSERVO5
dim tSERVO6
dim tSERVO7
dim tSERVO8
dim cmdidx,servonum,servodata
dim x,tmp,tdelay
configio 0,1,2,3,4,5,6,7,8
clearall
loop:
gosub procservos
getpacket loop,cmdidx,servonum,servodata
if servonum > lastservo then
goto loop
endif
arrayset tSERVO1,servonum,servodata
goto loop
'-----------------------------
procservos:
for x = 0 to lastservo
arrayget tSERVO1,x,tmp
tdelay = 255 - tmp 'Calculate wait value
servo x,tmp 'Servo Control command
servo 10,tdelay 'Compensate for servo delays
(dummy call)
next
return
The procservos subroutines does all the servo
processing. For the most part it just takes the data retrieved
with the get packet command and calls the getpacket command. A
variable tdelay is used to create a time wasting dummy servo
command.
Why waist time?
The servo pulse needs to be sent about once every
20ms. If all 6 servos are set to a low value this will
create a much shorter interval than if all the servos are set to a
high value. To keep a constant interval we compensate by
making a dummy servo call for each servo. The value for this
servo is calculated based on the servo being serviced.
Bottom line it keeps the interval constant between
servo calls regardless of what the servos are set to.
Sending Commands
In order to send commands from the PC you send them
to the debug port. During programming you can use the debug
terminal to test the program.

As you can see just enter the servo number (in this
case 0) and the value. Click the send button. The Athena
will set that servo to 2000us
Once you have all the testing complete you can send
the data from another program via the serial port. The baud
rate is 9600.
You can also use the krconnect program. This
software was designed to aid you in testing your software. It
also sets up an object that you may reference

The krconnect program is free and can be
downloaded here.
Once installed check out the krconnect help files. Not that
installing the krconnect software will also install the krobj.
Hints
You must use the EZ232 driver when connecting to the
PC.
While this will serve as an adequate servo interface
it is not powerful as the CPServo CoProc. Its much simpler but
the servos may glitch a small amount will lots of PC to Athena
activity. In many case this may not matter. For instance
say you are moving a servo and then taking a reading with a Sonar
device. You would move the servo then take the reading.
This project is perfect for that type application. Another
approach is to turn off the servo. This is done by setting the
servo value to a 0. When a servo is turned off it wont glitch.
Parts
Easy RS232 Driver
Athena
Athena Carrier 1
7805 (100ma)
7.5V AC Adapter
9 Pin Cable
Breadboard and
Wire Kit
|