Lecture2 Bugs PoF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 58

Unit 1: Bug Algorithms

The slides are a compilation of work based on notes and slides from Morteza Lahijanian, Howie
Choset, Lydia Kavraki, Greg Hager, Mark Moll, G. Ayorkor Mills-Tetty, Hyungpil Moon, Zack
Dodds, Nancy Amato, Steven Lavalle, Seth Hutchinson, George Kantor, Dieter Fox, Vincent Lee-
Shue Jr., Prasad Narendra Atkar, Kevin Tantiseviand, Bernice Ma, David Conner, and other
members of previous versions of this class. HC wants to especially thank Greg Hager and Ji
Yeong Lee for their help in supplying template slides and figures.
Today’s topic: Bug Algorithms

From McGuire at al, 2018


Overview

• Bug 1 Algorithm

• Bug 2 Algorithm

• Tangent Bug Algorithm


Think Like a Bug

• How would you navigate to Goal where food is?


• Can smell food but can’t see far
• No knowledge of the walls

• Write the algorithm …


Goal

Start
Why Bug Algorithms?

• Many planning algorithms assume global knowledge

• Bug algorithms assume only local knowledge of the


environment and a global goal

• Bug behaviors are simple:


• Follow a wall (right or left)
• Move in a straight line toward goal Goal

• Bug 1 and Bug 2 assume essentially tactile sensing

• Tangent Bug deals with finite distance sensing


Start
Definitions

• Workspace:

• the environment, in which the robot operates

• Notation: 𝑊
Goal
• Generally, either 2- or 3-dimensional
Euclidean space: ℝ2 or ℝ3

• Could be infinite (open) or bounded


(closed/compact) space

Start
• Obstacle 𝑖 in workspace 𝑊 is denoted by 𝑊𝑂𝑖

• Free workspace: 𝑊free = 𝑊 ∖ ⋃𝑖 𝑊𝑂𝑖


The Bug Algorithms

• Insect inspired with provable results!

• known direction to goal:


• robot can measure distance 𝑑(𝑥, 𝑦) between points 𝑥, 𝑦 ∈ 𝑊
• otherwise local sensing
• walls/obstacles & encoders

• Reasonable world:
Goal
1. finitely many obstacles in finite area
2. a line will intersect an obstacle finitely many times
3. workspace is bounded:

𝑊 ⊂ 𝐵𝑟 (𝑥), 𝑟 < ∞
Ball with
radius 𝑟
centered 𝐵𝑟 (𝑥) = { 𝑦 ∈ ℝ2 ∣ 𝑑(𝑥, 𝑦) < 𝑟 } Start
at 𝑥
The Bug Algorithms

• Assumptions

1. We know the position at all times - perfect localization

2. Contact sensor is available

3. Robot can measure distance to the goal Goal

Start
Bugginer Strategy

“Bug 0” algorithm • Assumptions:


• known direction to goal
• otherwise local sensing
𝑞goal walls/obstacles & encoders

𝑞start
how?
Bugginer Strategy

“Bug 0” algorithm • Assumptions:


• known direction to goal
• otherwise local sensing
𝑞goal walls/obstacles & encoders

• Strategy:
1. head toward goal
2. follow obstacles until you can
head toward the goal again
3. continue

𝑞start
path?
“Bug 0” Algorithm

𝑞goal

“Bug 0” algorithm

1. head toward goal


2. follow obstacles until you can
head toward the goal again
Assume a left-turning robot. 3. continue
𝑞start The turning direction is
decided beforehand.

done?
Bug Zapper

What map will foil Bug 0 ?

“Bug 0” algorithm
goal
1. head toward goal
2. follow obstacles until you can
head toward the goal again
3. continue

a left-turning robot start


Bug Zapper

How to make it smarter?


Suggestion: add memory?!

“Bug 0” algorithm
goal
1. head toward goal
2. follow obstacles until you can
head toward the goal again
3. continue

a left-turning robot start


“Bug 1” Algorithm

• Assumptions:
• known direction to goal
• otherwise local sensing
walls/obstacles & encoders
• Has memory
goal • Strategy:
1. head toward goal
2. if an obstacle is encountered,
circumnavigate it and
remember how close you get
to the goal
start 3. return to that closest point (by
wall-following) and continue
“Bug 1” Algorithm

𝑞goal “Bug 1” algorithm


• Strategy:
1. head toward goal
2. If an obstacle is encountered,
circumnavigate it and
remember how close you get
to the goal
3. return to that closest point (by
wall-following) and continue

𝑞start
“Bug 1” Algorithm

Algorithm: Bug 1

Input: A point robot with a tactile sensor


Output: A path to the 𝑞goal or a conclusion no such path exists

• Let 𝑞𝐿0 = 𝑞start ; 𝑖 = 1


• Repeat
Repeat
from 𝑞 𝐿𝑖−1 move toward 𝑞goal
Until goal is reached or obstacle encountered at 𝑞𝐻𝑖
If goal is reached,
exit
Repeat
follow boundary recording point 𝑞𝐿𝑖 with shortest distance to goal
Until 𝑞goal is reached or 𝑞𝐻𝑖 is re-encountered
If goal is reached
exit
Go to 𝑞𝐿𝑖
If move toward 𝑞goal moves into obstacle
exit with failure
Else
i=i+1
continue

𝑞 𝐻𝑖 : hit point 𝑞 𝐿𝑖 : leave point


“Bug 1” Algorithm

Algorithm: Bug 1

Input: A point robot with a tactile sensor


Output: A path to the 𝑞goal or a conclusion no such path exists

• Let 𝑞𝐿0 = 𝑞start ; 𝑖 = 1


• Repeat
Repeat
from 𝑞 𝐿𝑖−1 move toward 𝑞goal
Until goal is reached or obstacle encountered at 𝑞𝐻𝑖
If goal is reached,
exit
Repeat
follow boundary recording point 𝑞𝐿𝑖 with shortest distance to goal
Until 𝑞goal is reached or 𝑞𝐻𝑖 is re-encountered
If goal is reached
exit
Go to 𝑞𝐿𝑖
If move toward 𝑞goal moves into obstacle
exit with failure
Else
i=i+1
continue

𝑞 𝐻𝑖 : hit point 𝑞 𝐿𝑖 : leave point


Faiure “Bug 1” Algorithm
“Bug 1” Analysis

Bug 1: Path Bounds What are upper/lower bounds


on the path length that the
𝑞goal robot takes?
𝐷 = straight-line distance from start to goal
𝑃𝑖 = perimeter of the 𝑖 th obstacle

𝐷 𝑃2 Lower bound: 𝐷
What’s the shortest
distance it might travel?

𝑃1 Upper bound:
What’s the longest
distance it might travel?
𝑞start
“Bug 1” Analysis

Bug 1: Path Bounds What are upper/lower bounds


on the path length that the
𝑞goal robot takes?
𝐷 = straight-line distance from start to goal
𝑃𝑖 = perimeter of the 𝑖 th obstacle

𝐷 𝑃2 Lower bound: 𝐷
What’s the shortest
distance it might travel?

3
𝑃1 Upper bound: 𝐷 + ∑ 𝑃𝑖
What’s the longest
distance it might travel?
2
𝑞start
“Bug 1” Analysis

• Definition (Completeness):
• an algorithm is complete if, in finite time, it finds a path if such a path exists
or terminates with failure if it does not

• Prove Bug 1 is complete:


• Suppose BUG1 were incomplete
• Therefore, there is a path from start to goal
• By assumption, it is finite length, and intersects obstacles a finite number
of times.
• BUG1 does not find it
• Either it terminates incorrectly, or, it spends an infinite amount of time
• Suppose it never terminates
• But each leave point is closer to the goal than corresponding hit point
• Each hit point is closer than the last leave point
• Thus, there are a finite number of hit/leave pairs; after exhausting them, the robot
will proceed to the goal and terminate
• Suppose it terminates (incorrectly). Then, the closest point after a hit must be a
leave where it would have to move into the obstacle
• But, then line from robot to goal must intersect object even number of times (Jordan
curve theorem)
• But then there is another intersection point on the boundary closer to object. Since
we assumed there is a path, we must have crossed this point on boundary which
contradicts the definition of a leave point.
Better Bug?

How to make it even better?

𝑞goal
“Bug 1” algorithm
• Strategy:
1. head toward goal
2. If an obstacle is encountered,
circumnavigate it and
remember how close you get
to the goal
3. return to that closest point (by
wall-following) and continue
𝑞start
Better Bug?

How to make it even better?

𝑞goal B
“Bug 1” algorithm
• Strategy:
1. head toward goal
2. If an obstacle is encountered,
A circumnavigate it and
remember how close you get
to the goal
3. return to that closest point (by
wall-following) and continue
𝑞start
Better Bug?

How to make it even better?


Call the line from the starting
point to the goal the m-line
𝑞goal

1. head toward goal on the m-line


2. if an obstacle is in the way, follow it
until you encounter the m-line again
3. leave the obstacle and continue
toward the goal

𝑞start
“Bug 2” Algorithm

𝑞goal
“Bug 2” algorithm

1. head toward goal on the m-line


2. if an obstacle is in the way, follow it
until you encounter the m-line again
3. leave the obstacle and continue
toward the goal

done?
𝑞start
“Bug 2” Algorithm

“Bug 2” algorithm
start

1. head toward goal on the m-line


2. if an obstacle is in the way, follow it
until you encounter the m-line again
3. leave the obstacle and continue
toward the goal

done?
Goal NO! How do we fix this?
“Bug 2” Algorithm

“Bug 2” algorithm

1. head toward 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

Better or worse than Bug1?


“Bug 2” Algorithm

Left turn VS Right turn


“Bug 2” Algorithm

Algorithm: Bug 2

Input: A point robot with a tactile sensor


Output: A path to the 𝑞goal or a conclusion no such path exists

• Let 𝑞𝐿0 = 𝑞start ; 𝑖 = 1


• Repeat
Repeat
from 𝑞 𝐿𝑖−1 move toward 𝑞goal along the m-line
Until goal is reached or obstacle encountered at 𝑞𝐻𝑖
If goal is reached
exit
Repeat
follow boundary
Until 𝑞goal is reached or 𝑞𝐻𝑖 is re-encountered or m-line is re-encountered, 𝑥 is not 𝑞𝐻𝑖 ,
𝑑(𝑥, 𝑞goal ) < 𝑑(𝑞𝐻𝑖 , 𝑞goal ) and way to goal is unimpeded
If goal is reached
exit
𝐻
If 𝑞 𝑖 is reached
exit with failure
Else
i=i+1
continue

𝑞 𝐻𝑖 : hit point 𝑞 𝐿𝑖 : leave point


“Bug 1” VS “Bug 2”

Draw worlds in which Bug 2 does better than Bug 1 (and vice versa).

Bug 2 beats Bug 1 Bug 1 beats Bug 2


𝑞goal

𝑞start
“Bug 1” VS “Bug 2”
Bug 1
Bug 2 – partial strategy
“Bug 1” VS “Bug 2”

• BUG 1 is an exhaustive search algorithm


• it looks at all choices before committing

• BUG 2 is a greedy algorithm


• it takes the first thing that looks better

• In many cases, BUG 2 will outperform BUG 1, but


• BUG 1 has a more predictable performance overall
“Bug 2” Analysis

Bug 2: Path Bounds What are upper/lower bounds


on the path length that the
robot takes?
𝐷 = straight-line distance from start to goal
𝑃𝑖 = perimeter of the 𝑖 th obstacle

Lower bound:
What’s the shortest
𝐷
distance it might travel?

Upper bound:
What’s the longest
distance it might travel?

𝑛𝑖 : # of m-line intersections with the 𝑖-th obstacle


“Bug 2” Analysis

Bug 2: Path Bounds What are upper/lower bounds


on the path length that the
robot takes?
𝐷 = straight-line distance from start to goal
𝑃𝑖 = perimeter of the 𝑖 th obstacle

Lower bound:
What’s the shortest
𝐷
distance it might travel?

1
Upper bound: 𝐷 + ∑ 𝑛𝑖 𝑃𝑖
What’s the longest 2
distance it might travel?

𝑛𝑖 : # of m-line intersections with the 𝑖-th obstacle


Summary

• Bug 1: safe and reliable

• Bug 2: better in some cases; worse in others

• Overall there are some unrealistic assumptions:

• Knowing exactly where the boundary is


• Being able to follow it safely
• No optimal solutions
Potential Fields

• How to specify motion?


• We can always transfer a robot into a space that it is a point(C-space)
• How to get a path?

• Incrementally explore free space


• How about Bug algorithms?
• limited to 2-D
• C-space is generally multi-dimensional,
non-Euclidean
• Let’s improve Bug algorithms
• Assume known obstacles
• Treat robot as a rolling ball
• Make mountains out of obstacles and a
sink hole out of goal destination
Potential Function

• Potential function is a differentiable real-valued function

𝑈: ℝ𝑚 → ℝ

• Can be viewed as energy

• Gradient is a vector
𝑇
𝑇
𝜕𝑈 𝑞 𝜕𝑈 𝑞
∇ 𝑈 𝑞 = 𝐷𝑈 𝑞 = ,…,
𝜕𝑞1 𝜕𝑞𝑚

which points in the direction that locally maximally


increases 𝑈.

• Can be viewed as force. Here, assume 1st order


dynamics, i.e., ∇ 𝑈 𝑞 viewed as velocity.

• Can be used to define vector field.


Potential Function

• Potential functions viewed as landscapes moving the robot from high-value state
to low-value state

• Robot moves downhill by following the negated


gradient of 𝑈

• i.e., Gradient descent:

𝑐ሶ = −∇ 𝑈 𝑐(𝑡)

• Robot terminates when it reaches a point where ∇ 𝑈 vanishes

• Terminating point 𝑞 ∗ called critical point

• Can be maximum, minimum, or


saddle point

maximum saddle minimum


Potential Function

• Second derivative determines the type of critical point

• Hessian matrix
𝜕2𝑈 𝜕2𝑈

𝜕𝑞12 𝜕𝑞1 𝜕𝑞𝑛
𝐻= ⋮ ⋱ ⋮ maximum
𝜕2𝑈 𝜕2𝑈

𝜕𝑞1 𝜕𝑞𝑛 𝜕𝑞𝑛2

• When 𝐻 𝑞 ∗ is non-singular, 𝑞 ∗ is isolated

• 𝐻 𝑞 ∗ > 0 (positive definite): 𝑞 ∗ local minimum

• 𝐻 𝑞 ∗ < 0 (negative definite): 𝑞 ∗ local maximum saddle

• In gradient descent,

• the robot never terminates in maximum or saddle


points because, with a perturbation, it is freed.

• Local minimum is a problem minimum


Attractive/Repulsive Potential

• Simplest potential function in 𝐶free

𝑈 𝑞 = 𝑈𝑎𝑡𝑡 𝑞 + 𝑈𝑟𝑒𝑝 𝑞

𝑈𝑎𝑡𝑡 attracts the robot (goal) and 𝑈𝑟𝑒𝑝 repels the robot (obstacles)

• Designing 𝑈𝑎𝑡𝑡

• should be monotonically increasing with distance from 𝑞goal

• Simplest: conic potential

𝑈𝑎𝑡𝑡 𝑞 = 𝜉 𝑑(𝑞, 𝑞goal )

parameter to scale the


effect of attractive force
Repulsive Potential

• Repulsive potential function 𝑈𝑟𝑒𝑝 keeps the robot from an obstacle

• Strength of 𝑈𝑟𝑒𝑝 depends on robot’s proximity


to an obstacle

• The closer to an obstacle, the stronger


the repulsive force

• Define 𝑈𝑟𝑒𝑝 in terms of distance to the closest obstacle: 𝐷 𝑞


Gradient Descent Algorithm

• Gradient descent is well-known approach to optimization problems

• Idea:

• Start at the initial configuration

• Small step in the direction opposite to the gradient

• Now at a new (start) configuration

• Repeat until gradient is zero


Gradient Descent Algorithm

• Potential function 𝑈 = 𝑈𝑎𝑡𝑡 + 𝑈𝑟𝑒𝑝 :

• 𝑞 𝑖 : value of 𝑞 at iteration 𝑖

• 𝛼(𝑖): step size at the 𝑖 iteration


• Needs to be small enough not to allow “jump into obstacles”
• Needs to be large enough not to require excessive computation time
• The value is typically chosen ad hoc or empirically
• e.g., based on distance to the nearest obstacle or to the goal
Gradient Descent Algorithm

• Potential function 𝑈 = 𝑈𝑎𝑡𝑡 + 𝑈𝑟𝑒𝑝 :

• Highly unlikely to exactly satisfy ∇𝑈 𝑞 𝑖 =0

• More realistic condition:


𝜖
∇𝑈 𝑞 𝑖 ≤𝜖 𝑞goal
Computing Distance

• Potential function 𝑈 = 𝑈𝑎𝑡𝑡 + 𝑈𝑟𝑒𝑝

• Computing distance in 𝑈𝑎𝑡𝑡 is simple because distance to a point

• Computing distance in 𝑈𝑟𝑒𝑝 challenging because distance to obstacle

• For 𝑈𝑟𝑒𝑝 , can use various distance definitions, e.g.,

• Range sensor distance

• Discrete distance through discretization of continuous space


Computing Distance – Brushfire Algorithm

• Brushfire: grid-based algorithm for computing distance to obstacles

• Discretize 𝐶-space using a grid

• Define neighbors (connectivity) for each cell (pixel):

1. only those that share facets with the current cell

• Relates to Manhattan or 𝐿1 distance

• E.g., neighbors of 𝑁5 : {𝑁2 , 𝑁4 , 𝑁6 , 𝑁8 }

2. Those that share facets and vertices with the


current cell

• E.g., neighbors of 𝑁5 : {𝑁1 , … , 𝑁4 , 𝑁6 , … , 𝑁9 }


Computing Distance – Brushfire Algorithm

• Brushfire algorithm:

• Give a value of 1 to every grid cell (pixel) that


overlaps (even partially) with an obstacle and 0
to the others (free space)

• Give value of 2 to every 0-valued cell that is a


neighbor of 1-valued cell

• Give value of 3 to every 0-valued cell that is a


neighbor of 2-valued cell

• …

• Repeat until all every cell has a non-zero value

• Called Brushfire because the fire (obstacle value) grows from each of the
obstacles until it consumes all of the free-space cells
Computing Distance – Brushfire Algorithm

• Brushfire algorithm:
Computing Distance – Brushfire Algorithm

• The gradient distance at a cell:

• a neighbor with the lowest value

• if multiple neighbors with the same lowest value, just simply pick one

• The gradient is the vector pointing to this cell

• The grid is an approximation of the space, so the gradient is an approximation of


the actual distance gradient

• Can be generalized into higher dimensions

• Can become computationally intractable in higher dimensions


Now back to planning with potential fields:
Have we solved all problems?
Local Minima Problem

• Problem with all gradient descent algorithms:

• Getting stuck in local minima

• Gradient descent is guaranteed to to converge


to a minimum in the field

• No guarantee this minimum is the global


minimum

• No guarantee gradient descent will find a


path to 𝑞goal

• Gradient vanishes when the sum of the attractive


gradient and the repulsive gradient is zero
Wave-Front Planner

• Simplest solution to the local minima problem: Wave-front planner

• Inspired by brushfire algorithm

• Use a grid

• Exclude obstacles from the grid

• Follow the attractive force to goal


Wave-Front Planner

• Wave-front algorithm

• Initially, set cell values of 1 to obstacles


and 2 to the goal cell

• Give a value of 0 to the rest


𝑞start 𝑞goal
• Give a value of 3 to all the 0-valued
neighbors of the 2-valued cell

• Give a value of 4 to all the 0-valued


neighbors of the 3-valued cell

• …

• Repeat until start location is reached


4

• Grows a wave front from the goal


Wave-Front Planner

• Wave-front algorithm
Wave-Front Planner

• Path computed by gradient descent from 𝑞start

• All the points on the wave front have the same Manhattan distance

• Wave-front planner essentially forms a potential function on the grid, which has
only one local minimum

• Hence, complete planner w.r.t. the grid

• Also, determines the shortest path


4
• can comes dangerously close to obstacles

• Drawback: has to search the entire space for a path

• Generalizes to high dimensions

• Computationally intractable in high dimensions


Summary

• Potential functions + gradient descent


• Need careful design of these functions
• Simplest form: 𝑈 = 𝑈𝑎𝑡𝑡 + 𝑈𝑟𝑒𝑝
• Use Gradient descent for motion planning
• Challenge: computing distances
• Continuous approach: range sensor
• Discretization approach: Brushfire algorithm
• Problem: getting stuck in local minima

• Wave-front planner
• Discretization-based approach and uses only 𝑈𝑎𝑡𝑡 (removes obstacles)
• Resolves local minima problem
• Complete planner w.r.t. discretization
• Suffers from state-explosion problem in high dimensions

You might also like