# Landing Gear for Plane Pseudo Code...

Ok so for some background. Ive bought a plane happy with the foam and body parts. But, the wheels/gear were so poorly designed its stunningly stupid. It could have been built cheaper and better, the Chinese might want to look into that.

In any case, it falls on me to get the mechanics and electrical stuff right, which i can do. But the programming as usual is really holding me back im not good at it.

So heres a flow chart of the plan below. Note that the motor is a normal motor attached to a h-bridge, there is no conventional servo. The term " Servo" means servo mS value from RX )

ive also been looking here for PWM reading, without killing cpu cycles.

my psuedo-code looks like this:

//if Servo input = 600mS or less, gear down
//if Servo input = 800mS or more, gear up
// gear up when “up limit switch = high” and “dn limit switch = low” move motor CW
// gear dn when “up limit switch = low” and “dn limit switch = hi” move motor CCW

if servo = 600mS // command down
then :
motor = CCW until limit up = 0 and limit dn = 1

if servo = 800mS // command up
then :
motor = CW until limit up = 1 and limit dn = 0

Does this sound right ?
my brain hurts trying to think of all the possible logic combinations that would fail.
Pics below :

Hi PatrickZ.
Being an ex priavte pilot, having a lesson after 35 years of absence and watching numerous videos of RC-planes I say: By all means, use commercial products like ground controls and servos/receivers in the plane. I find it very hard to make better, more reliable stuff on Your own.
How do the "Big guys" do it, flying a 30 feet Concorde, a 747 modell? I don't know.
Can You ask people "in the business" how they manage with those "extra functions" like "gear up/down", smoke..?
Every plane is too beautifull to face an end else then standing on a poster.

``````read servo pin value then

if servo = 600mS  // command down
then :
motor = CCW until limit up = 0 and limit dn = 1
``````

That looks like blocking code. Turn the motor on counter clockwise and wait for the limit switches.

The loop could be non-blocking. If servo value is less than 600ms then set a boolean variable called going up true.

If going up is true and the upper limit switch isn't made then run the motor counter clockwise.

If going up is true and the upper limit switch is made then don't run the motor anymore.

Similar code for going down.

That would allow you to reverse directions in the middle or take care of any other tasks that the micro needed to while the gear is moving.

Being an ex priavte pilot,

No such thing. Your Airman's Certificate is still valid. You are just not current.

I need to re-design the existing mechanics for my Mechatronics class.

Delta_G

Yes the things you say worry me. The "in-between" condition may turn unexpected from the nanos' perspective.

I dont know what to do though.

You just have to separate the idea of deciding when the gear should move from the idea of moving the gear.

Something akin to:

``````boolean gearUp;

void loop(){

if(servoSignal > 600) gearUp = true;
else gearUp = false;

if(gearUp) {
turn motor off;
}
else {
turn motor on going up;
}
}
else  //  gearUp is false so gear should be down
turn motor off;
}
else {
turn motor on going down;
}
}
}
``````

The key point is that you are just deciding when to turn the motor on or off, you're not sitting and waiting for anything to happen.

Delta_G that pretty much does what I want! it explains my fear of "philosophical" failing...

and three can run in sequence ?

I understand the first of those three sentences.

Do you mean 600mS [sic]?

Did you mean 600us? (Can’t find the mu symbol on my Android keyboard)

What....
No multi axis gyro sensor feedback + barometric pressure to self initiate the landing gear?
This might as well be the bubble gum and dental floss forum /smile.

TheMemberFormerlyKnownAsAWOL:
Do you mean 600mS [sic]?

yes, uS its a RC / Tx / Rx servo standard thing. I goofed it. so i think that means I need to call the library function ?

How do I limit the length of the attachment code so it isn't a mile long ?

Of Delta_G ive got this far, I think Ive goofed it up in multiple places though...

void setup() {
// put your setup code here, to run once:

pinMode(2,INPUT); // Take RC mS value from RX into this Nano
int rcINpin;

pinMode(3,INPUT); // From Nose wheel down limit switch
pinMode(4,INPUT); // From Nose wheel up limit switch
int NoseWheelDown = 0;
int NoseWheelUp = 0;

pinMode(5,INPUT); // From left wheel down limit switch
pinMode(6,INPUT); // From left wheel up limit switch
int LeftWheelDown = 0;
int LeftWheelUp = 0;

pinMode(7,INPUT); // From right wheel down limit switch
pinMode(8,INPUT); // From right wheel up limit switch
int RightWheelDown = 0;
int RightWheelUp = 0;

pinMode(9, OUTPUT); // To nose wheel lead screw H-bridge, 1 to start 0 to stop
pinMode(10, OUTPUT); // To left wheel lead screw H-bridge, 1 to start 0 to stop
pinMode(11, OUTPUT); // To right wheel lead screw H-bridge, 1 to start 0 to stop
// Each of these pins can be 1 or 0 independently of the other two.

pinMode(12, OUTPUT); // Direction for H-bridge 1 or 0 for CC or CCW,
// applies to pins 9,10,11 simultanously
int HbridgeDir = 0;

boolean gearUp; // Create a space this condition

}

void loop() {

if(servoSignal > 1200uS) gearUp = true; // program TX "gear channel" switch to 1200 uS for UP, 1700 uS for DOWN
else gearUp = false;

if(gearUp) { // nose conditional loop
if (pin 4){ // upperLimitSwitch, pin 4 is hi
digitalWrite pin(); // pin 9 low stops nose lead screw
}
else {
turn motor on going up; //
}
}
else // gearUp is false so gear should be down
turn motor off;
}
else {
turn motor on going down;
}
}

}

[/quote]
[/quote]

PatrickZ:
Of Delta_G ive got this far, I think Ive goofed it up in multiple places though...