Simplified Robot Tutorial
Last Modified: 2006-11-20
find:

basket

Acroname Robotics PDF webpage version Simplified Robot Tutorial PDF

Related
Products

Product image for Brainstem GP 1.0 Module
Brainstem GP 1.0 Module
Product image for 4X AA Battery Pack w/Connector
4X AA Battery Pack w/Connector
Product image for High Speed BB Micro Servo
High Speed BB Micro Servo
Product image for Yellow Wheel with O-ring
Yellow Wheel with O-ring

Contents

Introduction

This tutorial walks through the building and initial coding of a very minimal robot.  While the BrainStem has IO features designed to function with complex multiprocessor systems, it can also act as a very capable main controller for a simple robot.  This tutorial walks through the building and programming of such a simple robot.  This tutorial also provides some simple examples of reflexes, TEA programming, and development structure. 

The Design

The basic idea is to use off the shelf parts as much as possible and also avoid as much soldering or custom wiring as possible.  As a rough goal, we will try to get the robot to do the following:

  • Respond to simple commands that tell it to go left, right, forward, and back. 

To accomplish this goal, we will need the following items:

  • A power supply. 
  • A BrainStem controller. 
  • Two drive motors arranged in a differential drive configuration. 
  • Wheels. 

For the drive motors, a couple of small servos modified for continuous rotation will do nicely.  We modified some Futaba mini servos for our robot, but a pair of Parallax Modified Servos would also work well.  Some wheels with O-rings fit directly onto the splines of the servo output shaft.  For power, we will keep things simple with a basic 4-cell AA Battery Pack and we will just use the plug as a switch. 

On our robot, we added a Sharp GP2D02 detector articulated by a Pico Servo.  This will give the robot the ability to look right, left, and center to judge distances.  Implementing behaviors with this sensor is discussed in other examples.  For this tutorial, it's just for show. 

Parts necessary spread out on a table.
The basic mechanical parts spread out for design.

The first design issue is how to arrange all these pieces into a compact and useful arrangement.  The batteries are the heaviest and so they will need to be low.  Probably the second concern is to get the Sharp GP2D02 as far to the back of the robot as possible to avoid the minimal range issue with the detector. 

Note

The Sharp GP2D02 detector has a minimum distance of roughly 3-4".  Closer objects report misleading distances so it is best to avoid having the robot see this "close". 

Fabrication

This robot doesn't promise to be pretty, just easy build.  All the construction was accomplished with double-sided sticky foam tape.  This stuff is sticky, the foam is forgiving, and it is very fast.  The design was to stack the two servos on top of the battery pack, the third servo that will articulate the Sharp GP2D02 was wedged between the two mini servos.  Then the BrainStem was stuck on top of the pile of servos.  Although the weight is low, the robot needs to be kept from tipping so a little aluminum tail skid was added in the back of the robot.  The wheels just push on to the servo hubs and secure with the standard servo horn screw.  A small piece of cardboard stock was used to extend the pico servo's horn to allow the GP2D02 to be positioned back slightly from the front of the robot.  This helps decrease the minimum distance the sensor can reliably read as well as protecting the sensor between the two wheels should the robot tip over. 

Source Code - TEA Robot Primitives Library

To keep the programs for each task easily readable, we can write a small library of common moves or "primitives" for the robot.  To start off with, we can just have the following primitives:

  • Turn left
  • Turn right
  • Move forward
  • Stop

Below are the routines that do this.  Notice that this library includes two system files "aCore.tea" and "aServo.tea".  These are also libraries but they are provided by the system.  If you want to take a look at them, they can be found in the aSystem directory in your BrainStem software distribution. 

/* file: minbot.tea */ #include <aCore.tea> #include <aServo.tea> #define OFF (unsigned char)128 #define FWD (unsigned char)176 #define BCK (unsigned char)70 #define TICK 1000 #define DELAY 400 /* * * * * * * * * * * * * * * * * * * * */ void stop() { aServo_SetAbsolute(0, OFF); aServo_SetAbsolute(1, OFF); aCore_Sleep(DELAY); } /* * * * * * * * * * * * * * * * * * * * */ void forward(int ticks) { aServo_SetAbsolute(0, FWD); aServo_SetAbsolute(1, FWD); aCore_Sleep(ticks * TICK); stop(); } /* * * * * * * * * * * * * * * * * * * * */ void left(int ticks) { aServo_SetAbsolute(0, BCK); aServo_SetAbsolute(1, FWD); aCore_Sleep(ticks * TICK); stop(); } /* * * * * * * * * * * * * * * * * * * * */ void right(int ticks) { aServo_SetAbsolute(0, FWD); aServo_SetAbsolute(1, BCK); aCore_Sleep(ticks * TICK); stop(); }

Source Code - Reflex that Uses a Switch to Trigger a TEA Program

The first task is to manage some simple, scripted movements with the robot.  These movements can just be sequences of the library primitives we have already created.  Since the method of coding is to compile the program on your host using the console application and then download and run them on the BrainStem, we will be needing to plug in the robot's serial link to code the robot and launch the application and then the robot will run off while tethered with the serial link.  To avoid this, we can use a reflex and a simple push button to initiate the program when the button is pressed.  Here is a simple reflex file that does this with a push button switch plugged into digital I/O port 0 on the BrainStem module. 

/* file: task1.leaf */ #include <aCmd.tea> #include <aGPReflexes.tea> #define MODULE 2 // message ID's #define CONFIG_DIG_0 0 #define LAUNCH_VM_0 1 #define RESET_DIG_0 2 module[MODULE] { /************* REFLEX COMMANDS *************/ // configure the digital I/O pin to trip a reflex // on transition to high message[CONFIG_DIG_0] { MODULE, cmdDIG_CFG, 0, 7 } // launch the TEA program in slot 0 message[LAUNCH_VM_0] { MODULE, cmdVM_RUN, 3, 0 } // reset digital 1 transition watching message[RESET_DIG_0] { MODULE, cmdDIG_RST, 0 } /************* REFLEX VECTORS *************/ // when digital 0 triggers, trip the launch message vector[aGP_RFX_DTRANS_0] { LAUNCH_VM_0, RESET_DIG_0 } // on boot up, configure the digital pin to trip reflex vector[aGP_RFX_BOOT] { CONFIG_DIG_0 } }

This leaf file is just saved in the aUser directory and then compiled using the leaf compiler.  LEAF stands for "Little Embedded Application Fragment" and the compiler puts this reflex definitions into a configuration file with a .bag extension.  This file can then be downloaded into the BrainStem using the batch command in the console. 

Here is the sequence used to compile and then download the resulting "task1.bag" file.  If you like, you can take a look at the "task1.bag" file.  It is a series of formated packets that set all the reflex configurations specified in the leaf file.  This sequence needs to be typed with the robot's BrainStem powered up and an active link must be present. 

Tip

To verify whether the link is active, you can always check the heartbeat status both on the board with the green LED or the heartbeat status indicator in the console.  application.  When they are blinking, the link is up and active. 

Console input and output for compiling and loading a reflex program.
Note

Notice the color coding in the output window of the console.  In this case, commands typed on the command line are blue, packets sent to the BrainStem module are red, and output from the console is black.  Also, notice that the batch command just opens up the "task1.bag" file and enters the contents of the file onto the command line as though it was typed by the user. 

Source Code - TEA Main Program

Now we have a library of primitives and a simple mechanism to run the program in slot 0 of the BrainStem's program slots.  Now lets write a simple program to run some primitives.  This program can also be saved into the aUser directory in the BrainStem distribution on the host.  Here is a simple example:

/* file: task1.tea */ #include <aCore.tea> #include "minbot.tea" void main() { // stall aCore_Sleep(10000); // wiggle left and right left(5); right(10); left(5); // move forward forward(12); // wiggle right and left right(5); left(10); right(5); }

To compile and load this program, once it is saved to the aUser directory follow these steps:

steep "task1" load "task1" 2 0

Executing the Program

Here we assume the BrainStem module's IIC address is 2 (the default for the GP 1.0) and we load the program into slot 0.  The first command, steep takes the task1.tea file and compiles it into a "task1.cup" file.  The resulting object file (.cup file) is stored in the aObject directory in the BrainStem distribution.  The second, load command takes this .cup file and loads it down onto the BrainStem module into slot 0.  Again, the BrainStem must be powered up and the link active for this to work properly. 

To test the program use the launch command telling the BrainStem module (IIC address 2) to run the program in slot 0:

launch 2 0
Tip

A simple but useful approach here is to set the robot on a small box or other object so the wheels can spin freely while tethered.  Once this seems to be working, you can graduate to spinning around on the floor untethered. 

Now it's time to configure the robot for stand-alone operation.  We need to enable the boot-up reflex that activates the button response.  If you like a blinking heartbeat light, you can configure the Stem to blink when it is not linked to a computer.  Enter the following commands:

2 18 6 1 2 18 5 1 2 19

The first two commands are cmdVAL_SET commands which enable the boot-up reflex and set the Stem to internal heartbeat mode.  The third command is a cmdVAL_SAV command that writes the new settings to the Stem's EEPROM. 

The final test is to try pressing the button to have the reflex initiate the running of the program.  If this works, the task is complete. 

Going Further

This tutorial just showed how to get a robot to twitch.  Next, we recommend taking a look at some examples that add a sensor to a base with two modified servos.  Some relevant examples are a robot with a Sharp GP2D02 scanner and a robot that does line-following with a photoresistor and bright red LED. 

Revision History:

  • 2002-08-01: Page Created

BrainStem
Resources

 
 
voice: 720-564-0373, email: sales@acroname.com, address: 4822 Sterling Dr., Boulder CO, 80301-2350, privacy
© Copyright 1994-2008 Acroname, Inc., Boulder, Colorado. All rights reserved.