Auto-attitude adjuster for a model glider. (auto-pilot)

kando

Senior Member
In this project I wanted to try to imitate some sort of Auto-pilot an Auto-attitude adjuster for a model glider without radio control. I am not sure I have the program correct yet. I was thinking that timing the checking of the switches somehow may be better. I'm not sure it is necessary though. I think this program might be quick enough to flow through the main part. After all, you don’t want the model to be waiting for the next loop of the main program just to get another adjustment to flight. It might be too late! Anyone have any thoughts on that?

I have used a PICAXE 28X2 because it has more than enough input output pins and plenty to spare for future use. What I am trying to do with this auto pilot is to get more forward distance out of my glider and less downward/vertical fall which will make the glider stay in the air longer. With this idea I hope to achieve it.

Simple tilt switches are set up so that they are switched off when the model is level and as soon as the model tips to one side, down forward or tilts up the switches inform the program running in the PICAXE chip what has happened and the program will try to correct the movement back to a glide path. Yaw movement is calculated by the program by analysing the roll and pitch and corrects it.

The system as shown is cheap to implement. It does not have sophisticated sensors and does its corrections from data given in the program which the user can change. This is necessary because not all models have the same flying capabilities. Some are heavier; some lighter, faster, slower or have different servos etc. Therefore it is essential that the user can calibrate their own model with their own data. I have created a starting point of general data which is given in the program for the user to adjust for their model.

The 28X2 module is light and can work from 7-12V dc from pin 28 and therefore can run off the servo batteries normally at about 8V dc. So no extra batteries!
When testing the tilt switches it is very difficult to see if they are on or off so by adding 4 LEDs so that when the tilt switch closes the LED lights. Adjustment can be made and seen when bending the legs of the switches.

I hope this idea will be useful to others and any comments are welcome. One thing I can think of is if the model flies very well you might have a problem getting it back down to earth. You may need some other method. Something to ponder.

Here is the Wire diagram I am using at the moment:
Attitude Model.jpg

and here is the code I'm using at the moment.

Code:
;PICAXE Attitude Adjuster for free flight gliders
;No Radio Control just the servos.
;Program by Ken Anderson. 2013 v1.0
;
;directives
#picaxe 28X2 module
setfreq em32 ;external module frequency of 32MHz

;The reason I choose this chip/module is because...
;1. 7-12 supply. (you can use the servo battery normally about 8V)
;2. It has a scratchpad memory for the data table accessable via 1 dimensional array commands
;3. it has the serial input socket already attached and ready to use
;4. it is very light especially as you don't need the extra batteries
;5. it has plenty of spare input/output pins for future use for example:
;			 a. addition of distance sensor from the ground for program landing
;			 b. addition of another servo for an air-brake/spoiler to bring it down to earth
;			 c. air speed sensor so that you can reduce speed when you need to

	
;Pinouts for information                        N/U = not used
;                serial out  1|¯¯¯|28  VIN (7-12V)
;               serial in    2|===|27  0V
;                      LED   3|===|26  Reset
;                      0V    4|===|25  +5V 
;      LED L         <->c.0  5|===|24 b.7<-> LED R
;     R_L tilt sw    <->c.1  6|===|23 b.6<-> Roll right tilt sw
;      N/U           <->c.2  7|===|22 b.5<-> Servo Yaw data line
;      N/U           <->c.3  8|===|21 b.4<-> Servo Roll data line 
;      N/U           <->c.4  9|===|20 b.3<-> Servo Pitch data line
;    LED D           <->c.5 10|===|19 b.2<-> interupt pin N/U
;    LED U           <->c.6 11|===|18 b.1<-> interupt pin N/U
;     N/U            <->c.7 12|===|17 b.0<-> interupt pin N/U
;   P_up tilt sw     <->a.0 13|===|16 a.2<-> N/U
;   P_Dn tilt sw     <->a.1 14|___|15 a.3<-> N/U

;variables
symbol P_Up		=	pinA.0	;	pitch up tilt switch
symbol P_Dn		=	pinA.1	;	pitch down tilt switch
symbol L_roll	        =	pinC.1	;	Left roll tilt switch
symbol R_roll	        =	pinB.6	;	Right roll tilt switch

symbol servoRoll	=	B.4		;	Servo data line
symbol servopitch	=	B.3		;	Servo data line
symbol servoYaw         =	B.5		;	Servo data line

symbol LED_Lroll	=	C.0		;	LED for left roll tilt switch
symbol LED_Rroll	=	B.7		;	LED for right roll tilt switch
symbol LED_PDown	=	C.5		;	LED for pitch down tilt switch
symbol LED_PUp          =	C.6		;	LED for pitch up tilt switch

symbol BCD_Pos          =	b5		;	Tilt switch Position indicator in BCD
Symbol ScratchM_pos    =	b6		;	Position in the scratchpad memory of correction info

;INFO.
;1 = high 0 = low value taken from tilt switches
;servo command = one end = 75 centre = 150 other end = 225

;TABLE      Note. BCD          Tilt switches	             Servos	
;                               Lr  Pd  Rr  Pu      Roll pitch  Yaw
;level flight		    0   0   0   0   0       150   150   150	               centre positions
;Pitch up only		    1   0   0   0   1	    150   140   150	
;right roll only            2   0   0   1   0	    160   150   150	
;Right roll + pitch up      3   0   0   1   1	    160   140   180
;Pitch down only	    4   0   1   0   0       150   170   150
;     ----                  5   0   1   0   1	     -     -     -	                Impossible(pitch down+pitch up at same time)
;Right roll + pitch down    6   0   1   1   0	    160   170   75
;     ----                  7   0   1   1   1	     -     -     -                         Impossible(pitch down+pitch up at same time)
;Left roll only             8   1   0   0   0	    140   150   150
;Left roll + pitch up       9   1   0   0   1	    140   140   180
;     ----                 10   1   0   1   0	     -     -     -                         Impossible(Left roll + right roll at same time)
;     ----                 11   1   0   1   1	     -     -     -                         Impossible(Left roll + right roll at same time)
;Left roll + pitch down    12   1   1   0   0	    140   170   225
;     ----                 13   1   1   0   1	     -     -     -	                     Impossible(pitch down+pitch up at same time)
;     ----                 14   1   1   1   0	     -     -     -                         Impossible(Left roll + right roll at same time)
;     ----                 15   1   1   1   1	     -     -     -                         Impossible(Left + right roll+up+down at same time)

;7 positions in BCD not used here but could be used for other tasks


Init:
;put all correctional servo data into scratchpad memory
;NOTE: When trials commence these may need to be changed in order for a particular model to fly as wanted.
;use the serial input from a laptop to change the program data
;this is general data

;    Roll      Pitch     Yaw
put 1,150:put 2,150:put 3,150		;correction level flight
put 4,150:put 5,140:put 6,150		;correction pitch up only
put 7,160:put 8,150:put 9,150		;correction Right roll only

put 10,160:put 11,140:put 12,180	;correction Right roll and pitch up
put 13,150:put 14,170:put 15,150	;correction Pitch down only
put 16,000:put 17,000:put 18,000	;Just for ptr

put 19,160:put 20,170:put 21,75         ;correction Right roll and pitch down
put 22,000:put 23,000:put 24,000	;Just for ptr
put 25,140:put 26,150:put 27,150	;correction Left roll only

put 28,140:put 29,140:put 30,180	;correction Left roll and pitch up
put 31,000:put 32,000:put 33,000	;Just for ptr
put 34,000:put 35,000:put 36,000	;Just for ptr

put 37,140:put 38,170:put 39,225	;correction left roll and pitch down

put 40,000:put 41,000:put 42,000	;Just to complete the BCD
put 43,000:put 44,000:put 45,000	;Just to complete the BCD
put 46,000:put 47,000:put 48,000	;Just to complete the BCD

debug

Main:
;set dynamic variables to 0
b5=0:b6=0

;keep looking at tilt switches and deal with accordingly

IF L_roll=0 AND P_Dn=0 and R_roll=0 and P_Up=0 then: BCD_Pos=0: goto correct_attitude: endif
IF L_roll=0 AND P_Dn=0 and R_roll=0 and P_Up=1 then: BCD_Pos=1: high LED_PUp: goto correct_attitude: endif
IF L_roll=0 AND P_Dn=0 and R_roll=1 and P_Up=0 then: BCD_Pos=2: high LED_Rroll: goto correct_attitude: endif
IF L_roll=0 AND P_Dn=0 and R_roll=1 and P_Up=1 then: BCD_Pos=3: high LED_Rroll: high LED_PUp: goto correct_attitude: endif
IF L_roll=0 AND P_Dn=1 and R_roll=0 and P_Up=0 then: BCD_Pos=4: high LED_PDown: goto correct_attitude: endif
IF L_roll=0 AND P_Dn=1 and R_roll=1 and P_Up=0 then: BCD_Pos=6: high LED_PDown: high LED_Rroll: goto correct_attitude: endif
IF L_roll=1 AND P_Dn=0 and R_roll=0 and P_Up=0 then: BCD_Pos=8: high LED_Lroll: goto correct_attitude: endif
IF L_roll=1 AND P_Dn=0 and R_roll=0 and P_Up=1 then: BCD_Pos=9: high LED_Lroll: high LED_PUp: goto correct_attitude: endif
IF L_roll=1 AND P_Dn=1 and R_roll=0 and P_Up=0 then: BCD_Pos=12:high LED_Lroll: high LED_PDown: goto correct_attitude: endif

goto main

correct_attitude:
;get servo correction information from scratchpad memory
ScratchM_pos=BCD_Pos*3
ptr=ScratchM_pos+1

;b7=@ptrinc	;test purposes
;b8=@ptrinc	;test purposes
;b9=@ptr	;test purposes

servo [45536],4,@ptrinc;roll
servo [45536],3,@ptrinc;pitch
servo [45536],5,@ptr;yaw

;switch off any LEDs
low LED_Lroll:low LED_Rroll:low LED_PDown: low LED_PUp

goto main
end
 
Last edited:

tony_g

Senior Member
just a thought, if you intend on using tilt switches wouldnt there be the possibilty of any slight turbulence causing that to be seen as a false input of pitch/roll leading to the servos constantly outputting and over compensating causing the glider to seem to possibly jerk around on many axis?

after watching a video my brother made of his X8 with an onboard camera even when he was flying relatively level and straight and even when his ardupilot had control you could clearly see varying turbulence effects on the different axis of the plane in the video.

if space is not too much of an issue could you possibly look at replacing the tilt switches with a dual/triple axis solid state gyro, that would allow you to add a possible finer error margin in the readings to allow for any turbulence and have a smooth linear response dependant on the gyro data ranging from a few small steps of the servo similar to adding a couple of clicks of trim to a larger deflection of the control surface if the data recieved was reading a significant difference from "level flight".

tony
 

kando

Senior Member
if you intend on using tilt switches wouldnt there be the possibilty of any slight turbulence causing that to be seen as a false input of pitch/roll

and...
dual/triple axis solid state gyro
Tony thanks for your reply. I Have not created the breadboard for this yet and so I don't know whether it will work to my satisfaction. I have a glider to try it in though.
The dual/triple axis solid state gyro sounds very expensive (is it?) and I want something that is easily obtainable and cheap so that young people and children can get involved. It's not the flying bang on correct its how you can educate and enjoy messing around to understand principles that matter to me.

I have thought on what you said about turbulence etc and have thought perhaps another two switches to make gentle / medium/ rough weather data to cater for differing weather patterns so that the user can decide. Would need some more programming.
Kando
 

AllyCat

Senior Member
Hi,

Well, the "proof of the pudding" would be Does it actually Work?

However, as others have said, I doubt if the PICaxe can get sufficient "input data" just from four tilt (on/off) switches, it needs some form of "proportional" information. Also, what happens if both switches of a pair are "active" at the same time, perhaps because the glider is upside down?

In any case, the string of IF ..... ENDIFs is likely to be rather slow. It could be better coded, for example using something like:
Code:
Attitude = L_roll * 2 + P_Dn * 2 + R_roll * 2 + P_Up
ON Attitude GOTO address0,address1, .......  address15
Cheers, Alan.
 

kando

Senior Member
Hi alley cat,
I don't know as yet and if i need proportional input I could always add another set of tilt switches set at different angle not the best way but something. Perhaps weighted and sprung pots and connect to the ADC inputs.

I did think that the code may be slow to react and I am really pleased you have spotted that. My problem is I can't get my head around your solution. Could you explain it a bit more for us to understand more.
Kando.
 

kando

Senior Member
Bluejets
Thanks for that link.
Could be interesting to a lot of people. It doesn't seem to allow me any program control using a picaxe chip so no good there but excellent if that is what you need to get your helicopter flying without programming or electronics.
Kando
 

jojojo

Senior Member
Sorry jojojo but you have lost me on those links... what am i supposed to be looking at?

Well.

In order to "auto-pilot" an engine, you must acquire, in real time a lot of informations. They are comming from accelerometers, gyro, and so on. And, you must interpreted and react to these info's. Allways in "real time" (not so easy, even when working with ASM)

But that's not all :
-React to the info's must be interpreted, and corrected, "in the context" (here is why you need a PID)
-Secondly, these info's must be also corrected by a filter, which have very specific characteristics, depending of flying object ... (here is why you need a Kalman filter).

Cheers.
 
Last edited:

jojojo

Senior Member
Provided that your glider is aerodynamically stable you probably will not need PID control

Just a personnal opinion : NO
 

AllyCat

Senior Member
Hi,

Hi alley cat, ...... Could you explain it a bit more for us to understand more.
The tilt switches just provide binary values of 0 and 1 so my code combines them (into a nybble) to produce a unique number (0 ... 15) for each possible permutation. This can be coded (even with a PICaxe) in many ways; my version effectively creates: Attitude = (L_roll * 8) + (P_Dn * 4) ....... but using PICaxe's left-to-right calculation sequence.

Then the program jumps to (just) the required routine (or subroutine if you use ON GOSUB).

IMHO a simple (slow) glider might work without "exotic" computations, but you probably do need a propotional (analogue) "error signal". Imagine walking quickly, but blindfolded, around a busy room if somebody is only allowed to say that you are too far "left" or "right".

Cheers, Alan.
 

srnet

Senior Member
I have used a PICAXE 28X2 because it has more than enough input output pins and plenty to spare for future use. What I am trying to do with this auto pilot is to get more forward distance out of my glider and less downward/vertical fall which will make the glider stay in the air longer.
Bear in mind that that the trim attitude for maximum distance and staying in the air longer will be different, and the differance will change depending on the air conditions (the wind) around the glider.
 

f2cf1g

Member
Keeping a model aircraft in the air for as long as possible without external control (R/C) is the aim of free flight competition aeromodelling. A lot is known about this subject. The aerodynamic design of the aircraft alone is sufficient to provide stability on the glide. Your idea of adding an automatic stabilising mechanism to improve duration is interesting but I suspect it would make little difference in the end because, in practice, duration tends to be limited by the lift provided by the air that the model is flying through. What definitely would help is a means of sensing lift, e.g. a variometer input, then devising a control algorithm which would keep the model in it. You are correct in thinking that a means is required to get the model down!
 

Jeremy Harris

Senior Member
I've spent a lot of time trying various techniques for auto stabilisation of aircraft. If you use any acceleration-sensitive sensor, like a tilt switch or accelerometer, or even a pendulum connected to a pot shaft, then you cannot get any form of working stabilisation without additional acceleration sensing in all three axes. The problem is that vertical acceleration (as caused by up and down drafts) will give spurious inputs to the control system, as does side slip and changes in forward velocity. These all need to be filtered out, faster than the loss-of-control response time of the aircraft (for example, before it's rolled so far as to make aileron control on it's own enough to correct the roll attitude and prevent a spin/stall.

Two ways I've found that work very well are :

1. Use a combined three axis accelerometer and three axis rate gyro module. Unfortunately the mathematics gets beyond the capability of a Picaxe with this method, as the accelerometer data has to be used to make real time corrections to the rate gyro data (with axis compensation where pitch, roll and yaw produce resultants in the "wrong" axis) such that you c an obtain true pitch, roll and yaw angle. Once you have the three angles you can then use them to provide feedback against the required angles. There are many cheap and readily available systems available that use just this approach, from budget solutions from companies like Hobby King through to some very interesting open source projects, often using the Arduino to get the required processing speed.

2. Use passive infra red sensing of the sky and ground to establish the true attitude of the aircraft in pitch and roll (but not yaw). This works by using the fact that the sky is always cold when compared to the ground, so if two IR sensors are placed at the wing tips facing outwards (for roll sensing), then the aircraft will be level when both sensors have the same output (indicating that both are seeing the same proportion of sky and ground). If the aircraft rolls then the sensor on the high wing tip see more of the sky than the sensor on the low wingtip and you can use this imbalance to command the ailerons back to give wings level. The sensors I used were made by Melexis and I probably still have a few of them around if you want a couple to experiment with. A Picaxe could probably control a glider in roll with such a system. There is a commercial system available that also uses these Melexis sensors as an auto-stabilisation system, but I can't recall the name of it at the moment.
 

AllyCat

Senior Member
Hi,

2. Use passive infra red sensing of the sky and ground ..... This works by using the fact that the sky is always cold when compared to the ground....
That's really interesting, it's the reverse of how a conventional "light" sensor (visible or near Infra Red) would work. For the un-initiated "PIR" refers to the "far" IR wavelengths (i.e. NOT those used for IR remote controls, etc.) which correspond to temperatures in the region of 300 K (i.e. 25 C).

Unfortunately, those sensors are not quite as low-cost (or readily available) as Visible/near-IR silicon phototransistors (which respond to light at the surface temperature of the sun, i.e. around 5,000 K). I wonder if "normal" light sensors could be made to work at all (for "educational" rather than "optimum" purposes)?

Cheers, Alan.
 

Jeremy Harris

Senior Member
I have a few brand new Melexis MLX90247ESF-DSA sensors sat here doing nothing at the moment if someone want to play with a couple. I think they were around £10 -£12 each when I bought them, but if anyone wants some to play with they could have a pair of them for £6 inc postage within the UK, first come first serve, as I only have 8 of them spare (4 pairs). PM me if interested. The data sheet for these sensors is attached.

View attachment 3901090247P006.pdf
 

kando

Senior Member
Re the Attitude = L_roll * 2 + P_Dn * 2 + R_roll * 2 + P_Up
Thank you Alleycat...
its coming through into my brain.... excellent thanks.
Kando
 

crowland

Member
I doubt that an intertial sensor such as a tilt switch will work because the aircraft will accellerate or decellerate as the pitch changes and this will remove most of the signal. Similarly if you are in a properly coordinated turn there will be no sideways force because of the bank. This is something I know about because I'm a glider pilot and instructor.

Lack of intertial information is what makes cloud flying impossible without instruments because your sense of balance is sensitive to inertial forces and gives you no useful information. In fact it's usually wrong and you have to work at ignoring it.

A more likely way would be to use light sensitive resistors to detect the ground/sky brightness difference. Have a pair looking forwards and backwards for pitch and a pair looking left and right for bank.

Connect each pair as a potential divider, read the difference as an analogue value and output this to the appropriate servo.

Chris
 

kando

Senior Member
Crowland,
Thank you very much for the insight and I will invest some time to look into the light sensitive issue. jeremy Harris and Alleycat came to a similar solution so I won't be building anything just yet. Got to do some homework now.

Thanks very much all of you.
Kando
 

bluejets

Senior Member
Bluejets
Thanks for that link.
Could be interesting to a lot of people. It doesn't seem to allow me any program control using a picaxe chip so no good there but excellent if that is what you need to get your helicopter flying without programming or electronics.
Kando
Well, the thought behind showing you this was NOT to do with choppers but rather your application.
If you look then you would see it has 3 gyros onboard that "perhaps" you can tap into and use your "picaxe" to do whatever you want with.
At the price for the piezo gyros alone I thought it would have been a "steal" and give you the necessary sensors.
I would have thought the choice between a tilt switch and a piezo gyro would be glaringly obvious, but perhaps beyond the forest there.
 

Jeremy Harris

Senior Member
I've exchanged a PM or two with Kando and thought it useful to post the basic interface I used for roll sensing using the Melexis thermopile sensors, so others could see it and comment:

Roll sensing amplifier.jpg

I attached the data sheet for the sensors to an earlier post in this thread. The sensor output is very small, around 46 µV per deg C for variations in long wavelength IR seen at the sensor window. The sky will typically have a temperature of around 20 to 50 deg colder than the ground (within the wavelength range of these sensors) so a fair bit of amplification is needed to get a signal that a Picaxe can read with a reasonable degree of resolution. I didn't come up with this idea, BTW, I got it from this project: www.ctie.monash.edu.au/hargrave/Bil-Bristol.pdf

I used a gain of 1005 (just because I happened to have some high stability 200 ohm resistors to set the gain of the INA122 instrumentation amp I used). This gives an output to the Picaxe of about 46mV per deg C. Because the sensors act differentially, a +1 deg C change in one (due to roll angle) will give a -1deg C in the other, so in practice the Picaxe analogue input sees a change of about 92mV for a roll that gives a 1 deg C temperature change.

Using the READADC10 command with the default 5V Picaxe supply and analogue reference gives a resolution of around 18 to 19 bits of change for a 1 deg C per side temperature imbalance, which in practice seems to be OK.

I used this as a crude (but effective) means of providing an artificial horizon, using a Picaxe driving some LEDs to give an indication of roll angle. It worked OK in clear air, but when tested in fog (which is what I was trying to make the thing for, accidental flight into cloud in a microlight) the sensors didn't get a good enough temperature differential due to water vapour IR absorption. As shown by the commercial Co-Pilot product that uses the same sensors the principle does work fine for model aircraft.
 

kando

Senior Member
Thank you Jeremy neat way of creating the sensor array and not too difficult to work a program around I hope.
Thanks for sharing the diagram for others to see as well.

Speak to you soon
Kando.
 

Jeremy Harris

Senior Member
One thing to note is that you need a way to do a "wings level" calibration for each flight. I added a button that I could press when the wings were level to set that point as a variable in the Picaxe code for that flight. This is because there will always be some slight drift and temperature effects on both the amplifier and the Picaxe A/D converter, so you need a simple way of setting the reference up each time.

For my project all I did was add a button that whenever it was pressed reset the nominal centre point that the code used as the "wings level" reference. Because I was using this technique as a cheap and crude, emergency use only, artificial horizon in roll only I was happy to just have this push button re-zero the reference at any time. In your case I suggest you use the same technique that the FMA Co-Pilot system uses, which is to set "wings level" at the start of the flight only, with the model held wings level for the initial zero point setting.
 

kando

Senior Member
Jeremy,
A question, if the model flies down hill and past some woodland trees on the right for example would this affect the sensors? Would it think that its right wing was not pointing at the sky/ground and compensate?
Kando.
 

Jeremy Harris

Senior Member
It depends how low the model is and how far away the trees are. The sensors have a fairly wide field of view (100 deg in each axis) so tend to average the temperature over a wide area. If the trees were a fair way away they they may not obscure much of the total field of view and so have little or no effect. If the model flew down a fair way below tree height on one side, with the trees fairly close so they blocked out a fair bit of the sky, then yes, they would have an effect.

In reality this doesn't seem to be a problem, because FMA have sold thousands of their Co-Pilot unit (which uses exactly this technique) over the years, and they consistently get good reviews (like this one: http://www.starcadplans.net/index.php/fma-co-pilot-an-honest-review.html). The Co-Pilot is aimed as a tool for helping people learn to fly RC models, by providing a two axis stabilising "autopilot" that will take control of the model and return it to straight and level flight when the RC controls are centred, allowing beginners a fail-safe recovery system if things get out of hand. If it suffered badly from the effects of flying past trees then I think this may have been reported on some of the model forums. I've not looked but a search of a few of the well-known model fora for "FMA Co-Pilot" should find some reviews and opinions.
 

kando

Senior Member
Jeremy,
Nice story about the Co-pilot unit on the link. Thanks for that and I can only but try the sensors and see what I can make from them so with that in mind I will have to PM you.
Thanks again for the input chaps.
I'll come back later to the subject.
kando
 
Top