[Company Logo Image]        Gear Retract 

Home Up Contents Search Articles Caveat Purpose Notice                                                           

Gear Assembler

Credit:  The program shown on the sidebar was written by CatsEyesIronsides attempted the code and CatsEyes sorted it out ;-)

Mainly used in glow-powered aircraft due to weight considerations, retracting undercarriage can make some models very authentic.  For example, nothing beats a Spitfire with the gear up.  Only then does the true beauty of that elliptical wing come through.

Photo from "Spitfire" by Alfred Price ISBN 1 85648 015 1 page 91

But, most transmitters have a simple switch that toggles the gear up or down.  In turn, most gear on the model moves up or down rather suddenly. Wouldn't it be nice to have the gear move slowly?  How about having one leg move differently than the other as is the case in many real airplanes, such as the Spitfire above?  The right oleo is almost in the wing while the left leg is starting to come up.  How about using a PIC to help out?

For the sake of simplicity, this module will consider a two leg main undercarriage where the undercarriage doors are attached to the gear oleo.  We will use a high torque proportional servo for each leg.

The PIC will have to be configured so that we have one INPUT (feeding from the Gear Switch channel of the receiver) and two OUTPUTS, left and right.   Therefore the configuration looks like:

GP3   INPUT

GP1   OUTPUT_LEFT

GP2   OUTPUT_RIGHT

 

Photo by Ironsides

Note:  Only the SIGNAL lines from each servo need to go to GP 1, GP2 and GP 3 so we should arrange a 5 volt and Ground buss to minimize wiring. 

Let us suppose that on this aircraft the left leg starts to drop first and then at the 45 degree point the right leg comes down.  On retract, the left leg comes up first and at the 45 degree point the right leg comes up. 

Note:  The code allows the user to change the variables for the end points of the servo displacement, as well as the point at which any sequencing of the second leg, if at all, will occur.

The command issued from the transmitter will be GEAR_UP or GEAR_DOWN.  That is, the transmitter will send a signal every 20 milliseconds that has a Pulse Width Modulation (PWM) of 1 milliseconds or 2 milliseconds.  This simple binary logic must now be translated into smooth and sequenced gear operations. 

The next thing we should think about is a smooth timer that will act somewhat like a stepper motor on a flatbed scanner.  We want to move the gear through 90 degrees in small increments - how about 100 steps?  In doing so, we have to use the PIC to generate a signal on the output pins GP1 and GP2 that moves the PWM from 1 milliseconds to 2 milliseconds, or vice versa depending on whether the gear is going up or down.  So in 100 steps, it goes from 1.0 millisecond to 1.01 to 1.02 ...1.99 to 2.0 milliseconds - or vice-versa. 

In essence, for each servo we need to move the Pulse Width Modulation (PWM) from 1 millisecond to 2 milliseconds.  Or, as discussed earlier, we need to move from value 100 to value 200.  The basis for the code is already for us in TIMER OUT !  Just remember that using this module, there are 25 cycles for half a second and 50 cycles for one second.  If, for example, we want the gear to cycle (start to finish) in 10 seconds, we have to count to 500 loops.

To make life easier, let us sequence (start the right leg moving)  when the left leg value hits a value of 150.

The following is the outline of the assemble code by CatsEyes :

The code a "ONE_PULSE" routine that would handle receiving and measuring an input pulse, followed by output pulses for the two channels. The advantage here is that one routine takes care of all the "low-level" functions. Even if you're just ignoring the input value, for instance, it's still handy to have the routine wait for the pulse as that handles the 50-Hz pulse timing for you.  Also, the "high-level" routine can just set the two output values (or leave them alone if nothing should change) and expect that the output pulses will change as a result.
 
The assumption has been made that we're going to start with an output of 1.0mS for both servos, and that that will represent "gear down." I.e., when the plane is first powered up, the servos will immediately slew to the "down" position, regardless of where they were before. This is done by initializing OUTPUT_LEFT and OUTPUT_RIGHT both to 100 (for 1.0mS), then starting up the process.
 
The top-level functionality, then, is:
 
1) Set both left and right servos to "down"
2) Wait for "gear up" command from pilot
3) Do "gear up" sequence
4) Wait for "gear down" command from pilot
5) Do "gear down" sequence
6) Go to step 2)
 
For the "gear up" and "gear down" sequence, the code is divided into three parts (this might not be the most elegant way to do it, but it works). The first part is the left gear movement (right gear stays fixed). The second part is both channels moving together. And the third part is the right gear movement alone. E.g.
1) Move left gear from 100 to 150 (right gear stays at 100)
2) Move left gear from 150 to 200 and right gear from 100 to 150
3) Move right gear from 150 to 200 (left gear stays at 200)
 
The "low-level" routine is:
1) Wait for start of input pulse
2) Time input pulse and store its value
3) Do output pulse for Left channel
4) Do output pulse for Right channel
5) Return to calling program
 
Since the gear movement takes 10 seconds, that translates as 500 pulses. Since there are only 100 "steps" in servo movement, we have to wait for 5 pulses before each "step" (i.e. changing the output value to another step). To handle this there is a useful little function called FIVE_PLS that just calls ONE_PULSE five times.

The ASSEMBLER code for this application is shown in the sidebar. 

Home ] Up ] Gear Assembler ]                                                                                                                                               

Send mail to ironsidz@hotmail.com with questions or comments about this web site.
Copyright © 2003 
Last modified: March 18, 2004