View Full Version : Discussion Auto Pilot Coding
raven46
Nov 08, 2007, 11:52 AM
Hello folks,
Is it possible we try to bring some kind of light about Auto-Pilot Coding? :rolleyes:
We are so many out there with no experience, how about trowing some kind of hints on the table and get folks to speak about their own experiences.
Thanks!
:)
skatj
Nov 12, 2007, 02:24 PM
What's a basic algorithm for an autopilot?
phubner
Nov 16, 2007, 09:52 PM
Here is s simplified version. If you want more exact detail, you can download my code from www.hubner.net and check the autopilot link on the left. For this example lets assume that we use X and Y insead of Lat and Lon. It just makes the example numbers easier. other that that is almost the same.
Step 1. Know where you need to be. You weren't expecting that were you! Let's say we are trying to get home, so we need to know where home is. For us, lets define that place as X=0, Y=0, or the origin of the graph below. This information would normally come from a GPS.
Y
5
4
3
2
1
012345X
Step 2. Know where you are. Easy enough. We'll call is X=4 Y=4. This would come from a GPS too.
Y
5
4 +
3
2
1
012345X
Step 3. Subtract where you want to be from where you are coordinates from each other:
Xs: 0-4 = -4
Yx: 0-4 = -4
So our output vector is (-4,-4) is an arrow facing from where we are to where we want to be (or from the "+" to the "0".
Y
5
4...+
3../
2./
1/
012345X
heading back to the origin 0,0. But do we determine the angle? We use the Arctangent function called ATAN2(y,x). This is something you can play with in Microsoft Excel as well as other programming languages. As a note, this function uses Radiens, not angles, so you need to convert to degrees. Sorry , but there now way around it. in Excel use: "=Degrees(ATAN2(y,x)". This will give you -135 degrees, which is right! Rotate 3/8s of a turn counterclockwise.
Step 4 - Correct for our current heading. I bet you though we were done. Nope. Almost, but not quite. Step 3 looked like the end because we just assumed the plane was heading north or up, even though we didn't say so. The last step is to find out what direction the plane is actually heading and add this to our calculated bearing.
Y
5
4...->
3../
2./
1/
012345X
In this case if we are heading East (I changed the + to an arrow ->), then the turn is -135 degrees plus 90 degrees (our heading). Adding the absolute values puts us at 225 degrees counterclockwise from our current heading, or 5/8 of a circle CCW. Think abou tyou being the plane,. Face east, turn CCM halfway left, ans 1/8 more.
There are mote steps to choose to turn right instead (because its a smaller turn) but thats just a refinement. The basic principles still stand.
---
I made a number of big simplifications here so real experts, please don;t jump on me!! :-). My goal was not to write a program but explain the concepts. Luckily I actually did write some programs if you are interested in checking the listed URL for the working code (language SPIN for an embedded processor).
I hope this helps a little without being too overwhelming! It took me quite a while to figure this stuff our, so I understand how frustrating it can be. Keep plugging away!
Paul
raven46
Nov 20, 2007, 11:36 AM
Hi guys, the last time I checked in here, nothing was going on.
Sorry, my mistake. I guest we already have some taughts (thanks Paul).
I have been very busy, trying to collect different type of information about Auto-Pilot coding.
Later today i will put some more caveats to this topic. :)
raven46
Nov 22, 2007, 10:10 PM
Case study:
(Trying to develop a Auto-Pilot System for R/C Airplanes.
First of all, I am writing this because I discovered that Forums (what ever they are intended to be) are pretty good to learn or to improve one’s knowledge. I would like to thank all those who really want to share and help others in getting started (… that CLICK that is missing to put everything together in our brain).
I am a rookie in this Topic, I just started this August and I decided that it can’t be too difficult (or maybe I am wrong) to put everything together to build a simple Auto-Pilot System for R/C airplanes.
I would like to talk a little bit about my knowledge and experiences, for all those out there to understand what are the basics from my experiences and from my point of view.
I finished High School. I learned something’s about electricity, (Current, Voltage and Resistance) nothing else.
Since I didn’t have the chance to learn electronics I read quite a lot in books, magazines and of course surfing the Internet.
• Acelerometer (we will use only 2 axis – roll and pitch);
• GPS ( Navigation instructions to go from A to B, which means we need current position of “A point” and position of “B point”, a Bearing and finally an Altitude.
Speaking about R/C airplanes: It’s something I only know by eyes, which means I never had one, I don’t have any and I never played with one.
So, now that we all know what I really know (which is zero….I’am just kidding-No I’am not… its Zero with a big ZZZZZZ). If there still someone out there, well …lets start.
This Auto-Pilot System is going to be very simple, but if we can build it, then nothing can stop us from going further on.
OBJECTIVE:
• Get a r/c plane to go from point “A” to “B”;
• Position of point “A” is lower than point “B”;
• To go from “A” to “B” we will have to bank (roll) right for a specific bearing. (If we succeed it means that doing the opposite – bank (roll) left for a specific bearing is also easy);
• We will suppose that there is a slight wind that is drifting our plane, which means we have to be able to do some corrections to make it go to point “B”.
What do we need to achieve this objective:
• An r/c airplane with 3 servos (1 for roll – ailerons, 1 for pitch – elevators and 1 for yaw – rudder). If you don’t have an r/c airplane it doesn’t matter because what we really need is something that looks like an airplane with the 3 control surfaces;
• No need for a r/c Transmitter and Receiver;
• A microcontroller (8 bits);
• Some basic knowledge of a programming language (like BASIC);
• (If something else turn out, don’t worry, I will try to explain it)
JUST 2 OTHER ISSUES!!!
1st. I will try to update and reply to any question on a daily basis.
2nd. For all those Gurus out there, on Auto-Pilot Systems & Coding, you are welcome to correct me on any issue you think I am wrong
raven46
Nov 22, 2007, 10:18 PM
i dont know how to put a picture here?
help needed, thanks
vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.