Robotics/Design Basics/Basic Programming

< Robotics < Design Basics

Programmable devices

Microcontrollers

These days using programmable components is easy. In the early days you had to write code in assembly, burn it in an EPROM, plug the EPROM in its socket and hope you didn't make any mistake. Because if you did, you had to hunt down the error in hundreds of lines of cryptic assembly code and had to use a new EPROM. These days you've got flash memory which can be reprogrammed in circuit. You've got C and Basic compilers to write your code. Most µcontrollers have a whole lot of hardware on chip (UART, Watchdog, Real Time Clock, RAM, ROM, EEPROM,...) and libraries are available for different programming languages which make coding LC-displays or Servos very easy. Not to mention you've got emulators (A special connector plugged into the MICROcontroller socket which allows a PC to pretend to be the µcontroller) and simulators (simulates the µcontroller on a PC and allows to run its code) to hunt down the bugs.

AVR

A good µcontroller to start with is the Atmel AVR ATtiny2313 (previously: AT90S2313) or ATMEGA8535 (previously: AT90S8535) (Atmel). It's cheap, has all the essentials on chip and has a whole lot of websites dedicated to it. The 8535 is more expensive, but has more memory and has an on board ADC. An AVR combined with Bascom-AVR is pretty much the easiest way to start with µcontrollers.

See Atmel AVR for details.

See Robotics/Computer Control/The Interface/Microcontrollers for other popular microcontrollers.

See General Engineering Introduction/Arduino and Motors/Arduino Introduction for one way to do AVR development.

PC

The PC has many advantages over µcontrollers when it comes to controlling a robot. However it has 2 flaws that make it nearly impossible to use in small robot-projects:

This means that PCs are limited to tethered or large robots. If power isn't a problem the PC offers enormous amounts of RAM and HD space and plenty of CPU power. Plus a very handy user interface. Also network capabilities can be very useful for some applications. Providing your robot with a wireless connection (IR, radio, WiFi, bluetooth,...) and a similar interface on the PC reduces the wire-problem to a limited-distance (or in the case of IR a line-of-sight) problem.

If you intend to use a PC in your project, you might want to use one of the flavors of linux as the OS, as it allows easy access to any of the parts of the computer. Another choice for an OS is the older MS-DOS, although MS-DOS lacks multithreading (but those can be added in your software) and has ugly memory management (remember the 640Kb limit?).

Laptop

The laptop has only its size against it. A laptop provides the benefits of a PC without the enormous power consumption. The downside to laptops is their limited battery life.

PDA

The PDA (Personal Digital Assistant) is nothing more than a hand held PC (Personal Computer). Most of the time these units used scaled down RISC (Reduced Instruction Set Chip) processors to allow for fast execution times and also allow the unit to remain smaller and lighter than your average laptop. Some PDA's even have built-in GPS which makes it very interesting for outdoor robot applications. The downside is their price. The PDA is useful for play, but also serves as a great business tool especially when they are equipped with a stylus.

Gameboy

The Gameboy (the classic, advance, color and DS) can be a very powerful device. These have been used in many projects (see google). The only drawback is constructing the special PCB to act as a connector.

Gameboy Advance (GBA)

The Gameboy Advance is also excellent as a robotics platform. There are a few complete open-source development suites available (GCC based C/C++ plus ARM assember). There is also a good kit (Charmed Labs) available to interface Lego robotics motors/sensors and give much more control compared to the Lego RCX. With 4MB of FLASH and a few hundred K of RAM the kit has huge potential. The kit is not really for the complete beginner though as setting up the GNU tools can be quite complicated although the development environment is consequently very rich.

See GBA Development for tips on writing software for the Game Boy Advance.

Programmable Logic Controllers

Programmable logic controllers, PLCs, are special purpose industrial computers, made to be easy to interface with electrical circuits. Most PLC are expandable but there are some compact "all-in-one" solutions as well. They have excellent bit-manipulating possibilities, and add-on-cards for several special signals as high-speed counters, analog I/O, networks and fieldbuses (RS-232, RS422, RS-485, Ethernet, DeviceNet, Profibus...), pulse output, servo control, etc. Increasingly, special inputs are included in the PLC CPU unit. PLCs are traditionally used to control automated factories, possibly several machines per PLC. They normally use special-purpose programming languages, most commonly ladder or SFC.

PLCs are available in sizes from approximately 5x5x5 cm (there is a PLC IC available as well, but for the purposes of this book we choose to ignore that fact). The smallest ones are very limited though, with only a few I/Os and very limited memory, and also very limited instruction set with regards to data processing and calculations. PLCs are especially suitable if you have a lot of experience of electric systems, but feel intimidated by designing and soldering PCBs and programming computers (i.e., you are an electrician). They also shine in very large system with many special purpose sensors and outputs, as mostly there will be a standard solution from the manufacturer that is possible to use.

The downside with PLCs are their price - They can be quite costly, normally at least an order of magnitude higher than microcontrollers. They also draw more current than a microcontroller, however less than a computer. On the other hand, compared to a computer, they are computationally weak. They aren't suited for heavy signal-processing work.

PLC:s are best suited for large robots, but could be usable in medium-sized projects as well.

Combinations

It's common to use both a computer/laptop/PDA and (a) microcontroller(s) as those 2 complement each others limitations. e.g. The first has the advantage of large amounts of memory and processing power, however lacks specific outputs that are very handy in robotics, like PWM. Microcontrollers commonly have PWM channels that operate independently of the rest of the microcontroller, but are limited in their processing speed and memory.
Linking those 2 devices provides the best of both worlds.

Programming languages

This page discusses some of the available programming languages and provides links to download compilers for those languages.

Which language to pick?

The choice of language depends on a few points:

Writing your software

This section doesn't intend to teach the basics of programming, just those points that aren't addressed in most programming tutorials and beginners books.

Further reading

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.