This post describes the beta version of BASIC Stamp autopilot code. As mentioned in my last post, the two main challenges in this project were dealing with the constraints of integer-only math and a severely restricted variable space (just 26 bytes!).

The first one I got around by treating fractional degrees as full degrees (since the UAV is never going to travel more than one full degree away from launch) and essentially treating them as integers. This was a little tricky, since I'm limited to word-length variables (with a max value of 65,535, which is essentially 4 and half digits of precision) and the GPS natively generates six and half digits of precision (360.9999 W/E). But I truncated the full degrees to just 1 and -1 from the current position, and that let me retain the full precision of the fractional degrees.

The second problem I got around by splitting the program up into five sub-programs (each one is allowed to reuse the variable space in RAM) and switching in real-time between them. I also used the Stamp chip's 121 bytes of "scratchpad" memory to store a lookup table of all the waypoints, and that's available to all the programs, although you can't manipulate the scratchpad memory directly without copying it into a variable.

The current program does three things:

  1. It intercepts R/C receiver commands to the rudder, elevator and gear switch and translates them into computer commands, which drive the servos through a Parallax servo board or FT639 chip. When it detects that the gear switch has been thrown, it transfers control of the rudder and elevator to the autopilot program, and back again when the switch is returned to its manual position.
  2. When under autopilot control, it reads GPS coordinates and headings and translates them into directional vectors to the next GPS waypoint. It uses those vectors to steer the rudder.
  3. It also uses GPS altitude readings to do a crude sort of altitude hold. Because the GSP altitude data is so noisy, the autopilot averages over three readings and treats that as accurate +- 10 meters. It uses that data to adjust the elevator to try to keep the plane within a range of +- 10 meters of the original altitude at which it was put into autopilot mode.

The code has been tested on several different kinds of servo driver chips and GPS modules, as well as with GPS simulators, but not yet in the air. So consider it just instructional at this point. I'm sure there are some bugs, and a lot of settings that need to be tweaked. Also, we have not yet added camera controls and other more sophisticated in-air options, such as circle and hold (although these aren't hard to add, not that we've got the basic hardware interfaces working).

You can download the code at the following link. Load the first program (uav.bsp) and it will call the others at compile and download time.

The recommended hardware is a Basic Stamp BS2p on a dev board using the FT639 servo driver chip and a standard GPS module such as the EM406. Details on these hardware configurations can be found in the main post on this UAV. Other servo drivers, such as the Parallax board can be used, and the details on how to modify the code for them is in the comments of the code

-------------------------------------------------------
[Older code, no longer supported but may be useful for instructional purposes]
  • Code for the Parallax servo board and Parallax GPS module is here.
  • Similar code for the FT639 servo controller chip and Parallax GPS module is here.

Views: 1721

Comment by rad man on November 21, 2007 at 9:53pm
stupid question.............so how will all of these be in the stamp if they cant fit? or can they?

3D Robotics
Comment by Chris Anderson on November 22, 2007 at 8:07am
Rad,

The way BASIC Stamps work is that you can have multiple programs in storage memory and switch between them, to make effecient use of the very limited "working" RAM.

You might want to teach yourself basic programming on these chips before you embark on this project. My code will require a good deal of tweaking to work on your platform, and if you're not pretty comfortable with programming you'l find it confusing.
Comment by rad man on November 22, 2007 at 6:14pm
well i actually own a basic stamp and have a book on it but i don't recall the book saying anything about what you said it just gave experiments and a short description on what a micro controller is. So i have pretty basic knowledge on programming (it should give me something to keep busy anyway) i thank you very much for your help and PATIENTS!! thanks!

100KM
Comment by wayne garris on December 2, 2007 at 11:21pm
the bs2 version can only hold one program but other versions like the bs2p can hold up to 8

Developer
Comment by Jordi Muñoz on December 3, 2007 at 4:58pm
Hello, im making an autopilot too, but im using a better solution: http://www.Arduino.cc, anf if you wish you can use arduino mini version. Is super easy to program (C++), a lot of examples, like, GPS reading, servocontrolling (up +12), PMM signal genration, etc. Right now im able to read GPS from flight simulator 2004 (simulated), and generate a PPM signal to control a joystick, to test porpuses... Letter if you one i can send you the code, and diagrams.. :)

Developer
Comment by Jordi Muñoz on December 3, 2007 at 5:03pm
http://www.youtube.com/watch?v=PeScmRwzQho

http://www.youtube.com/watch?v=MD_-YnFZFP8

Developer
Comment by Jordi Muñoz on December 3, 2007 at 5:12pm
this is what i making:

http://youtube.com/watch?v=7xkJseQyhJA

But im using a shipper arduino called boarduino, and i program it with arduino diecimila:
http://www.adafruit.com/index.php?main_page=product_info&cPath=19&products_id=72
Comment by Dan on January 24, 2008 at 12:18pm
I reckon I could just copy the code across to an oopic board - what do you think ?

3D Robotics
Comment by Chris Anderson on January 24, 2008 at 1:14pm
Dan,

I've never used on oopic board, so I don't know. If you do it and it works, could you get back to use with tricks and tips?

Developer
Comment by Jordi Muñoz on January 25, 2008 at 9:30am
Hello Dan,
I was checking the C code of oopic, and is very similar, but you need to adapt it. I think you gonna have no problems, try to understand the arduino language and then translate it to oopic, the only difference i saw was in the declaration, but the main code seems to be similar. Good Luck

Comment

You need to be a member of DIY Drones to add comments!

Join DIY Drones

© 2018   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service