Software and Computers:

Robots and computers go hand in hand(or hand in mouse,as the case may be). And where there is a computer, there is programming.

Kits such as the ones you will work with in this book keep programming on your part to a minimum. If you want to add functionality to your robot, however,you'll have to know something about programming. The more you know, the more you can make your robot do.

If you can not imagine yourself doing even a bit of programming, use a preprogrammed robot that quires no programming. And certain robotics kits,such as Lego MindStorms, have their own easy-to-learn software languages.
I give you the programming details you need to get the code(which I provide for you) into your robot and to understand the gist of what that code will make your robot do.
What follows are a few concepts that you should know about how I approach programming a robot.

Keep It Modular:

Programs are made up of code - lines of text that tell your robot what to do. One good programming discipline is to make your code modular. Modular programming means creating reusable and easily modifiable blocks of code that may be added or removed. Tasks in modular programming are broken up into these logical function blocks of code.
The opposite of modular code is spagehetti code. Spaghetti code is so integrated and hard to follow that it can not be modified or removed easily.(It's called spaghetti code because if you were to draw lines to follow the logic of the code, you'd end up with a page that looked like a plate of spaghetti.)
Modular code usually has a method for sending and receiving data, but the details of its internal operation are hidden from view. If you write modular code, you save yourself a lot of time both when writing and debugging (locate and correct problems with) your robot's program.
I generally divide programs into two categories:high level and low level.The low-level software module handles and regulates hardware access,such as turning on motors or reading sensors. The high-level software controls the task at hand, such as navigating down a hallway.

Programming:The low road

Low-level programming involves developing the software that controls robot hardware directly through what is called a device driver. You've probably encountered device drivers before because they also control hardware peripherals such as printers and modems on your desktop computer.
In addition to controlling hardware, low-level  software might also be written to provide operating system like functions, such as grouping and controlling device drivers, or software application functions such as error checking. Low-level programming usually involves  simple commands such as turning a motor on or off. Low-level programs access the hardware directly but often hide the details of the hardware from higher level programs. This modularity makes life simpler if you have to hunt down a problem with the software.

Technical Stuff:
Rarely do low-level programs access high level functions,except to interrupt the high level software in case of an emergency that might require the robot to shut down.
Programming:The high road
High-level programming usually involves developing the software application that will ultimately control your robot. High-level programs usually perform the decision making processes of the robot.

High-level software should never access hardware directly, thought  it may direct low level software to do things. For example, if you are making a fire fighting robot, your high-level program will search for fire and snuff it out, utilizing the device drivers to control or take readings from heat sensors.
In this book, you'll encounter a few simple algorithms that high-level software might typically run. You will also explore a few techniques used by high level programs to decide  what to do and to issue commands to the operating system and device driver software.

Programming quick start:

Many types of programming languages are used for computers. Some of the most popular are C,basic,cobol and assembly language. Of the many variations of these languages floating around,each has its own strengths and weaknesses. The language used in the BS2 is PBasic,which is based on the popular Basic language that many of the first personal computers used. PBasic instructions are easy to understand and provide all the power needed for a small processor,like the BS2(Basic Stamp 2).
In a nutshell, a program is just a series of instructions that tells the computer in this case, the BS2 controller - what to do.The program resides in nonvolatile memory in the BS2. The BS2 executes the commands in the program one at a time,in sequence. For the most part,you can simply take chunks of code in this book and enter them into the Basic Stamp editor.
When you download a program from your computer to the BS2 controller, the Basic Stamp editor converts the program text into small instruction packets, called tokens. The BS2 stores these tokens and interprets them while the program is running. A single token might result in many smaller instructions being executed.

Programming resources:
Complete information about programming in PBasic is available from the Parallax Web site at Check out the multimedia tutorial, the Basic stamp editor user's guide  with programming references, and several application notes. These are all free for the taking. Note,however,that the programming documentation is long(several hundred pages) so you are better off buying a book if you are serious about programming.

Any program that you download to the BS2 controller gives you complete control over all of your robot's features. For example, you can read the status of the whisker sensors,turn the steering left or right,turn LEDs on or off, make sounds with the speaker,read the status of the switches and jumpers, almost anything that your little heart desires with your robot,providing that enough memory exists to hold the program.
Programs consist of things such as comments,program code and variable declarations. The arrangement of these pieces and the format that you use can make life a lot easier when you need to debug the program or when others have to work with your program.


The first few lines of a program should contain information about the programmer and the program. Make sure that each program you write begins with this information:
  • Program name
  • Program function
  • Programmer's name
  • date
  • Information  on how to use the program
Here are some samples:


Leave a Reply

Subscribe to Posts | Subscribe to Comments

Welcome to My Blog

About Robotics

About Robotics
About Robotics Notes


  • Mobile Robots:Inspiration to Implementation by Joseph L.Jones,Anita M.Flynn,Bruce A.Seiger(published by A.K.Peters Ltd.) Build your Own Robot! By Karl Lunt(published by A.K.Peters Ltd.) Robot Builder’s Bonanza by Gordon McComb(published by McGraw-Hill/TAB Electronics) Getting Started in Electronics by Forrest Mims III(Published by Radio Shack Corp.)

Follow by Email

Google+ Followers

Robot technology

Robot technology

Robot Technology


Popular Post

Blogger templates

-Robotic Notes- - Designed by Poonam Khatti-