This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Create controller to follow set of waypoints


The robotics.PurePursuit System object™ creates a controller object used to make a differential drive robot follow a set of waypoints. The object computes the linear and angular velocities for the robot given the current pose of the robot. Successive calls to the object with updated poses provide updated velocity commands for the robot. Use the MaxAngularVelocity and DesiredLinearVelocity properties to update the velocities based on the robot’s performance.

The LookaheadDistance property computes a look-ahead point on the path, which is a local goal for the robot. The angular velocity command is computed based on this point. Changing LookaheadDistance has a significant impact on the performance of the algorithm. A higher look-ahead distance results in a smoother trajectory for the robot, but can cause the robot to cut corners along the path. A low look-ahead distance can result in oscillations in tracking the path, causing unstable behavior. For more information on the pure pursuit algorithm, see Pure Pursuit Controller.


Starting in R2016b, instead of using the step method to perform the operation defined by the System object, you can call the object with arguments, as if it were a function. For example, y = step(obj,x) and y = obj(x) perform equivalent operations.

To compute linear and angular velocity control commands:

  1. Create the robotics.PurePursuit object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects? (MATLAB).



controller = robotics.PurePursuit
controller = robotics.PurePursuit(Name,Value)



controller = robotics.PurePursuit creates a pure pursuit object that uses the pure pursuit algorithm to compute the linear and angular velocity inputs for a differential drive robot.

controller = robotics.PurePursuit(Name,Value) creates a pure pursuit object with additional options specified by one or more Name,Value pairs. Name is the property name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name-value pair arguments in any order as Name1,Value1,...,NameN,ValueN. Properties not specified retain their default values.

Example: controller = robotics.PurePursuit('DesiredLinearVelocity', 0.5)


expand all

Desired constant linear velocity, specified as a scalar in meters per second. The controller assumes that the robot drives at a constant linear velocity and that the computed angular velocity is independent of the linear velocity.

Data Types: double

Look-ahead distance, specified as a scalar in meters. The look-ahead distance changes the response of the controller. A robot with a higher look-ahead distance produces smooth paths but takes larger turns at corners. A robot with a smaller look-ahead distance follows the path closely and takes sharp turns, but potentially creating oscillations in the path.

Data Types: double

Maximum angular velocity, specified a scalar in radians per second. The controller saturates the absolute angular velocity output at the given value.

Data Types: double

Waypoints, specified as an n-by-2 array of [x y] pairs, where n is the number of waypoints. You can generate the waypoints from the PRM class or from another source.

Data Types: double



[vel,angvel] = controller(pose)
[vel,angvel,lookaheadpoint] = controller(pose)



[vel,angvel] = controller(pose) processes the robot’s position and orientation, pose, and outputs the linear velocity, vel, and angular velocity, angvel.

[vel,angvel,lookaheadpoint] = controller(pose) returns the look-ahead point, which is a location on the path used to compute the velocity commands. This location on the path is computed using the LookaheadDistance property on the controller object.

Input Arguments

expand all

Position and orientation of robot, specified as a 3-by-1 vector in the form [x y theta]. The robot’s pose is an x and y position with angular orientation θ (in radians) measured from the x-axis.

Output Arguments

expand all

Linear velocity, specified as a scalar in meters per second.

Data Types: double

Angular velocity, specified as a scalar in radians per second.

Data Types: double

Look-ahead point on the path, returned as an [x y] vector. This value is calculated based on the LookaheadDistance property.

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:


expand all

infoCharacteristic information about PurePursuit object
stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object


expand all

Use the info method to get more information about a PurePursuit object. info returns two fields, RobotPose and LookaheadPoint, which correspond to the current position and orientation of the robot and the point on the path used to compute outputs from the last call of the object.

Create a PurePursuit object.

pp = robotics.PurePursuit;

Assign waypoints.

pp.Waypoints = [0 0;1 1];

Compute control commands using the pp object with the initial pose [x y theta] given as the input.

[v,w] = pp([0 0 0]);

Get additional information.

s = info(pp)
s = struct with fields:
         RobotPose: [0 0 0]
    LookaheadPoint: [0.7071 0.7071]

Extended Capabilities

Introduced in R2015a