3D Robotics

BASIC Stamp UAV code now in beta

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.
E-mail me when people leave their comments –

You need to be a member of diydrones to add comments!

Join diydrones

Comments

  • 3D Robotics
    No, it uses some commands that are only available on the BS2p. Note that Basic Stamp is a TERRIBLE platform for an autopilot, mostly due to the lack of floating point, and I abandoned the project after this proof of concept. So don't expect it to fly a plane or anything ;-)
  • does this same code work for the BS2 as well?
  • Moderator
    Oh Man! Too bad they dont have an updated kit, or do they? Do you mind checking this link. I think this would work and still provide a buch of things to get used to working with it...

    .http://parallax.com/Store/Microcontrollers/BASICStampProgrammingKit...
  • 3D Robotics
    Even worse, I think that kit is based on a Basic Stamp 1, which is unuseable for our purposes. Better to get a USB dev board and a BS2p module. They cost a bit more, but they're actually useful.
  • Moderator
    Radio Shack has a kit called "What's a Microcontroller BASIC Stamp Kit" it is a serial version and comes with a book and some other good beginner stuff. It costs $79.

    I just have a dumb newb question...

    Is a serial version going to be a big deal try to use? Reading this string of comments I understand that thie basic stamp is kind of a training exercise and to me the cost of the Radio shack kit is worth it but if I'll end up needing to spend another 70 bucks to get a usb based board it's better to just buy it all piece by piece.
  • I know you say your moving away from the basic stamp to something more powerful, but if anyone is interested in continuing the project with a basic stamp i have alot of ideas. I have already made a gps navigation system for an rc car and i am using alot of that code for an autopilot for a super stick.
  • I wrote a little code to compensate for the waypoint every mile issue. It just compares each digit of your current lat and long vs waypoint lat and long from most sig to least sig, and if they are = then it shifts the digits one position to the left and the last spot is filled with the small part of the lat and long. then loops until the digits are not =

    I also notice that when you are normalizing the values for the atn function it isnt very accurrate when the waypoint is close. I had the same problem with a ugv i built(basic stamp on a RC Acura). To fix i just divided the larger by 129, added one, then divided both number by that result.
    ex....for A atn B
    if a>b
    c = (a/129) + 1
    else
    c =(b/129)+1

    a= a/c
    b= b/c
    bearing = a atn b

    also here you can also add a distance formula. distance = (a hyp b) * c
  • 3D Robotics
    Jerod. Good point. A Basic Stamp word can handle up to 65,535, which in practice mean that the furthest we can go is +-10,000 from the next waypoint. As you rightly note, most GPS modules today output DDMM.MMMM (for lat) or DDDMM.MMMM (for lon), so in practice yes, M.MMMM is just +- one minute (and its fractional component), which is just a mile.

    Yet another reason why we describe the Basic Stamp auotpilot as a teaching tool for experimenting within line of sight. If you want to go further and otherwise upgrade to a "real" autopilot, stay tuned for ArduPilot, which will have none of those restrictions.
  • When you say you will never be more than one degree away from the next waypoint, do you mean one minute? I was looking at the gps sentance and the first variable looks like it is DDMM and the second variable is .MMMM. one minute is pretty close to one mile so do your waypoints have to be less than a mile apart?
  • Do you have the libraries that you used for the C code?
This reply was deleted.