Skip to main content Link Search Menu Expand Document (external link)

Bug 2

Table of contents

  1. Working of Algorithm
  2. MATLAB Code
  3. References

Working of Algorithm

Bug algorithms assume only knowledge of the environment and a global goal. Their behaviors are quite simple:

  1. Follow a wall (right or left)
  2. Move in a straight line toward goal

The “catch” here is simple as displayed in the below figure

  1. Head towards goal on the m-line
  2. If an obstacle is in the way, follow it until you encounter the m-line again closer to the goal
  3. Leave the obstacle and continue toward the goal

Howie chest Bug_2

The algorithm is used when you have a mobile robot

  • With a known starting location
  • With a known goal location**
  • An Unexplored environment
  • Contains a distance sensor that can detect distances to objects and walls in the environment
  • Contains an encoder that the robot can use to estimate how far the robot has traveled from the starting location

MATLAB Code

% We start by loading an obstacle field to challenge the robot

load house;
about house;   % matrix is an example of occupancy grid 

% list of named places within the house
place

% Assumptions:
% 1. robot operates in a grid world and occupies one grid cell
% 2. robot is capable of omnidirectional motion and can move to any of its eight neighboring grid cells
% 3. it is able to determine its position on the place which is a nontrivial problem

% we create an instance of the bug2 class
bug = Bug2(house);

% The bug2 algorithm does not use the map to plan a path – the map is used by the simulator to provide sensory inputs to the robot.

bug.plot();     % to display robot's environment

% to simulate using 'query' command and the arguments are start and goal
% position of the robot within the house.
bug.query(place.br3, place.kitchen, 'animate')  

% bug.query(place.garden, place.kitchen, 'animate')  % this takes very very loooong time

p = bug.query(place.br3, place.kitchen)
about p

Bug 2 figure

References

  1. Bug 2 by automatic addison - Implemented using Python
  2. Howie Chest lecture slides - CMU