Encoder Front Page
SRS Home | Front Page | Monthly Issue | Index
Google
Search WWW Search seattlerobotics.org

SCROB
Subsumption Controlled RObotic Bug

Design & Development

George Vastianos
Electronics Engineer BSc.
Dipl. from Electronics Department,
Faculty of Technological Applications,
Technological Educational Institute of Piraeus, Greece

www.vastianos.com

Table of contents

0. Abstract
1. Robot's hardware
1.1 The AT90S2313 microcontroller
1.2 Hardware implementation of SCROB robot
2. Robot's software
2.1 Subsumption control network
2.2 Decide behavior
2.3 Escape behavior
2.4 Follow behavior
2.5 Software implementation of SCROB robot
2.5.1 Robot's software driver
2.5.2 Implementation of photovoric attitude
2.5.3 Implementation of photophobic attitude
3. Robot's photo gallery
4. References

Keywords: Artificial intelligence & life, bahavior networks, subsumption architecture, behavior-based robots, mobile robotic systems, micro-robotics.

0. Abstract

Subsumption architecture is the result of work by professor Rodney Brooks and the Mobile Robotics Group at the MIT Artificial Intelligence Lab. Brooks' subsumption architecture arose from an attempt to escape the confines of traditional robot control methods and provides a way of combining distributed real-time control with sensor-triggered behaviors. SCROB is a micro-robot that uses subsumption architecture to implement a variety of different attitudes that are consisted from a hierarchical group of behaviors. SCROB's brain is based on a RISC microcomputer that is capable to execute four millions instructions per second. The robot's subsumption control network is implemented by using the software strategy of the cooperative multitasking. The parallel execution of the behaviors is achieved from a group of fifteen finite state machines (FSMs) that are divided in three behaviors.

Notice: This paper is not a tutorial in subsumption architecture. If you don't have background knowledge about this architecture read the references (chapter 4) for further reading...

1. Robot's hardware

1.1 The AT90S2313 microcontroller

The AT90S2313 is a low-power CMOS 8-bit microcontroller based on the AVR RISC architecture. By executing powerful instructions in a single clock cycle, the AT90S2313 achieves throughputs approaching 1 MIPS per MHz allowing the system designer to optimize power consumption versus processing speed.

The AVR core combines a rich instruction set with 32 general-purpose working registers. All the 32 registers are directly connected to the Arithmetic Logic Unit (ALU), allowing two independent registers to be accessed in one single instruction executed in one clock cycle. The resulting architecture is more code efficient while achieving throughputs up to ten times faster than conventional CISC microcontrollers.

The AT90S2313 provides the following features: 2K bytes of In-System Programmable Flash, 128 bytes EEPROM, 128 bytes SRAM, 15 general-purpose I/O lines, 32 general-purpose working registers, flexible timer/counters with compare modes, internal and external interrupts, a programmable serial UART, programmable Watchdog Timer with internal oscillator, an SPI serial port for Flash Memory downloading and two software selectable power-saving modes. The Idle Mode stops the CPU while allowing the SRAM, timer/counters, SPI port and interrupt system to continue functioning. The Power-down Mode saves the register contents but freezes the oscillator, disabling all other chip functions until the next external interrupt or hardware reset.

The device is manufactured using Atmelís high-density nonvolatile memory technology. The on-chip In-System Programmable Flash allows the program memory to be reprogrammed in-system through an SPI serial interface or by a conventional nonvolatile memory programmer. By combining an enhanced RISC 8-bit CPU with In-System Programmable Flash on a monolithic chip, the Atmel AT90S2313 is a powerful microcontroller that provides a highly flexible and cost-effective solution to many embedded control applications.

The AT90S2313 AVR is supported with a full suite of program and system development tools including: C compilers, macro assemblers, program debugger/simulators, in-circuit emulators and evaluation kits.

1.2 Hardware implementation of SCROB robot

The robot's brain based on the AT90S2313 AVR microcontroller that described above. The microcontroller (IC2) uses a quartz of 4MHz (X1) to achieve a command-execution speed close to 4MIPS (Millions Instructions Per Second). Two photoresistors (PR1,2) have been used as eye sensors and four small switches (SW1,4) as whisker sensors. Also a button (SW5) is used as a special sensor for the training process of the robot. The actuators of the robot are only two: a dc motor (M1) that is installed on a "Move forward/Move Backward-Turn" mechanical chassis and a small piezo electric buzzer (BZ1) that is used for sound production. The "Move forward/Move Backward-Turn" mechanical chassis have been constructed from pieces of an old toy car. This type of chassis is very famous in small toy cars and offers an X-Y locomotion with only one motor!!! The electronic circuit of the robot is the following:

PARTDESCRIPTION
SW1-4,6SPST SWITCHES
SW5SPST BUTTON
C1,2100nF
C3330nF
C4,522pF
C6,74700uF/25V
D1-41N4148
PR1,2PHOTORESISTORS
R110K/0,25W
X14MHz QUARTZ
TR1BC546 NPN TRANSISTOR
IC1L293B DOUBLE H-BRIDGE
IC2AT90S2313 AVR RISC MICROCONTROLLER
M1DC MOTOR
BZ1PIEZO ELECTRIC BUZZER
BT1-41,5V AA BATTERIES

As you see above, the microcontroller (that has no A/D converter) is connected directly with the photoresistors through two capacitors (C1,2). The way that the microcontroller reads the photoresistors' values based on the RC timing circuits' theory. The microcontroller charges the capacitors for a constant time (assuming that the photoresistors have the maximum resistance) and then measures the time that each capacitor needs to discharge through the photoresistor that is connected to it. The measured times express the luminance values that the photoresistors read.

To save space and make the design simpler, the microcontroller uses its internal pull-up resistors (that are purposed for output-pin configurations) and is connected directly with the switches (sensors) that lead the pull-up resistors to logical ground.

The microcontroller drives its actuators through two amplifiers. The motor is controlled from an H-Bridge amplifier that is embedded in the IC1 chip. The H-Bridge type of amplifiers consisted from four transistors and used to control dc motors. The L293B (IC1) includes two embedded H-Bridge amplifiers. The piezo electric buzzer is controlled from a single-transistor "common-emitter" amplifier that uses a NPN transistor (TR1).

The diodes D1-D4 are used as "flyback" diodes to protect the internal transistors of the H-Bridge from the voltages spikes that are caused during the switching of the motor (inductive load). Also the two large capacitors C1,2 are used to buffer the power supply of the microcontroller from the motor transients and they offer stability of the microcontroller's operation.

2. Robot's software

2.1 Subsumption control network

During the software development process, two different programs were developed to test the subsumption architecture on SCROB's platform. The first program turns SCROB to a photovore and the second to a photophobe robot. In both programs the hierarchy of behaviors described from the same subsumption control network. However there are some minor differences inside the behaviors' structure in each case.

This diagram shows only the hierarchy of the behaviors and their connection with the sensors. Detailed structure descriptions of each behavior and how these are implemented using finite state machines can be found in the following chapters.

2.2 Decide behavior

Decide behavior is the behavior with the highest priority in the network. This behavior "decides" if it's worth for the robot to move around or just stay in its current position. The criterion for this decision is the difference between the current luminance level of the surrounding environment and the threshold luminance level. The threshold luminance level is defined during the robot's training process (read more in chapter 2.5).

In case of the photovoric attitude, the main goal of the robot is to find a place where the LIGHT level is greater than a desired level (threshold). Only in this case the robot will be "satisfied" and will stop move, otherwise it will continue to move around with the "hope" that maybe it will reach its goal... The "decide" behavior for the photovoric attitude is consisted by three finite state machines and based on the condition that the value of the front eye must be GREATER than the threshold value. The structure of this behavior for the photovoric attitude is illustrated bellow:

In case of the photophobic attitude, the main goal of the robot is to find a place where the DARK level is greater than a desired level (threshold). Only in this case the robot will be "satisfied" and will stop move, otherwise it will continue to move around with the "hope" that maybe it will reach its goal... The "decide" behavior for the photophobic attitude is consisted by three finite state machines and based on the condition that the value of the front eye must be LOWER than the threshold value. The structure of this behavior for the photophobic attitude is illustrated bellow:

2.3 Escape behavior

Escape behavior is the behavior with the medium priority in the network. The role of this behavior is to protect the robot's existence from collisions with walls or objects that may appear in front of the robot during its route. This behavior uses the whisker sensors that are activated when they touch objects. This behavior is light independent and for this reason it's used exactly the same in both attitudes. The "escape" behavior is consisted by seven finite state machines and is activated only when the robot is moving (so the "decide" behavior is inactive). The structure of this behavior is illustrated bellow:

2.4 Follow behavior

Follow behavior is the behavior with the lowest priority in the network. This behavior makes the robot to "follow", track or seek for a "light" or "dark" source. This behavior is important for the robot and helps it to reach the final goal for a bright or dark placeÖ The criterion for this behavior is the difference between the current luminance levels of the surrounding environment on the front and back eyes.

The "follow" behavior for the photovoric attitude is consisted by five finite state machines and based on the condition that the robot must move forward only when luminance value of the front eye is GREATER than the value of the back eye. The structure of this behavior for the photovoric attitude is illustrated bellow:

The "follow" behavior for the photophobic attitude is consisted by five finite state machines and based on the condition that the robot must move forward only when luminance value of the front eye is LOWER than the value of the back eye. The structure of this behavior for the photophobic attitude is illustrated bellow:

2.5 Software implementation of SCROB robot

The programming language that was used for the development of the robotís software was the BASCOM-AVR basic (Version 1.11.6.2) of MCS Electronics. To make easier the development of the new programs for the SCROB platform, the routines for the robotís initiation, training, sensing and acting have been embedded in the scrob_drv.bas file that works as the robotís software driver. So when the user starts a new program for the robot, includes the $include "scrob_drv.bas" directive in the source code and all the necessary code for the robotís control is embedded automatically.

In the driverís file the Init() subroutine is used for the initiation and is executed automatically during start-up. The Train() subroutine is the second routine that is executed (after the initiation routine) and is used to set the threshold value. During the execution of this routine the train process starts with three short beeps, after this the user must press the train button and hold it pressed, then the buzzer starts to chirp. At this point the microcontroller starts to read the luminance value of the front eye. The chirp continues while the user holds the button pressed. When the button is released, the current luminance value is defined as the threshold value and the train process finishes with a long beep. The Sense() subroutine is used from the userís program to read the sensors and the Act() subroutine is used also from the userís program to control the motor actuator. During start-up, after the execution of the initiation and train subroutines the robotís control passed to the userís program. The source code of the software driver is listed in chapter 2.5.1.

The two programs that have been developed to implement the photovoric and photophobic attitude and are based on the subsumption architecture are consisted by three parts. The first part is the group of the behavior subroutines. Each behavior subroutine has been written by using the finite state machine diagrams and uses two "personal" variables to store the number of its current active finite state machine and the value of its "local" output. The second part is the subroutine of the cooperative multitaskerís scheduler. This routine is the kernel of all the software that runs in parallel all the processes. The scheduler starts by executing the sense routine of the software driver and continues with the execution of all the behavior subroutines. After the execution of the behavior subroutines the results are stored in the "personal" output variables. Then the scheduler runs the Arbitrate() subroutine. This routine is the third part of the software and within this routine the structure of the subsumption control network is defined. So the arbitrate routine reads all the "personal" output variables and according to the hierarchy decides which output will be forwarded to the robotís actuators. This allows us to design behaviors that are completely independent from the rest behaviors and can be added or removed easily without reconfiguration of all the software. The only part that needs to be reconfigured is the arbitrate subroutine. At the end the scheduler forwards the selected (by the Arbitrate() subroutine) output to the robotís motor actuator by executing the Act() subroutine. The source codes of the photovore and photophobe programs are listed in chapters 2.5.2 - 2.5.3.

Robot's software files. (24,5 KBytes)

2.5.1 Robot's software driver

'***************************
'*      SCROB - Robot      *
'*      Driver Module      *
'* R&D by George Vastianos *
'***************************

'Declare module's subroutines
Declare Sub Init
Declare Sub Sense
Declare Sub Act
Declare Sub Train
'Declare sensors' variables
Dim Button As Bit
Dim Front_whisker As Bit
Dim Back_whisker As Bit
Dim Front_eye As Word
Dim Back_eye As Word
'Declare actuators' variables
Dim Motor As Byte
Const Idle_mode = 0
Const Stop_move = 1
Const Move_forward = 2
Const Move_backward_turn = 3
'Declare general variables
Dim Threshold As Word
'Init robot
Init
'Train robot
Train
'Exit module
Goto Exit_module

Sub Init
   '*** Configure robot's sensors ***
   Config Portb = Input
   '> Button sensor
   Set Portb.0
   Button_pin Alias Pinb.0
   '> Front whisker sensor
   Set Portb.1
   Front_whisker_pin Alias Pinb.1
   '> Back whisker sensor
   Set Portb.2
   Back_whisker_pin Alias Pinb.2
   '> Front eye sensor
   Reset Portb.3
   Front_eye_pin Alias Pinb.3
   '> Back eye sensor
   Reset Portb.4
   Back_eye_pin Alias Pinb.4
   '*** Configure robot's actuators ***
   Config Portd = Output
   '> Motor actuator
   Reset Portd.0
   Reset Portd.1
   Motor_a_pin Alias Portd.0
   Motor_b_pin Alias Portd.1
   '> Speaker actuator
   Reset Portd.2
   Speaker_pin Alias Portd.2
End Sub

Sub Sense
   '*** Read sensors ***
   '> Button sensor
   Button = Not Button_pin
   '> Whisker sensors
   Front_whisker = Not Front_whisker_pin
   Back_whisker = Not Back_whisker_pin
   '> Eye sensors
   Config Pinb.3 = Output
   Config Pinb.4 = Output
   Set Portb.3
   Set Portb.4
   Waitms 10
   Config Pinb.3 = Input
   Config Pinb.4 = Input
   Reset Portb.3
   Reset Portb.4
   Dim Looking As Bit
   Front_eye = 65535
   Back_eye = 65535
   Do
      Config Pinb.3 = Output
      Config Pinb.4 = Output
      Config Pinb.3 = Input
      Config Pinb.4 = Input
      If Front_eye_pin = 1 Then Decr Front_eye
      If Back_eye_pin = 1 Then Decr Back_eye
      Looking = Front_eye_pin Or Back_eye_pin
   Loop Until Looking = 0
End Sub

Sub Act
   '*** Write actuators ***
   '> Motor actuator
   Select Case Motor
      '>> Stop move
      Case Stop_move:
         Reset Motor_a_pin
         Reset Motor_b_pin
      '>> Move forward
      Case Move_forward:
         Reset Motor_b_pin
         Set Motor_a_pin
      '>> Move backward
      Case Move_backward_turn:
         Reset Motor_a_pin
         Set Motor_b_pin
   End Select
End Sub

Sub Train
   '*** Define threshold light level ***
   Dim Count_a As Integer
   Dim Count_b As Integer
   '> Start train: 3 short beeps
   For Count_a = 1 To 3
      For Count_b = 1 To 500
         Set Speaker_pin
         Waitus 150
         Reset Speaker_pin
         Waitus 150
      Next Count_b
      Waitms 50
   Next Count_a
   '> Wait until button is pressed
   Bitwait Button_pin , Reset
   '> Read front eye sensor until button is released
   Do
      Sense
      Threshold = Front_eye
      For Count_a = 1 To 100
         Set Speaker_pin
         Waitus 50
         Reset Speaker_pin
         Waitus 50
      Next Count_a
   Loop Until Button = 0
   '> Train finished: 1 long beep
   For Count_a = 1 To 2000
     Set Speaker_pin
     Waitus 300
     Reset Speaker_pin
     Waitus 300
   Next Count_b
   Wait 1
End Sub

Exit_module:

2.5.2 Implementation of photovoric attitude

'***************************
'*      SCROB - Robot      *
'*   Photovoric attitude   *
'* R&D by George Vastianos *
'***************************

'Include robot's driver
$include "scrob_drv.bas"

'Declare behaviors' subroutines, variables & constants
'*** Decide behavior ***
Declare Sub Decide
Dim Decide_state As Byte
Decide_state = 1
Dim Decide_output As Byte
Decide_output = Idle_mode
'*** Escape behavior ***
Declare Sub Escape
Dim Escape_state As Byte
Escape_state = 1
Dim Escape_output As Byte
Escape_output = Idle_mode
Dim Escape_duration As Byte
Escape_duration = 0
Const Duration_max = 10
'*** Follow behavior ***
Declare Sub Follow
Dim Follow_state As Byte
Follow_state = 1
Dim Follow_output As Byte
Follow_output = Idle_mode

'Declare arbitrate subroutine
Declare Sub Arbitrate

'*** SCHEDULER OF COOPERATIVE MULTITASKER ***
Scheduler:
   Do
      '> Read sensors
      Sense
      '> Behaviors
      Decide
      Escape
      Follow
      '> Subsumption
      Arbitrate
      '> Write actuators
      Act
   Loop
End

Sub Decide
   '*** Decide behavior ***
   Select Case Decide_state
      Case 1:
         If Front_eye > Threshold Then
            Decide_state = 2
         Else
            Decide_state = 3
         End If
      Case 2:
         Decide_output = Stop_move
         Decide_state = 1
      Case 3:
         Decide_output = Idle_mode
         Decide_state = 1
   End Select
End Sub

Sub Escape
   '*** Escape behavior ***
   Select Case Escape_state
      Case 1:
         If Front_whisker = 1 Then
            Escape_state = 2
         Else
            Escape_state = 3
         End If
      Case 2:
         Escape_duration = Duration_max
         Escape_output = Move_backward_turn
         Escape_state = 1
      Case 3:
         If Back_whisker = 1 Then
            Escape_state = 4
         Else
            Escape_state = 5
         End If
      Case 4:
         Escape_duration = Duration_max
         Escape_output = Move_forward
         Escape_state = 1
      Case 5:
         If Escape_duration = 0 Then
            Escape_state = 7
         Else
            Escape_state = 6
         End If
      Case 6:
         Decr Escape_duration
         Escape_state = 1
      Case 7:
         Escape_output = Idle_mode
         Escape_state = 1
   End Select
End Sub

Sub Follow
   '*** Follow behavior ***
   Select Case Follow_state
      Case 1:
         If Front_eye > Back_eye Then
            Follow_state = 2
         Else
            Follow_state = 3
         End If
      Case 2:
         Follow_output = Move_forward
         Follow_state = 1
      Case 3:
         If Front_eye < Back_eye Then
            Follow_state = 4
         Else
            Follow_state = 5
         End If
      Case 4:
         Follow_output = Move_backward_turn
         Follow_state = 1
      Case 5:
         Follow_output = Idle_mode
         Follow_state = 1
   End Select
End Sub

Sub Arbitrate
   '*** Implementation of the Subsumption Control Network ***
   If Decide_output <> Idle_mode Then
      Motor = Decide_output
   Elseif Escape_output <> Idle_mode Then
      Motor = Escape_output
   Elseif Follow_output <> Idle_mode Then
      Motor = Follow_output
   End If
End Sub

2.5.3 Implementation of photophobic attitude

'***************************
'*      SCROB - Robot      *
'*  Photophobic attitude   *
'* R&D by George Vastianos *
'***************************

'Include robot's driver
$include "scrob_drv.bas"

'Declare behaviors' subroutines, variables & constants
'*** Decide behavior ***
Declare Sub Decide
Dim Decide_state As Byte
Decide_state = 1
Dim Decide_output As Byte
Decide_output = Idle_mode
'*** Escape behavior ***
Declare Sub Escape
Dim Escape_state As Byte
Escape_state = 1
Dim Escape_output As Byte
Escape_output = Idle_mode
Dim Escape_duration As Byte
Escape_duration = 0
Const Duration_max = 10
'*** Follow behavior ***
Declare Sub Follow
Dim Follow_state As Byte
Follow_state = 1
Dim Follow_output As Byte
Follow_output = Idle_mode

'Declare arbitrate subroutine
Declare Sub Arbitrate

'*** SCHEDULER OF COOPERATIVE MULTITASKER ***
Scheduler:
   Do
      '> Read sensors
      Sense
      '> Behaviors
      Decide
      Escape
      Follow
      '> Subsumption
      Arbitrate
      '> Write actuators
      Act
   Loop
End

Sub Decide
   '*** Decide behavior ***
   Select Case Decide_state
      Case 1:
         If Front_eye < Threshold Then
            Decide_state = 2
         Else
            Decide_state = 3
         End If
      Case 2:
         Decide_output = Stop_move
         Decide_state = 1
      Case 3:
         Decide_output = Idle_mode
         Decide_state = 1
   End Select
End Sub

Sub Escape
   '*** Escape behavior ***
   Select Case Escape_state
      Case 1:
         If Front_whisker = 1 Then
            Escape_state = 2
         Else
            Escape_state = 3
         End If
      Case 2:
         Escape_duration = Duration_max
         Escape_output = Move_backward_turn
         Escape_state = 1
      Case 3:
         If Back_whisker = 1 Then
            Escape_state = 4
         Else
            Escape_state = 5
         End If
      Case 4:
         Escape_duration = Duration_max
         Escape_output = Move_forward
         Escape_state = 1
      Case 5:
         If Escape_duration = 0 Then
            Escape_state = 7
         Else
            Escape_state = 6
         End If
      Case 6:
         Decr Escape_duration
         Escape_state = 1
      Case 7:
         Escape_output = Idle_mode
         Escape_state = 1
   End Select
End Sub

Sub Follow
   '*** Follow behavior ***
   Select Case Follow_state
      Case 1:
         If Front_eye > Back_eye Then
            Follow_state = 2
         Else
            Follow_state = 3
         End If
      Case 2:
         Follow_output = Move_backward_turn
         Follow_state = 1
      Case 3:
         If Front_eye < Back_eye Then
            Follow_state = 4
         Else
            Follow_state = 5
         End If
      Case 4:
         Follow_output = Move_forward
         Follow_state = 1
      Case 5:
         Follow_output = Idle_mode
         Follow_state = 1
   End Select
End Sub

Sub Arbitrate
   '*** Implementation of the Subsumption Control Network ***
   If Decide_output <> Idle_mode Then
      Motor = Decide_output
   Elseif Escape_output <> Idle_mode Then
      Motor = Escape_output
   Elseif Follow_output <> Idle_mode Then
      Motor = Follow_output
   End If
End Sub

3. Robot's photo gallery

Front view Back view Side view
Top view Bottom view Brain view

4. References

  1. Vastianos G., "SCROB - Subsumption Controlled RObotic Bug", (Draft Notes), (01/2002).
  2. Atmel Corporation, "8-Bit RISC Microcontrollers Data Book", San Jose CA, May 1997, pp. 3.5-3.7.
  3. Brooks, Rodney A., "A robust Layered Control System for a mobile Robot.", IEEE Journal of Robotics and Automation., RA-2, April, 14-23, (1986).
  4. Brooks, Rodney A., "A Robust Layered Control System for a Mobile Robot.", Artificial Intelligence Memo 1126, Massachusetts Institute of Technology, (09/1985).
  5. Brooks, Rodney A., "A Robot that Walks; Emergent Behaviors from a Carefully Evolved Network.", Artificial Intelligence Memo 1091, Massachusetts Institute of Technology, (02/1989).
  6. Brooks, Rodney A. and Lynn Andrea Stein, "Building Brains for Bodies.", Artificial Intelligence Memo 1439, Massachusetts Institute of Technology, (08/1993).
  7. Brooks, Rodney A., "Intelligence Without Reason.", Artificial Intelligence Memo 1293, Massachusetts Institute of Technology, (08/1991).
  8. Brooks, Rodney A., "The Behavior Language; User's Guide.", Artificial Intelligence Memo 1126, Massachusetts Institute of Technology, (04/1990).
  9. Flynn Anita M., Rodney Brooks A., and Lee S. Tavarow, "Twilight Zones and Cornerstones: A Gnat Robot Double Feature.", Artificial Intelligence Memo 1126, Massachusetts Institute of Technology, (07/1989).