QQFLY.NET
← Writing

An introduction to motion planning

“What is your PhD about?”

“Motion planning for robot arms.”

“Isn’t that already a mature field? What is left to research?”

“Motion planning, not trajectory planning. Let me explain…”

I have had this conversation with other people in robotics many times. So I thought I should write about what motion planning actually is.

It still took me three weeks to start. Perhaps I had become too relaxed during the summer break at home. Or perhaps writing about my own research brought on the same procrastination as writing a dissertation.

What is motion planning?

Put simply, motion planning means finding a path for a robot from a given position A to a given position B while satisfying specified constraints.

That might mean finding a shortest route to a destination for a mobile robot, or finding a collision-free motion for a robot arm so that it can grasp an object.

Motion-planning tasks for a mobile robot and a robot arm
Two examples of the problem.

Some people prefer to call the first case path planning. Once we get to configuration space—assuming this article gets that far—we will see that the two are the same kind of problem, expressed in different planning spaces: one in three-dimensional Euclidean space, the other on a higher-dimensional manifold.

This is going to be a long article, so here is the video first: a collection of motion-planning demonstrations with several of the robot arms in our lab. If you would rather skip the text, start there.

Watch the video in the original article ↗

A comic crowd asking what could be difficult about picking up a bottle

You might be wondering: “All that just to pick up a bottle of water? What is so difficult? Robots in films can do much more.”

Yes, it is 2016 and there is a quantum satellite in orbit, yet we still struggle to get a robot to fetch a bottle. Most industrial robots still work by repeating motions that a person has taught them, point by point. Service robots remain largely confined to laboratories.

One main reason robot-arm motion planning is hard is the high dimensionality of the problem, which we will come back to. We do not yet have a planning algorithm that gives us both real-time performance and optimality across these problems.

The comic crowd reacting to the difficulty of motion planning

Why study it?

If we want robots to fetch bottles, cook, or tidy a room, they need to generate collision-free, optimal motions quickly. Industry has some more specific reasons to care as well.

A diagram showing the flexibility gap between industrial applications and robotics research
The gap between industrial robotics and robotics research.

I think I first saw a diagram like this in some ROS-Industrial material. I could not find it again, so I sketched it from memory.

Industrial robots in 2016 are generally not very flexible. They rely heavily on manual teaching and have difficulty accommodating changes in orders. Academic research, meanwhile, concentrates on much more flexible applications. A substantial gap lies between the two.

Industrial robots on an automotive production line
An automotive production line.

Industrial robots are used extensively in automotive manufacturing. A car model may stay in production for several years, and the profit per vehicle is substantial enough that spending time teaching the robots at the outset is acceptable.

But robot manufacturers also want to enter the “3C” industries: computers, communications, and consumer electronics. Phones change much more frequently than car models, and the return on an individual product is much smaller. Production lines have to adapt quickly. Traditional point-by-point teaching becomes a poor fit.

For all their maturity and successful applications, industrial robots have several weaknesses: teaching takes time and effort; changing environments are difficult; changing a production line is expensive; and the tasks they handle tend to be relatively simple. Rapid product turnover in 3C manufacturing, together with rising labor costs, creates a demand for more flexible robots.

Imagine programming at the task level—“pick up A and place it at B”—instead of teaching a sequence like “A → point 001 → point 002 → open gripper → point 200 → … → close gripper → … → point 666 → B → open gripper.” That would be quite a change.

This was also the point of my earlier Zhihu answer about Mujin and its algorithms: motion planning makes higher-level task programming possible without the laborious manual teaching process.

Starting with two-dimensional planning

This section draws on the University of Pennsylvania’s Coursera course Robotics: Computational Motion Planning, the books Planning Algorithms and Principles of Robot Motion: Theory, Algorithms, and Implementations, and my dissertation proposal from the previous year.

Two common criteria for evaluating a planner are:

  • Completeness: the algorithm solves every problem that has a solution, in finite time.
  • Optimality: the algorithm finds an optimal path—for example, the shortest path or the one requiring the least energy.

Start with a game

Motion-planning algorithms are used far beyond robotics. Video games are another major application.

Screenshot of Command & Conquer: Red Alert 2—Yuri’s Revenge
Command & Conquer: Red Alert 2—Yuri’s Revenge. My choice of example probably gives away my age.

In a real-time strategy game such as Red Alert, we normally just select a destination. A unit finds its way around obstacles and goes there. Motion planning is what makes that possible.

To keep things simple, let us first treat the robot—or game character—as a point with zero size.

Walk To

The simplest “algorithm” is Walk To: move directly from the current position toward the goal until you arrive.

Walk To moving straight from the start to the goal
The Walk To algorithm.

Some RPGs, such as The Legend of Mir—another clue to my age—use this simple approach, with mouse clicks specifying the character’s direction of travel.

Screenshot of The Legend of Mir
The Legend of Mir.

The resulting path is the shortest one, so it is optimal, but the method cannot handle an obstacle in the way. It is incomplete and leaves obstacle avoidance to the player.

Bug algorithms

Bug algorithms add a way of dealing with simple obstacles:

  1. Move along the line M joining the start and the goal.
  2. On meeting an obstacle, follow its boundary clockwise or counterclockwise until returning to M.
A Bug algorithm following an obstacle boundary before returning to the goal line
A Bug algorithm.

This is the familiar idea of following a boundary through a two-dimensional maze. The algorithm is complete in two dimensions, but its path is not guaranteed to be optimal.

Ant colony optimization

Ant colony optimization is, as the name suggests, an optimization method, but it can be applied directly to path planning. The method is complete and optimal, though slow convergence has limited its use.

Ant colony optimization with pheromone accumulation on alternative routes
Ant colony optimization; source credited in the image.

Artificial potential fields

A potential field describes an energy distribution. Gravity is a familiar example: an object at a different height has different potential energy, and a ball on a slope naturally rolls downhill.

An artificial potential field borrows this idea. Define a potential whose lowest point is the goal, with higher potential farther away. Add repulsive potentials around obstacles, with the highest values at the obstacles themselves, to discourage collisions.

Artificial potential fields around obstacles and a goal
An artificial potential field. Source: Coursera.
A ball moving over an artificial potential surface

Potential fields are intuitive, computationally inexpensive, and can be integrated with a robot’s controller. Senior students in our lab used them in middle-size-league robot soccer.

The difficulty is local minima: the robot can become stuck somewhere other than the goal. The method is therefore incomplete and not optimal.

Graph search

Another large family of methods first turns the motion-planning problem into a graph, then uses a graph-search algorithm to solve it.

A graph consists of discrete vertices—also called nodes or points—and the edges that connect them. It describes the connectivity of a structure.

Route and graph representations of the postman problem
The postman problem is one familiar problem that can be expressed using a graph.

Graph theory gives us many ways to find shortest paths. Two particularly familiar algorithms in planning are Dijkstra’s algorithm and A*.

Pseudocode for Dijkstra’s algorithm and A*
Pseudocode for Dijkstra’s algorithm and A*.

The pseudocode is enough to implement both. The animation below is my own demonstration. A* adds a heuristic that guides the search, so in many cases it finds a path substantially faster than Dijkstra’s algorithm.

Dijkstra and A* searching the same obstacle map
My comparison of Dijkstra’s algorithm and A*.

To use either algorithm for motion planning, we still need a way to turn the planning space into a graph.

Visibility graphs

Represent obstacles as closed polygons. Connect their vertices, discarding any connection that intersects an obstacle. Connect the start and goal to the vertices in the same way, again removing connections that cross obstacles. The result is a graph.

A visibility graph connecting polygon vertices
A visibility graph.

The name suggests a useful mental picture: stand at a vertex and connect it to every other vertex you can see without an obstacle in the way. This method can be shown to be complete and optimal.

Grid discretization

Discretization is even more direct. Divide the space into cells of a chosen size and mark any cell containing an obstacle as impassable. Connect neighboring cells using four- or eight-way connectivity, and you have a graph.

If the cells are too large, a passage may disappear. This makes the method resolution-complete and optimal.

Discretizing a continuous obstacle map into grid cells
Turning a continuous space into a grid.

This approach is common in real-time strategy games. I do not know whether the original Red Alert used it, but the open-source implementation OpenRA uses grid discretization with A*. Its source code is available on GitHub.

Screenshot of the open-source real-time strategy game OpenRA
OpenRA. Source credited in the image.

Probabilistic roadmaps: PRM

A probabilistic roadmap samples N points in the planning space, connects points, and removes connections that collide with obstacles. The result is a randomly constructed roadmap.

With too few samples, or a poor distribution of samples, it is incomplete. As the sample count increases, completeness can be approached. PRM is therefore probabilistically complete, but not optimal.

Sampling and connecting a probabilistic roadmap between obstacles
Building a probabilistic roadmap.

There are many other ways to construct a search graph, including Voronoi diagrams and cell decomposition.

Rapidly exploring random trees: RRT

Alongside graph-search approaches, another major family grows a tree. The best-known example is RRT.

Starting at the initial configuration, RRT extends a tree outward. Random samples in the planning space determine the directions in which it grows. Like PRM, it is probabilistically complete, but not optimal.

An RRT expanding around obstacles
Growing an RRT.

Configuration space: from mobile robots to arms

Robot arms differ from our planar examples in two main ways: they use a different planning space, and they usually have more degrees of freedom.

So far, we have treated the robot as a point. To plan for an arm, we need a way to represent its whole configuration with a single point. This is the idea of configuration space, or C-space.

Even a mobile robot has a physical size, so it cannot simply be treated as a point in the original map. One intuitive solution is to shrink the robot to a point and inflate the obstacles accordingly. This construction uses the Minkowski sum.

Representing a planar robot as a point by inflating obstacles
Configuration space for a planar mobile robot.

A robot arm is less straightforward. Its generalized coordinates—usually its joint angles—let us describe its configuration as a point. A six-degree-of-freedom arm, for example, can be represented by a vector (θ₁, θ₂, θ₃, θ₄, θ₅, θ₆).

Representing the obstacles is harder. Multiple inverse-kinematics solutions and singularities complicate the nonlinear relationship between workspace and configuration space. There is no convenient general method for directly mapping workspace obstacles into C-space. A usual approach is to discretize C-space and test each cell for collisions.

A two-joint arm and its configuration-space obstacles
The configuration space of a two-joint arm.

The picture above flattens that space onto a plane. A revolute joint wraps around: 0 and 2π represent the same angle. The configuration space is therefore more like a torus than a flat rectangle.

A toroidal configuration space formed by two periodic joint angles
A torus representation of the two-joint configuration space.

The torus itself has only two degrees of freedom, even though it is embedded in three-dimensional space. If you have read The Three-Body Problem, think of the flattened Solar System still sitting within a three-dimensional universe. Beyond three degrees of freedom, we cannot draw the arm’s configuration space directly.

This change in topology raises a question: do the planning algorithms we used before still work in C-space? My impression is that this receives fewer mathematical proofs of completeness in robotics than one might expect. Partly, not everyone building robots specializes in advanced mathematics. Partly, the configuration spaces of many familiar mechanisms—continuous revolute joints and prismatic joints, for example—are differentiable manifolds, locally resembling Euclidean space, so many of the algorithms remain usable.

An animated mechanism with a non-manifold configuration-space example
The configuration space of a mechanism like this is not a differentiable manifold.

For a two-joint arm, most of the methods above can be applied directly:

Obstacle-avoiding motions of a two-joint arm using a Bug algorithm
A Bug algorithm applied to a two-joint arm. Source credited in the image.
A two-joint arm and Dijkstra search in configuration space
Dijkstra’s algorithm applied to a two-joint arm. Source: Coursera.

What changes in higher dimensions?

Higher dimensions bring two problems: the computational burden grows, and explicitly describing the obstacles becomes difficult. To decide whether a planner is useful for a robot arm, we need to ask how it handles both.

Walk To. It works in any dimension, in the limited sense that it moves directly toward the goal. It still has no way to handle obstacles. We barely count it as a planning algorithm.

Bug algorithms. They depend on following an obstacle clockwise or counterclockwise. Those directions do not have the same meaning in higher dimensions, so the method does not carry over directly.

Ant colony optimization. Convergence is still slow, and it is not widely used here.

Artificial potential fields. The classical construction requires a potential in C-space, which in turn depends on knowing how obstacles occupy that space. That prevents it from being applied directly to a high-dimensional arm in the same way.

Researchers have found workarounds. For example, put several control points on the arm and define a potential in the workspace. Apply the corresponding force at each control point, then use the relationship between force and the Jacobian—derivable through virtual work—to convert those forces into joint torques. Those joint torques act as the potential-field forces in configuration space.

Potential-field forces on fixed and floating control points of a robot arm
A control-point potential-field method, from my paper “Hand-eye coordinative remote maintenance in a tokamak vessel.”

Khatib is a leading figure in artificial potential fields and has applied them to motion planning for humanoid robots.

An arm-planning animation using potential fields from Khatib’s lectures
Potential-field robot planning. Source: Khatib’s lecture materials.

For arms with many degrees of freedom, potential fields offer good real-time performance and integrate well with control. But they remain neither complete nor optimal, so failure to find a solution is still possible.

Visibility graphs. Like Bug algorithms, this method requires an explicit description of the obstacles in C-space. It therefore cannot be used in high-dimensional space in this form.

Grid discretization. In principle, this applies in any dimension. The problem is the number of cells. Consider a six-degree-of-freedom arm with a grid spacing of 6°—already a coarse resolution. That produces 60⁶ = 4.67 × 10¹⁰ cells. At 0.1 ms per collision test, checking every cell alone would take 1,296 hours. The planning computation also grows exponentially with dimension. For planning problems above three degrees of freedom, this approach generally loses its practical value.

PRM and RRT. Neither requires an explicit map of how obstacles fill C-space. Instead, they use a collision-checking function to test sampled configurations. I am being called to dinner, so I will jump to the conclusion: both work in high-dimensional spaces, both are probabilistically complete rather than optimal, and both can plan very quickly.

A laboratory robot arm executing an RRT-planned motion
A robot arm planned with RRT.

Their speed comes with a serious drawback: the randomness introduced by sampling. With RRT or PRM, the user cannot predict the resulting motion, and each run may produce a different answer. As I see it in 2016, this is what keeps automatically planned robots out of industrial applications that demand extreme consistency.

Different RRT motions generated for the same planning task
Different RRT runs can produce different motions.

Much of the planning research I see therefore concerns improvements to PRM and RRT: reducing that uncertainty and, in some cases, adding optimization objectives. Examples include RRT*, Informed RRT*, and SBL.

This is only an introduction. I have left many questions untouched: how to sample uniformly, how to check for collisions, how to solve inverse kinematics quickly, and how to put all of this on a real robot. Those will have to wait for another article.

← Writing