Page 200 - Build Your Own Quadcopter_ Power Up Your Designs with the Parallax Elev-8
P. 200
Chapter 7: Ser v o Motors and Extending the Ser v o Control System 179
The start method also contains this very complex statement:
cog[i] := cognew(readPins(@long[pins_array_address][i*2],
@long[pulsewidth_array_address][i*2]), @stack[i*20]) + 1
It is the instruction that creates several cogs to do the pulse-width measurements. This
instruction is in a loop that iterates i from 0 to 2. Substituting 0 for i in the first iteration
results in this:
cog[0] := cognew(readPins(@long[pins_array_address][0],
@long[pulsewidth_array_address][0]), @stack[0]) + 1
This really odd expression simply translates as:
Start executing the method named readPins using the beginning data pointed to
by the “pins_array_address” pointer and store the result in the first memory
location pointed to by “pulsewidth_array_address.” Also, use all the
memory needed for the cog located at the beginning of the “stack” memory area.
The index ‘i’ will increment to 1. Then the whole process will repeat with cog number 1,
and it will use the next sequential pin number and store the result in the next sequential
location in the pulsewidth array. The stack location is incremented by 20 due to the expression
@stack[i*20], which ensures that the new cog has plenty of memory space within which
to operate.
The readPins method is the heart of the RX object. I will not step through this method
line-by-line other than to point out the liberal use of the waitPEQ instruction in this method.
waitPEQ pauses the cog’s execution until a pin, which is being monitored, reaches a certain
state, normally high or low. Of course, the system counter continues to run, thus accumulating
a count directly proportional to the elapsed time. Therefore, the high and low times of a
pulse are easily determined using this instruction.
The last portion of the program is concerned with the extended servo outputs that are
handled by the Servo32v6 program along with the associated sub-object Servo32_Ramp_v1.
This program is a clever extension that will allow you to control up to 32 servos, if you
needed such a hefty requirement. I will not be discussing these programs though, since they
are not used in either of the two servo applications I discuss below. Just be aware that
operating a large number of servos simultaneously can represent a hefty current flow. Even
the standard Hitec HS-311 analog servo can take up to 180 mA when operating at no load.
The peak-current draw will, of course, go much higher if there is a torque load on the servo.
That would mean about an average 3-A current flow, if you were by any chance, trying to
run 16 servos at the same time. This is a heavy draw that could rapidly deplete a normal
battery.
Elev-8 LED-Lighting Controller
This project is actually a second revision of an LED-lighting controller that I built and
installed on my original Elev-8. That controller is shown in Figure 7.18. It worked quite well
and was based on the Parallax Basic Stamp II BOE. The LED transistor-driver circuits are
located under the hardboard labeled Elev-8 seen on the left side of the figure.
This controller worked correctly as I mentioned above, but I was a bit disappointed that
I could not dynamically control the light pattern once it was programmed. I made all the