View Full Version : Discussion Plane Stabilizing Electronics
jon-AMIG
May 18, 2006, 10:16 AM
Hi guys, Im building a slow flyer with an onboard "junior" flight computer. The flight computer will be made up with a 2axis accelerometer, Memsic 2125 & a PIC chip, PIC18F2520 & thats all.
Its called a "junior" flight computer is because the flight computer would only be stabilizing the roll & pitch axis of the plane. The chip would be programmed in C language. Thus Im having headaches in doing the programming :( . Im hoping to get some useful help from here.
I have singled out two areas of concern:
1. Servo control in C language
2. Programming the chip to read the accelerometer output & do some calculations based on the outputs
I hope to get some programs written in C here.
Thanks in Advance. :)
terryk
May 18, 2006, 11:37 AM
Interesting, I'm engaged in a rather similair project myself..
However I am programming in PIC assembler and using the thermopile horizon sensor.If i can get that working I plan to introduce a steering signal into the roll channel, initially by mounting the leveller sensor on a servo then by having a pulse width input channel and summing that with the roll sensor ip channel
So far I've got the servo pulse width O/P working. To do this I've created a real-time exec by using the on chip timer to generate interrupts at 0.1mS intervals. 255 calls to the exec constitutes the frame rate for the servo's, (and eventually the other activities.) Servo's have a minimum pulse duration of 10 frames, 1mS and a maximum of 20 frames. Thus a bit of code counts frames and when the frame count is less than the demand value of the servo a discrete is turned on, otherwise it is off. (for mid servo position the demand is set to 15, for example)
The leveller sensor produces an analogue voltage which must be read by the PICs A to D and turned into an appropriate pulse width. The next programming job ís to create a a look up table to convert the Analague input value to the required PW out value.(if the IP voltage is 0v-level servo deman value is 15 etc)
Programming in assembler is not as scary has it may seem, I downloaded a freebie called MPE Lab which is a dev environment for assembler PIC code. It includes a simulator which allows you to step thru your code on the PC, see what memory locations are up to etc. I was pleased to see that it handled my code, timer interrupt and all.
glidermann
May 19, 2006, 09:40 AM
2. Programming the chip to read the accelerometer output & do some calculations based on the outputs
Hi,
I don't think you can use only two accelerometers to stabilize roll and pitch axis. I mean, you know that when you start for exemple a turn, accelerometers will only show a discrete rise in the value because and the direction of the acceleration won't move at all, as if you were flying straight.
You have to use several gyroscope to determine your position in the space.
And I don't thing it will be much presice ,due to an offset which will introduce an error rising with the elapsed time.
In fact what you need is an inertial measurement unit.
I don't know if you understood me because of my poor english.
a+
jon-AMIG
May 20, 2006, 03:09 AM
I Have gotten my idea of usnig a single piece of 2axis accelerometer from here (http://www.parallax.com/sx/contest/contest_airplane_autopilot.asp).
I have thought that its possible to replace the thermopile sensor to an accelerometer because an accelerometer senses tilt too. So far, I have only tested the accelerometer output while its static. So I might have not seen the disadvantage of using an acceleromter while its in motion(ie. while its in flight). I think I'll just make the impossible, Possible! :D Haha..
Im using MPLab 7.31 version with C18 compiler. I have written programs in assembly for servo control, but I need to incorperate the accelerometer too which calculations like multipications are needed so writing in C language is more advantages.
flieslikeabeagle
May 20, 2006, 03:42 AM
If you're not stuck on using C, something like the PicBasic Pro compiler might be helpful. It lets you program Microchip's PIC's using the simple and yet powerful PBASIC programming language developed by Parallax Corp for their BASIC Stamp microcontrollers. The time savings compared to using assembly language is immense, though you may not earn the same "geek points".
For instance, centering a servo is done with a code fragment something like this:
SERVO PIN 6 'servo is connected to pin 6
DO WHILE 1=1
PULSOUT SERVO, 750 'send 1500 uS pulses to pin 6 to center the servo
PAUSE 20 'wait 20 mS between pulses
LOOP
I do indent code inside loops, but the software running this forum strips out whitespaces, removing the indentation.
By the way, Jon, have you tried the 'Pete yet? You do NOT need 1:1 thrust:weight to make it fly...
-Flieslikeabeagle
jon-AMIG
May 20, 2006, 03:07 PM
Hmm..We did have considered using Basic Stamp but was thinking that since it needs another chip on top of the PIC chip mean more weight & space. So we didnt want to use Basic.
flieslikeabeagl, I would like to ask about the servo control. Im under the impression that signals sent to the servo is in 20ms periods. So 1ms within the 20ms period would cause the servo arm to move to the extreme left. Am i Right? From your program, 20ms is not the period but a dead pulse length between rises. So this should the way?
I have posted the reply on my Pete here (http://www.rcgroups.com/forums/showthread.php?t=513316&page=4#post5502830). Thanks for your concern.
I welcome more comments & help here Please.
flieslikeabeagle
May 20, 2006, 05:39 PM
Jon - the Basic Stamp is much more expensive than a naked PIC. Its advantage is ease of programming.
The PicBasic Pro compiler is just that - a compiler. You type in PBASIC code, just as you would into a Stamp, and the compiler turns that source code into a hex file that you then download to a plain-jane (read: cheap) PIC, instead of to the expensive Stamp.
The compiler itself is not cheap, so a Stamp is better for a one-off project; but if you wish to work on multiple projects, the cost of the compiler will be lower than the cost of multiple BASIC Stamps.
The servos I've used (and I'm pretty sure this is the standard) require a +5 V pulse of length between 1mS and 2mS, followed by 20 mS of 0 volts. The code fragment above does exactly that - the "PULSOUT" command for the BS2 is a bit counter-intuitive in that the duration of the "high" state is *twice* the number specified. So "PULSOUT SERVO, 750" will send out 1500 micro seconds (or 1.5mS) of +5 volts. After that the "PAUSE 20" tells the Stamp to wait 20 mS before sending out the next pulse.
Still, if you think about how four lines of code are all that is necessary to position a servo, you can see how much programming time PBASIC can save you compared to assembly language.
-Flieslikeabeagle
vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.