Build Robots Robotics Theory

How to Build a Simple Differential Wheeled Mobile Robot System

If you’re passionate about Robotics and have always wanted to build your own mobile robot, this might be a good starting point. From physically building the robot platform, to setting up, programming and hardware or software fine tuning, while not necessarily difficult everything needs to be taken into account. In this article you can find out how to make a simple robot with two independently motorized wheels and basic sensors to avoid obstacles or follow certain targets, as well as learn about general rules that need to be followed when putting together such a project, regardless of the platform employed or the technical build solution.

Building blocks of a mobile robot

A mobile robot can be regarded essentially as an ensemble of five main parts and subsystems, as discussed below.

Simple wheeled mobile robot platform
A wheeled mobile robot platform

The Platform

This would be the main part of a robot’s body, its chassis, designed to carry all of the other components, transmission mechanisms, electronics and so on. It needs to be sufficiently large and provide adequate fixtures to accommodate all necessary parts as well as sturdy enough to cope with the weight of the parts as well as with additional loads which can appear in dynamic conditions such as vibrations, shocks or chassis torsion (e.g. when traveling over rough terrain), actuators torque, supplementary weight to be picked up and so on.

The platform can be manufactured from a variety of materials ranging from different types of plastic to high-rigidity and lightweight alloys or advanced composite materials. The common choice of material is aluminum which is sufficiently lightweight while providing reasonable sturdiness and ease of workmanship at reasonable cost. For larger platforms or even rough environment use, aluminum alloys are usually employed, e.g. “Dural” which is an Al-Cu-Mg alloy providing higher grade sturdiness while maintaining its lightweight and cost-effective characteristics.

The Actuator system

All of the robot’s moving parts must be actuated by means of converting energy from various sources (electricity, oil or air pressure) into motion. This goal is accomplished by using motors coupled to transmission means or mechanisms which provide rotational or translational movement.

In our case, a mobile robot’s actuator system is in most cases the propelling system which consists of motors and transmission mechanisms designed to actuate the wheels.

There are many types of motors and transmissions, however the most common choice would be an electric servomotor, which is essentially a compact package containing an electric motor coupled to a transmission mechanism and a transducer, which provides position and speed feedback, thus allowing for precise control and direct engagement of a wheel or another type of part requiring actuation.

The Control System

Here we must have a microcontroller to perform data processing and a memory module in which the programming for the robot resides. An electronic components array — a mainboard — designed to adapt signals coming to and from the microcontroller is also needed. Input signals are usually generated by the robot’s various sensors while the commands generated by the microcontroller represent the output signals which control the actuators and other hardware.

In small and compact robots that have low power requirements, like the one we want to build, the electrical power source is connected only to the mainboard which in turn provides power to the microcontroller, sensors, actuators and other hardware.

The Sensor Array

An autonomous or quasi-autonomous mobile robot must have means of acquiring information about the environment in which it activates, to alter it’s behaviour in a proper manner otherwise, if it meets an obstacle for instance, it would not perform efficiently, trying to pass it over rather than going around it, or even fail to accomplish certain tasks at all, not being able to reach its destination because of a trajectory deviation caused by passing over an irregularity in the rolling surface.

There are various types of sensors, ranging from simple contact-type, or tactile sensors to more complex laser sensors or video camera systems with advanced image processing means.

The Effector System

There is a large variety of equipment that can be mounted on a mobile robot platform depending on the designation of the robot, like simple gripper mechanisms, robotic arms or video equipment for monitoring in harsh environments where human intervention would be difficult or even impossible and so on.

Our robot is equipped with a simple gripper actuated by a servomotor that can grab and transport objects over small distances.

Building The Robot

Lego Mindstorms NXT kit
Lego Mindstorms NXT kit

Numerous manufacturers offer nowadays robot building kits, some of these being extremely versatile and reliable being suited for both simple as well as advanced projects and application. Such an example is Lego’s Mindstorms NXT platform, now at its second generation, which provides both, a powerful control module, sensors, actuators, building parts as well as a powerful visual programming tool which is both easy to use and versatile. Better yet, there is a large online community for this platform packed with resources to help you create with it. Mindstorms NXT is also supported by MRDS.

BOE-Bot
Boe-Bot robot from Parallax

Another example would be Parallax which offers several types of development platforms, with an array of microcontrollers ranging from simple, 2000 lines of code per second processing power, models to more advanced multi-core models with up to 160 MIPS processing power. Depending on the platform, they can be programmed using languages developed by Parallax or even using a Sun Microsystems Java language subset.

Pololu 3pi Robot kit
Pololu 3pi Robot kit

Yet another very cost-effective mobile robot building kit is the 3pi robot kit from Pololu, featuring an ATmega168 microcontroller running at 20 MHz and can be programmed using C/C++ language. Energized by its two electrical micromotors it is capable of speeds up to 1 m/s or 3,3 km/h. It is equipped with a 8×2 character monochrome LCD display, buttons and reflectance sensors. Software-wise tools such as Atmel’s AVR Studio or the very well-known GNU C/C++ compiler provide a very comfortable development environment. Vast online resources are available and the kit is also compatible with the Arduino development platform.

You can also read our more extensive review of mobile robot building kits.

Our robot

The robot is based on the Boe-Bot kit from Parallax and has a Basic Stamp family microcontroller. This kit contains all the necessary building parts as well as the software required for setting up an programming the differential wheeled mobile robot.

Boe-Bot Robot
Boe-Bot Robot

Supplementary we have equipped the robot with a Parallax gripper kit, multiple IR sensors set up in a fashion we will discuss later on, switches for easily changing programming scripts loaded to the robot’s memory without connecting it to a computer and a single digit LED display.

Boe-Bot robot with gripper
Boe-Bot robot with gripper

Description

The robot has two independently actuated wheels and one support wheel, all the wheels being non-directional. The motorized wheels are mounted directly on the output shafts of the two continuous rotation servomotor actuators which are mounted to the chassis. The support wheel is mounted directly to the chassis. All the wheels are made of plastic, the motorized wheels being equipped with rubber bands which act as tires to avoid slippage on certain surfaces.

Boe-Bot robot with gripper
Robot measurements – side
Boe-Bot robot with gripper
Robot measurements – top

Continuous rotation type servomotors are, as the name says, in continuous movement, requiring only speed setting commands as opposed to standard servomotors which act more like stepper motors, moving and holding a position until another command is received.

Such a standard servomotor is employed for actuating the gripper, after reaching the position set in the command, the servomotor needs to stop and not rotate continuously against the physical limitations of the mechanism.

The gripper is made from lightweight aluminium with rigid plastic joints. The two main aluminium plates are kept parallel by the gripper mechanism and can be spread or joined when grabbing or releasing objects. Rubber bands are also attached to the plates in order to increase grip on the grabbed objects.

The chassis is also made of lightweight aluminium parts and is designed to accommodate all the necessary equipment.

The BS2 16 bit microcontroller employed by the robot uses the 24-pin DIP chip form factor, components found on the microcontroller board are:

  • PIC16C57C-20 PBASIC interpreter with up to 4000 instructions per second processing power;
  • 2 kB EEPROM memory unit for long-term program storage;
  • 32 byte RAM memory for variable storage during runtime;
  • 20 MHz clock frequency generator;
  • 5 VDC LM293 voltage regulator and a filtering capacitor;
  • I/O interfaces.
Basic Stamp 2 microcontroller and the mainboard
Basic Stamp 2 microcontroller and the mainboard

The mainboard of the system provides various expanding possibilities and safety features. It also has a voltage regulator and can be powered up by up to 12V DC power sources. It is equipped with a jack to which the 4 AA battery power pack can be connected and it is also equipped with terminals for connecting a 9V PP3 battery.

Four servomotor ports are provided as well as numerous I/O terminals and a breadboard for easy development of additional electronic circuits for various I/O devices (e. g. sensors).

With the help of a 3-position switch mounted on the board the system can be shut down or powered up either fully or without the servomotor ports. An indicator LED is mounted on the board to indicate that it is powered up and there is also a button for resetting the robot, for instance if the system hangs or the program script is improperly written and causes the robot to enter a loop.

Assembly

Putting together the robot is pretty straight-forward requiring basic tools such as a Philips screwdriver for the assembly screws and a slotted screwdriver for calibrating the servomotors. All the parts are mounted to the chassis with screws and bolts.

The pins of the electronic components and additional wires that make up auxiliary sensor circuits are simply inserted into the breadboard’s holes and then connected to I/O and power pins, bearing in mind the electrical connections layout of the breadboard. More details about breadboarding, electronic circuitry and other information can be found on Parallax’s educational site or in the manual.

Programming The Robot

All the required interactions, when connecting the robot to the computer, like scripting, program upload and debug can be done with the aid of the Basic Stamp Editor computer application, included in the package. Scripts can also be saved on the computer and detailed documentation is also available.

Programming environment
Programming environment
Debug console
Debug console

Scripting

Scripting is done in the PBASIC 2.5 language which is developed exclusively for the Basic Stamp family microcontrollers. It includes well known instructions like GOTO, FOR…NEXT or IF…THEN as well as specialized instructions like SERIN, BUTTON, COUNT or DTMFOUT.

There are four integral data types available, with sizes listed below:
Bit – 1 bit, values 0 or 1
Nib (nibble) – 4 bit, values in the range 0 to 15
Byte – 8 bit, values in the range 0 to 255
Word – 16 bit, values in the range 0 to 65535 or -32768 to 32767.

Detailed PBASIC language documentation is provided with the kit and is also available online, together with continuous rotation servomotors calibration and sensor setup, steps necessary to be performed before any other work is done.

Navigating using IR sensors

This task is described by the flowchart below. IR LED pulse frequencies are generated and afterwards the status of the two IR sensors is read. If no obstacle is detected their status will be 1, conversely when something is detected the status will become 0.

Flowchart for IR navigation algorithm
Flowchart for IR navigation algorithm

In the following script the task is implemented. The status of the two top-mounted IR sensors is checked before sending commands to the servomotors. If an object is present in the robot’s path, it will go around it only as necessary, otherwise continuing its straight-forward motion.

' {$STAMP BS2}
' {$PBASIC 2.5}

IRleft VAR Bit
IRright VAR Bit
pulseRH VAR Word
pulseLH VAR Word

DO
FREQOUT 8, 1, 38500   'LH IR LED on pin 8
IRleft=IN9            'LH IR sensor on pin 9
FREQOUT 2, 1, 38500   'RH IR LED on pin 2
IRright=IN0           'RH IR sensor on pin 0

IF (IRleft=0) AND (IRright=0) THEN
pulseLH=650
pulseRH=850
ELSEIF (IRleft=0) THEN
pulseLH=850
pulseRH=850
ELSEIF(IRright=0) THEN
pulseLH=650
pulseRH=650
ELSE
pulseLH=850
pulseRH=650
ENDIF

PULSOUT 13, pulseLH   'LH servo on pin 13
PULSOUT 12, pulseRH   'RH servo on pin 12
PAUSE 15
LOOP

Fine tuning of the algorithm – prevent falling

While the programming above allows the robot to navigate freely, it cannot prevent the robot from falling off a certain surface, for instance if the work environment is a table top.
Two variables, a counter and a variable for limiting the number of executions for the loop, can be added, as in the following example:

' {$STAMP BS2}
' {$PBASIC 2.5}

IRleft VAR Bit
IRright VAR Bit
pulseRH VAR Word
pulseLH VAR Word
cntloop VAR Byte      'FOR...NEXT loop counter
cntpuls VAR Byte      'predefined number of loop executions
DO
FREQOUT 8, 1, 38500   'LH IR LED on pin 8
IRleft=IN9            'LH IR sensor on pin 9
FREQOUT 2, 1, 38500   'RH IR LED on pin 2
IRright=IN0           'RH IR sensor on pin 0

IF (IRleft=0) AND (IRright=0) THEN    'surface detected by both sensors
cntpuls=1                             '1 servo pulse forward
pulseLH=650
pulseRH=850
ELSEIF (IRleft=1) THEN     'RH sensor no detection
cntpuls=10                 '10 servo pulses left
pulseLH=850
pulseRH=850
ELSEIF(IRright=1) THEN     'LH sensor no detection
cntpuls=10                 '10 servo pulses right
pulseLH=650
pulseRH=650
ELSE
cntpuls=15                 '15 servo pulses back if no
pulseLH=850                'detection on both sensors
pulseRH=650
ENDIF

FOR cntloop=1 TO cntpuls   'pulse generation
PULSOUT 13, pulseLH        'LH servo on pin 13
PULSOUT 12, pulseRH        'RH servo on pin 12
PAUSE 20
NEXT
LOOP

Fine tuning of the algorithm – prevent getting stuck in the corners of a room

It can also happen that the robot remains stuck when reaching the corner of a room. What happens is that when the robot approaches a corner the right-hand sensor detects a wall the robot will turn left, the left-hand sensor will almost immediately detect another wall making the robot to turn right. This cycle can repeat itself endlessly until both sensors will simultaneously detect something making the robot to turn 180 degrees or go back.

This problem can be solved by storing previous states of each sensor and incrementing a counter at each left-right detection cycle described above. If the counter reaches a certain value, the robot can be programmed to act in a certain way. This algorithm is presented in the flowchart below:

Flowchart for advanced IR navigation
Flowchart for advanced IR navigation

The following code can be added to the IR navigation script presented earlier:

'...
IRleft VAR Bit    'LH sensor stored value
IRright VAR Bit   'RH sensor stored value
pulseRH VAR Word  'RH servo pulse
pulseLH VAR Word  'LH servo pulse
counter VAR Nib   'left-right cycle counter
prevRH VAR Bit    'previous RH value
prevLH VAR Bit    'previous LH value

prevLH=0          'initialization
prevRH=1
counter=1

DO
FREQOUT 8, 1, 38500   'LH IR LED on pin 8
IRleft=IN9            'LH IR sensor on pin 9
FREQOUT 2, 1, 38500   'RH IR LED on pin 2
IRright=IN0           'RH IR sensor on pin 0

IF (IRleft<>IRright) THEN   'if left or right detection
IF (prevLH<>IRleft) AND (prevRH<>IRright) THEN
counter=counter+1                 'and new values different
prevLH=IRleft                     'from stored, counter increment
prevRH=IRright                    'because alternance detected
                                  'new values are stored
IF (counter>4) THEN
counter=1
'... servo pulses for 180 degree turn
ENDIF
ELSE
counter=1
ENDIF
ENDIF

Proportional distance regulation

The robot can be programmed to follow a moving target, for example another robot in a convoy. Our robot must be able to detect the distance to the followed target and must be able to perform speed and direction adjustments in order to maintain a predefined following position.

The block diagram for proportional regulation of a servomotor’s speed is presented below. The feedback information is represented by IR sensor status.

Proportional distance regulation diagram for one motor
Proportional distance regulation diagram for one motor

Object pick-up and displacement

The robot is programmed to find the object, grab it with the gripper and transport it to a predefined location. Between the two locations, the object pick-up zone and the drop zone, the robot must travel in a straight line.

Trajectory errors are pretty high and are caused by the fact that the robot is not equipped with a system through which it can establish its position in the environment. Moreover the robot has to perform several operations, when locating the object it must execute a 180 degree turn to position the gripper located in the back and when reaching the drop zone it must do another 180 degree turn to place the object. The rolling surface type can also greatly affect the straight line trajectory of the robot, requiring extensive calibration and testing of the servomotors.

For improved performance high contrast markers can be placed in the path of the robot, however this would result in a limited versatility in this configuration.

' {$STAMP BS2}
' {$PBASIC 2.5}

kpl CON -15      'P regulation constants
kpr CON 15
ref CON 1

pulsc CON 750    'servo pulse constants
gclosed CON 1100
gopen CON 200

freqsel VAR Nib  'IR detection variables
irfreq VAR Word
irdetl VAR Bit
irdetr VAR Bit
irdetgrip VAR Bit
distl VAR Nib
distr VAR Nib

pulseLH VAR Word 'miscellaneous variables
pulseRH VAR Word

counter VAR Word
counter2 VAR Nib

counter2=0

DEBUG CLS,
"object in area...", CR,
"left right", CR,
"-----------------"

DO
GOSUB objectpos          'object detect and positioning

PAUSE 500

FOR counter=0 TO 52      '180 degree turn
PULSOUT 12, 700
PULSOUT 13, 700
PAUSE 20
NEXT

FOR counter=0 TO 50      'open gripper
PULSOUT 14, gopen
PAUSE 20
NEXT

DO                       'check if object is inside gripper
FREQOUT 1,1,38500
irdetgrip=IN2
PULSOUT 12, 790
PULSOUT 13, 710
LOOP UNTIL irdetgrip=1

FOR counter=0 TO 60     'close gripper
PULSOUT 14, gclosed
PAUSE 20
NEXT

GOSUB objectpos

FREQOUT 1,1,38500       'check gripper status (full or empty)
irdetgrip=IN2

IF (irdetgrip=1) THEN   '180 degree turn
FOR counter=0 TO 50
PULSOUT 12, 800
PULSOUT 13, 800
PAUSE 20
NEXT

FOR counter=0 TO 50     'open gripper
PULSOUT 14, gopen
PAUSE 20
NEXT

DO                      'slowly move forward until
FREQOUT 1,1,38500       'the object is no longer in
irdetgrip=IN2           'gripper reach
PULSOUT 12, 710
PULSOUT 13, 790
LOOP UNTIL irdetgrip=0
ENDIF

FOR counter=0 TO 100
PULSOUT 12, 650
PULSOUT 13, 850
NEXT
LOOP

objectpos:             'servo speed P regulation subroutine
DO
GOSUB getdist
GOSUB sendpuls
'GOSUB dispdist        'sensor info can be displayed on computer
                       'but robot will become sluggish
pulseLH=(ref-distl)*kpl+pulsc
pulseRH=(ref-distr)*kpr+pulsc

IF (ref=distl) THEN
PULSOUT 13, pulsc
IF (ref=distr) THEN
PULSOUT 12, pulsc
counter2=counter2+1
ENDIF
ENDIF
LOOP UNTIL counter2=2
counter2=0
RETURN

getdist:               'subroutine for determining distance to detected object
distl=0
distr=0
FOR freqsel=0 TO 4
LOOKUP freqsel, [37500,38250,39500,40500,41500],irfreq
FREQOUT 1,1,irfreq
irdetl=IN15
distl=distl+irdetl
FREQOUT 1,1,irfreq
irdetr=IN0
distr=distr+irdetr
NEXT
RETURN

sendpuls:              'pulse generation subroutine for all 3 servos
PULSOUT 13, pulseLH
PULSOUT 12, pulseRH
PULSOUT 14, gclosed
RETURN

dispdist:              'sensor info display subroutine
DEBUG CRSRXY,2,3, DEC1 distl,
CRSRXY,13,3, DEC1 distr,
CRSRXY,0,4,"-----------------",
CRSRXY,0,5,"stare gripper: ", DEC1 irdetgrip,
CRSRXY,9,6, DEC1 counter2
RETURN

Multiple routines in the same script

This script makes switching between different routines possible simply by pressing buttons mounted on the robot. In this way a connecting to a computer for uploading a different routine is not necessary. A 1-digit LED display is also used for easily observing what choice is made.

In the first subroutine information from the IR sensors is read and displayed in the debug console on the computer, in the second subroutine the robot navigates freely in the environment and avoids obstacles. In mode 3 the robot can track a moving target and proportionally regulate its distance to it. By pressing a button the program returns to mode 0, the selection mode.

' {$STAMP BS2}
' {$PBASIC 2.5}

'-------- 1 digit LED display character definitions
c0 CON %0111111
c1 CON %0000110
c2 CON %1011011
c3 CON %1001111
c4 CON %1100110
c5 CON %1101101
c6 CON %1111101
c7 CON %0100111
c8 CON %1111111
c9 CON %1101111

a CON %1110111
b CON %1111100
c CON %0111001
d CON %1011110
e CON %1111001
f CON %1110001

DIRL=%01111111      'pins 0-6 set as output

displ VAR Byte

segments VAR OUTL

'-------- button defininitions
btns VAR Nib
btn1 VAR btns.BIT0
btn2 VAR btns.BIT1
button1 PIN 15
button2 PIN 11

index VAR Nib
counter VAR Nib

program VAR Nib

'-------- IR sensors variables
irdetl VAR Bit
irdetr VAR Bit
cntpuls VAR Byte
distl VAR Byte
distr VAR Byte
freqsel VAR Byte
irfreq VAR Byte

'-------- proportional regulation constants
kpl CON -35
kpr CON 35
ref CON 2
pulsc CON 750

pulsl VAR Word
pulsr VAR Word

GOSUB displnumbr
program=0

DO 'main loop start

SELECT program

CASE 0 'mode select routine
GOSUB buttons
DEBUG CRSRXY,10,6, DEC program

IF (btns=%10) OR (btns=%01) THEN    'if a button is pressed
displ=displ+btn2//10                'a counter is incremented
GOSUB displnumbr                    'value is sent to display
DEBUG CRSRXY, 0,5, DEC displ        'and selection variable

IF (btns=%01) THEN
program=displ
ENDIF
PAUSE 250
ENDIF

CASE 1                          'mode 1 – display on computer distances to detecte objects
PAUSE 2000
IF (button1=0) THEN program=0   'if button 1 is pressed program returns
'to selection mode
GOSUB detdist
GOSUB dispdist

CASE=2                          'mode 2 – free navigation using IR sensors
PAUSE 2000
IF (button1=0) THEN program=0

FREQOUT 10,1,38500
irdetl=IN9
FREQOUT 7,1,38500
irdetr=IN8

IF (irdetl=0) AND (irdetr=0) THEN
GOSUB back
GOSUB left
GOSUB left
ELSEIF (irdetl=0) THEN
GOSUB right
ELSEIF (irdetr=0) THEN
GOSUB left
ELSE
GOSUB fwd
ENDIF

CASE 3                        'mode 3 – P distance regulation
PAUSE 2000
IF (button1=0) THEN program=0

GOSUB detdist
pulsl=ref-distl*kpl+pulsc
pulsr=ref-distr*kpr+pulsc
ENDSELECT
LOOP                          'main loop end

displnumbr:
LOOKUP displ, [c0,c1,c2,c3,c4,c5,c6,c7,c8,c9], segments
RETURN

buttons:
btns=%0011
FOR index=1 TO 5
btns.BIT0=btns.BIT0 & button1
btns.BIT1=btns.BIT1 & button2
DEBUG CRSRXY, 10,5, BIN4 btns 'displ stari buttons
NEXT
RETURN

detdist:
distl=0
distr=0

FOR freqsel=0 TO 4
LOOKUP freqsel,[37500, 38250,39500,40500,41500], irfreq
FREQOUT 10,1,irfreq
irdetl=IN9
distl=distl+irdetl
FREQOUT 7,1,irfreq
irdetr=IN8
distr=distr+irdetr
PAUSE 100
NEXT
RETURN

dispdist:
DEBUG CRSRXY,0,3,DEC1 distl,
CRSRXY,9,3,DEC1 distr
RETURN

sendpuls:
PULSOUT 13, pulsl
PULSOUT 12, pulsr
RETURN

fwd:
PULSOUT 13, 850
PULSOUT 12, 650
PAUSE 20
RETURN

left:
FOR cntpuls = 0 TO 20
PULSOUT 13, 650
PULSOUT 12, 650
PAUSE 20
NEXT
RETURN

right:
FOR cntpuls = 0 TO 20
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN

back:
FOR cntpuls = 0 TO 40
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN

 

Conclusions

Even for a simple robot like this features can be greatly expanded, the main limitation in this case being the interpreter which can execute instructions purely sequential. This limitation can be overcome very easily by using multiple dedicated microcontrollers or more advanced multi-core units.

A model like this can be scaled up very easily, thus providing extended duty capabilities while retaining simplicity.

With the aid of more advanced sensor arrays and minor electronic adaptations the robot can be programmed to be either fully autonomous, remote controlled or can even assist the remote human operator, overriding commands which could not be adequate.

Resources

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.