Chapter 2

Open-Loop Control & Trajectory Optimization

In Chapter 1, we introduced the state space model as a mathematical formulation for representing a robot’s dynamics. These models, typically expressed as systems of differential equations, provide a foundational framework that describes how the state of a robot evolves over time in response to control inputs. In particular, we saw how a state space model can be derived from the robot’s kinematics and dynamics, providing a compact yet expressive description of its physical motion. In this chapter, we turn to a fundamental question: given a state space model of the robot, how can we determine the control inputs that will drive it to execute a desired behavior?

As we will see throughout Chapters Chapter 2-Chapter 4, robots must transform high-level goals into precise physical actions. This process is often described hierarchically, spanning decision-making, motion planning, trajectory optimization, and control (Figure 2.1). Each layer plays a distinct role, yet they remain deeply interconnected.

At the higher level of this hierarchy, decision-making governs what tasks the robot should perform to fulfill its objectives. It involves reasoning over goals, resources, and constraints, often under uncertainty. In a self-driving car, for example, this may correspond to deciding when to overtake, yield, or reroute. Because it involves strategic considerations rather than immediate actuation, decision-making typically unfolds on the order of seconds to minutes. Ultimately, decision-making defines the high-level objectives that guide subsequent layers of the hierarchy.

Refer to caption
Figure 2.1: A hierarchical view of the relationship between decision-making, motion planning, trajectory optimization, and control.

Once a high-level decision has been made, motion planning determines how to realize it in the robot’s physical environment. This is typically expressed in terms of the robot’s configuration space and involves finding a collision-free path that respects geometric and kinematic constraints. For instance, motion planning may compute a path for a mobile robot to navigate a cluttered warehouse without collisions. The timescale of motion planning is often on the order of hundreds of milliseconds to seconds.

Building on this path, trajectory optimization refines it into a time-parameterized trajectory that is dynamically feasible and optimized for performance criteria. This entails solving continuous optimization problems that incorporate dynamics, actuator limits, and objectives such as energy efficiency, comfort, or safety margins. The result is a trajectory specifying both the robot’s states and the control inputs needed to realize them over time, ensuring compatibility with the robot’s actuation capabilities and dynamic constraints. Trajectory optimization typically operates on shorter timescales, from tens to hundreds of milliseconds.

Finally, low-level control ensures that the robot faithfully executes the desired trajectory in the physical world, by converting the trajectory into actuation commands. Controllers must operate at high frequency, applying feedback to correct deviations caused by disturbances, modeling errors, or sensor noise. Whether adjusting wheel torques, joint forces, or thrust vectors, control is what closes the loop between higher-level plans and physical reality.

Together, these layers form the backbone of an autonomous system: decision-making provides strategic guidance, motion planning translates that guidance into feasible paths, trajectory optimization refines those paths into feasible and optimal trajectories, and control ensures that the robot can follow those trajectories in the real world. In practice, the boundaries between these layers are often blurred. Trajectory optimization, for instance, may be tightly integrated with planning or even embedded within control loops, while high-level decisions may be informed by the lower-level processes. For the purposes of this book, we will adopt the hierarchical perspective outlined above, while acknowledging that real-world systems frequently combine or intertwine these processes.

In this chapter, we focus on trajectory optimization as a fundamental tool for computing trajectories that are both feasible and optimal. While control and motion planning will be revisited in Chapter Chapter 3 and Chapter Chapter 4, respectively, our emphasis in this chapter is on the formulation and solution of the trajectory optimization problem. We begin in Section 2.1 by introducing the trajectory optimization problem and casting it as a continuous optimization problem. Building on this foundation, Sections 2.2 and Section 2.3 present two major classes of solution strategies—indirect methods, which derive optimality conditions for the continuous problem using tools from the calculus of variations, and direct methods, which discretize and numerically solve the problem as a finite-dimensional nonlinear program. Finally, in Section 2.4, we explore specialized techniques tailored to certain problem structures, known as differentially flat systems.

2.1 The Optimal Control Problem

Optimal control theory aims to determine control inputs that drive a dynamical system to satisfy its physical constraints while optimizing a performance criterion. At a high level, formulating an optimal control problem requires three key components:

  • A mathematical model of the system, typically expressed in state space form.

  • A description of the physical constraints the system must satisfy.

  • A specification of the performance criterion to be optimized.

Mathematical model.

As discussed extensively in Chapter 1, the purpose of a mathematical model is to describe how the system’s state evolves over time in response to control inputs. Using the notation from Chapter 1, the system dynamics can be expressed as a set of ordinary differential equations:

𝒙˙(t)=f(𝒙(t),𝒖(t)), (2.1)

where 𝒙(t)n is the state of the system at time t, 𝒖(t)m is the control input, and f:n×mn defines the state evolution over time. Throughout this book, we will often refer to 𝒙(t) and 𝒖(t) as the state and control sequences, respectively, or equivalently as the state and control trajectories.

Physical constraints.

Once we define the system dynamics, the next step is to specify the physical constraints that the system must satisfy. These constraints can take several forms, including:

  • Initial conditions, which specify the state at the initial time t0 as 𝒙(t0)=𝒙0.

  • Final conditions, which specify the state at the final time tf as 𝒙(tf)=𝒙f or 𝒙(tf)𝒳f, where 𝒳f denotes a set of allowable terminal states.

  • State constraints, which require that the state remains within an allowable set 𝒳 for all times t[t0,tf], that is, 𝒙(t)𝒳.

  • Control constraints, which enforce that the control input remains within an allowable set 𝒰 for all times t[t0,tf], that is, 𝒖(t)𝒰.

Depending on whether the constraints are satisfied or not, we can define the concept of admissibility for a control history and state trajectory.

Definition 2.1 (Admissible State and Control Sequences).

A state trajectory 𝒙(t) and a control sequence 𝒖(t) are admissible if they satisfy the state and control constraints at all times, that is:

𝒙(t)𝒳and𝒖(t)𝒰,t[t0,tf].

Admissibility is a key concept in optimal control, as it restricts the set of realizable trajectoriesmargin: In practice, this allows numerical methods to focus exclusively on admissible state and control sequences, rather than considering all possible solutions. .

Performance criterion.

The final component of an optimal control problem is the performance criterion to be optimized. An optimal control is defined as one that minimizes (or maximizes) this performance criterion. In some cases, the performance criterion may be implicitly defined by the problem statement (e.g., minimizing the time to reach a goal state), whereas in other cases, it must be explicitly designed (e.g., driving a car in a way that is comfortable for the passengers).

Throughout this book, we will focus on performance criteria that can be expressed as a cost functionalmargin: A functional maps functions to real numbers; intuitively, we might say that a functional is a “function over functions”. Here, the cost functional maps a state trajectory and control sequence to a real number representing the overall cost. of the form:

J(𝒙(t),𝒖(t),t)=h(𝒙(tf),tf)+t0tfg(𝒙(t),𝒖(t),t)𝑑t, (2.2)

where h:n× is the terminal cost and g:n×m× is the running cost. The terminal cost h is evaluated at the final time tf and typically represents a cost associated with the state of the system at that time, such as a penalty for being far from a desired goal state. The running cost g is integrated over the time interval [t0,tf] and represents the instantaneous cost incurred by the system at each time step, for example, the cost of energy consumption, or any other cost associated with the system’s operation. Depending on the problem, the final time tf may be finite and fixed, finite and free, or infinitemargin: In the case of an infinite final time, the terminal cost h is typically ignored and set to zero. .

2.1.1 Problem Formulation

As a result, an optimal control problem can be formulated as follows:

Determine an admissible control sequence 𝒖(t) such that the system dynamics:

𝒙˙(t)=f(𝒙(t),𝒖(t),t),

generate a corresponding admissible state trajectory 𝒙(t) that minimizes the performance criterion:

J(𝒙(t),𝒖(t),t)=h(𝒙(tf),tf)+t0tfg(𝒙(t),𝒖(t),t)𝑑t,

where 𝒖(t) and 𝒙(t) are referred to as the optimal control sequence and optimal state trajectory, respectively.

This problem can be formally posed as the following optimization problem:

minimize𝒖(t) J(𝒙(t),𝒖(t),t), (2.3)
subject to 𝒙˙(t)=f(𝒙(t),𝒖(t),t),
𝒙(t0)=𝒙0,𝒙(tf)=𝒙f,
𝒖(t)𝒰,𝒙(t)𝒳,t0<t<tf.

This general formulation serves as the starting point for the optimal control methods developed in the remainder of this book. There are also several important attributes related to the solution of this problem that are worth highlighting:

  1. 1.

    Existence: A solution to an optimal control problem is not guaranteed to exist; there may be no control history that is both admissible and optimal.

  2. 2.

    Uniqueness: Even when a solution exists, it may not be unique. Multiple admissible control inputs can yield the same performance. While this can pose challenges for numerical algorithms, it also provides flexibility in selecting among equally good solutions depending on the application.

  3. 3.

    Optimality: The objective of optimal control is to find a control sequence that outperforms all other admissible candidates. Thus, optimal control is interested in global optimality, as opposed to local optimality.

Example 2.1.1 (Autonomous Racing Optimal Control).

Consider an autonomous racing scenario in which the goal is to complete a lap of a known course in the shortest possible time. We can formulate this as a finite-horizon optimal control problem, where the objective is to minimize the final time tf required to reach a designated goal position (xgoal,ygoal), subject to the constraint that the vehicle must remain on the track at all times. Let 𝒳𝕔𝕠𝕦𝕣𝕤𝕖 denote the set of admissible states that correspond to positions on the course.

Suppose the vehicle is modeled using the simple kinematic car model from Equation 1.29, with state 𝒙=[x,y,θ] representing position and heading, and control inputs 𝒖=[v,ϕ] representing forward speed and steering angle, respectively. The resulting optimal control problem is:

minimizev(t),ϕ(t) tf,
subject to x˙=vcosθ,y˙=vsinθ,θ˙=vLtanϕ,
𝒙𝒳course,𝒖𝒰,
𝒙(t0)=𝒙0,(x(tf),y(tf))=(xgoal,ygoal).

In this formulation, the cost depends only on the final time and not directly on the state or control at intermediate points. As a result, the time-optimal solution (𝒙(t),𝒖(t)) will lie on the boundaries of the admissible control and state sets. In practice, this means the vehicle will operate at full throttle and steer at the physical limits to cut the lap time, a strategy that achieves optimality mathematically—but may not make for a smooth or comfortable ride.

Throughout this book, we will see that the solution to the optimal control problem can take different forms, depending on whether and how it incorporates feedback from the current state of the system. At the most fundamental level, we distinguish between open-loop and closed-loop control. While closed-loop control will be the focus of Chapter 3, this chapter addresses open-loop control.

Open-loop control.

If the optimal control is computed purely as a function of time for a given initial state,

𝒖(t)=(𝒙(t0),t), (2.4)

it is said to be in open-loop form. In the context of trajectory optimization, restricting the focus to open-loop strategies is natural, as they balance computational efficiency—computing open-loop sequences is faster than computing closed-loop policies—with effectiveness, since robustness can be endowed through closed-loop tracking or by re-optimizing the trajectory in a receding-horizon fashion, as in Model Predictive Controlmargin: Discussed further in Chapter 3. .

Having introduced the optimal control problem, we now turn to methods for computing optimal open-loop solutions. Fundamentally, Problem (Equation 2.3) is an infinite-dimensional optimization problem, where the optimization variables are functions of time. In practice, solution methods must rely on discretization strategies, thereby approximating the infinite-dimensional problem with a finite-dimensional one. Different discretization approaches give rise to distinct families of methods.

Broadly speaking, two main classes of methods exist: indirect methods and direct methods. Indirect methods follow an “optimize-then-discretize” paradigm: they first derive necessary conditions for optimality—typically in the form of boundary-value problems involving adjoint variables—and then apply numerical techniques to solve these conditions. In contrast, direct methods take a “discretize-then-optimize” approach: the state and control sequences are parameterized using finite-dimensional representations, and the resulting finite-dimensional optimization problem is solved numerically.

Beyond these two general classes, some systems admit further structural simplifications. In particular, differentially flat systems allow trajectories to be described in terms of a small set of variables that fully capture the system’s evolutionmargin: These variables are commonly known as flat outputs. . This property enables efficient trajectory generation and optimization, making these systems especially relevant in mobile robotics and aerospace applications.

The remainder of this chapter examines these three classes of methods in detail: indirect methods in Section 2.2, direct methods in Section 2.3, and trajectory optimization for differentially flat systems in Section 2.4.

2.2 Indirect Methods

Indirect methods provide a principled framework for solving optimal control problems by drawing on ideas from calculus of variations (CoV)margin: Calculus of variations extends the principles of classical calculus from functions to functionals. The central idea is to study how small perturbations—called variations—of a candidate function influence the value of the functional. By analyzing the first- and higher-order effects of these variations, one can derive necessary conditions for optimality. . For a comprehensive treatment of the calculus of variations and its applications in optimal control theory, we refer the reader to Kirk (2004)11. Kirk, D. E. Optimal Control Theory: An Introduction. Dover Publications, 2004.. At their core, indirect methods rely on the derivation of necessary optimality conditions (NOCs) that any solution must satisfy and then leverage numerical techniques to compute solutions consistent with these conditions. In this way, the NOCs serve as the bridge between the continuous-time formulation of an optimal control problem and its numerical resolution.

Before turning to the derivation of such conditions for infinite-dimensional optimization problems, let us first review key concepts from finite-dimensional optimization, which will serve as a foundation for the discussion ahead.

2.2.1 NOCs for Unconstrained Nonlinear Optimization Problems

Consider the following finite-dimensional optimization problem:

minimize[𝒙n]f(𝒙), (2.5)

where f:n is assumed continuously differentiable, i.e., fC1. We wish to identify the NOCs that any minimizer—local or global—must satisfy.

The key intuition is that at a local minimizer, no infinitesimal perturbation of the decision variable should decrease the objective. Formally, this requires analyzing how f changes under small variations around a candidate minimizer 𝒙.

First-order necessary condition.

Let 𝒙n be a local minimizer. If fC1, we can use gradients and Taylor series expansions to characterize the behavior of f near 𝒙. For a small perturbation Δx, the cost variation is, up to first order:

f(𝒙+Δx)f(𝒙)f(𝒙)Δx.

If 𝒙 is a local minimizer, then for sufficiently small Δx, the first-order term must be non-negativemargin: This is because, if we were to decrease the cost by perturbing 𝒙 by Δx, then 𝒙 would not be a local minimizer. :

f(𝒙)Δx=i=1nf(𝒙)xiΔxi0.

In particular, by taking Δ𝒙 to be positive and negative multiples of the coordinate unit vectors, that is, vectors having all components equal to zero except for one component equal to one, we obtain simultaneously:

f(𝒙)xi0andf(𝒙)xi0,i=1,,n,

which forces the condition:

f(𝒙)xi=0,i=1,,n,

or, more compactly:

f(𝒙)=0.

Thus, any local minimizer 𝒙 must be a stationary point of f.

Second-order necessary condition.

Assuming fC2, consider again the Taylor expansion of f around a local minimizer 𝒙, this time up to second order:

f(𝒙+Δx)f(𝒙)f(𝒙)Δx+12Δx2f(𝒙)Δx.

For 𝒙 to be a local minimizer, the second-order variation must be nonnegative for all sufficiently small Δ𝒙, that is:

f(𝒙)Δx+12Δx2f(𝒙)Δx0.

Using the first-order condition f(𝒙)=0, the linear term vanishes, leaving:

Δx2f(𝒙)Δx0.

Thus, the Hessian 2f(𝒙) must be positive semidefinite at any local minimizer.

Theorem 2.1 (Necessary Conditions for Unconstrained Local Minimizers).

Let 𝐱 be a local minimizer of f:n. If fC1 in an open set containing 𝐱, then:

f(𝒙)=0(first-order NOC). (2.6)

If, in addition, fC2, then:

2f(𝒙)0(second-order NOC). (2.7)

2.2.2 NOCs for Constrained Nonlinear Optimization Problems

Having introduced the NOCs for unconstrained problems, this section extends the discussion to optimization problems subject to constraints. The definition of optimality conditions in the constrained setting requires the introduction of auxiliary variables, known as Lagrange multipliers. These variables are associated with the constraints and facilitate the characterization of optimal solutions while providing insights into the sensitivity of the optimal cost with respect to perturbations in the constraints. In this section, we limit our discussion on the theory of Lagrange multipliers to the case of equality constrained optimization. For a comprehensive treatment of optimality conditions in finite-dimensional optimization, the reader is referred to Bertsekas (2016)22. Bertsekas, D. Nonlinear Programming. Athena Scientific, 2016..

Consider the following constrained optimization problem:

minimize[𝒙n] f(𝒙), (2.8)
subject to hi(𝒙)=0,i=1,,m,

where f:n and hi:n are continuously differentiable.

For compactness, define the constraint function h:nm as:

h(𝒙)=(h1(𝒙),,hm(𝒙)), (2.9)

so that the constraints can be written simply as h(𝒙)=0.

The Lagrange multiplier theorem for equality-constrained optimization states that, if 𝒙 is a local minimizer, then there exist scalars λ1,,λm, called Lagrange multipliers, such that:

f(𝒙)+i=1mλihi(𝒙)=0. (2.10)

To interpret this condition, observe that the cost gradient f(𝒙) must be orthogonal to the subspace of first-order feasible variations:

V(𝒙){Δ𝒙|hi(𝒙)Δ𝒙=0,i=1,,m}.

This subspace consists of all variations Δ𝒙 that preserve feasibility to first order margin: That is, variations for which 𝒙=𝒙+Δ𝒙 satisfies h(𝒙)=0 to first order. . Thus, condition (Equation 2.10) ensures that the first-order cost variation f(𝒙)Δ𝒙=0 for all Δ𝒙V(𝒙). This statement is analogous to the f(𝒙)=0 condition of unconstrained optimization.

Formally, the necessary conditions for equality constrained optimality are summarized as follows:

Theorem 2.2 (Lagrange Multiplier Theorem — Necessary Conditions for Equality Constrained Local Minimizers).

Let 𝐱 be a local minimizer of f:n subject to the equality constraints hi(𝐱)=0, i=1,,m, and assume the constraint gradients h1(𝐱),,hm(𝐱) are linearly independent. Then there exists a unique vector [λ1,,λm], called the Lagrange multiplier vector, such that:

f(𝒙)+i=1mλihi(𝒙)=0. (2.11)

It is often convenient to express these conditions using the Lagrangian function L:n+m defined as:

L(𝒙,𝝀)f(𝒙)+i=1mλihi(𝒙). (2.12)

The first-order NOCs for a local minimum 𝒙 then take the compact form:

𝒙L(𝒙,𝝀)=0,𝝀L(𝒙,𝝀)=0, (2.13)

where 𝒙L and 𝝀L denote the gradients with respect to 𝒙 and 𝝀, respectively, and where the system in (Equation 2.13) consists of n+m equations in n+m unknowns—namely, the n components of 𝒙 and the m components of 𝝀.

In practice, optimality conditions serve as a powerful tool to filter candidate solutions for global or local minima and often form the foundation of numerical optimization algorithms. For instance, in the unconstrained case of Problem (Equation 2.5), one might (i) find all stationary points by solving f(𝒙)=0, and (ii) apply the second-order test by checking 2f(𝒙)0 at each candidate. This same philosophy extends naturally to infinite-dimensional optimal control problems, where any candidate solution must satisfy the corresponding NOCs. However, as we move to infinite-dimensional problems, the nature of the NOCs changes significantly: rather than yielding algebraic equations as in the finite-dimensional case, the NOCs for optimal control take the form of differential equations.

2.2.3 Pontryagin’s Minimum Principle

Extending the concept of necessary optimality conditions to infinite-dimensional problems leads to Pontryagin’s Minimum Principle (PMP), a cornerstone of optimal control theory. Specifically, the PMP generalizes the finite-dimensional NOCs to the infinite-dimensional setting.

Consider the problem of finding an admissible control 𝒖(t)𝒰 that drives the system:

𝒙˙(t)=f(𝒙(t),𝒖(t),t), (2.14)

along a trajectory that minimizes the cost functional:

J(𝒙(t),𝒖(t),t)=h(𝒙(tf),tf)+t0tfg(𝒙(t),𝒖(t),t)𝑑t.

To derive the NOCs, we define the Hamiltonian, the analog of the Lagrangian in finite-dimensional optimization:

H(𝒙(t),𝒖(t),𝒑(t),t)g(𝒙(t),𝒖(t),t)+𝒑(t)f(𝒙(t),𝒖(t),t), (2.15)

where 𝒑(t)n is the costatemargin: The term costate highlights that there is one costate associated with each state variable, analogous to Lagrange multipliers in finite-dimensional optimization. vector.

Similarly to the finite-dimensional case, where necessary conditions for optimality are derived by considering the cost increment Δf=f(𝒙+Δ𝒙)f(𝒙) in response to a perturbation Δ𝒙, here we analyze the increment ΔJ under variations around a candidate function.

Theorem 2.3 (Pontryagin’s Minimum Principle; for a comprehensive treatment, we refer the reader to Chapter 5 in Kirk (2004)33. Kirk, D. E. Optimal Control Theory: An Introduction. Dover Publications, 2004.).

Let 𝐮(t) be an optimal control with associated state trajectory 𝐱(t) for the system in (Equation 2.14) over [t0,tf]. Then there exists a costate vector 𝐩(t) such that, for all t[t0,tf], the following conditions hold:

𝒙˙(t)=H𝒑(𝒙(t),𝒖(t),𝒑(t),t),𝒑˙(t)=H𝒙(𝒙(t),𝒖(t),𝒑(t),t),𝒖(t)=argmin𝒖𝒰H(𝒙(t),𝒖,𝒑(t),t), (2.16)

along with the boundary conditions:

[h𝒙(𝒙(tf),tf)𝒑(tf)]δ𝒙f (2.17)
+[H(𝒙(tf),𝒖(tf),𝒑(tf),tf)+ht(𝒙(tf),tf)]δtf=0,

where δ𝐱f and δtf denote the variations of the final state and time, respectively margin: As we will discuss in the remainder of this section, the boundary conditions in Equation Kirk (2004)44. Kirk, D. E. Optimal Control Theory: An Introduction. Dover Publications, 2004.). ‣ 2.2.3 Pontryagin’s Minimum Principle ‣ 2.2 Indirect Methods" class="ltx_ref">2.17 depend on whether the final state and time are fixed (i.e., δ𝐱f=0 or δtf=0) or free (i.e., δ𝐱f or δtf are arbitrary). .

Equations (Equation Kirk (2004)55. Kirk, D. E. Optimal Control Theory: An Introduction. Dover Publications, 2004.). ‣ 2.2.3 Pontryagin’s Minimum Principle ‣ 2.2 Indirect Methods" class="ltx_ref">2.16) constitute the necessary conditions for optimality. They form a system of 2n first-order differential equations—n for the state and n for the costate—together with m algebraic equations defining the control input. Solving these equations produces 2n constants of integration. Half of these constants are determined by the initial conditions 𝒙(t0)=𝒙0. The remaining n (or n+1, if the final time is free) are specified by the boundary conditions in Equation Kirk (2004)66. Kirk, D. E. Optimal Control Theory: An Introduction. Dover Publications, 2004.). ‣ 2.2.3 Pontryagin’s Minimum Principle ‣ 2.2 Indirect Methods" class="ltx_ref">2.17. This results in a two-point boundary value problem, which may be solved analytically in special cases, or numerically using methods such as shooting or collocation2626. Hertling, J. “Numerical Methods for Two-Point Boundary Value Problems (Herbert B. Keller).” SIAM Review 12(2), 313-315, 1970..

In practice, once the initial state is fixed, the boundary conditions are obtained by substituting the appropriate assumptions into Equation Kirk (2004)77. Kirk, D. E. Optimal Control Theory: An Introduction. Dover Publications, 2004.). ‣ 2.2.3 Pontryagin’s Minimum Principle ‣ 2.2 Indirect Methods" class="ltx_ref">2.17. Common cases include:

Fixed final time and fixed final state.

If both tf and 𝒙(tf) are fixed, then δtf=0 and δ𝒙f=0, leaving the sole boundary condition:

𝒙(tf)=𝒙f.

Fixed final time and free final state.

If tf is fixed but 𝒙(tf) is free, then δtf=0 while δ𝒙f is arbitrary. Hence, the boundary condition is:

h𝒙(𝒙(tf),tf)𝒑(tf)=0.

Free final time and fixed final state.

If 𝒙(tf) is fixed but tf is free, then δ𝒙f=0 while δtf is arbitrary. Thus, the boundary condition is:

H(𝒙(tf),𝒖(tf),𝒑(tf),tf)+ht(𝒙(tf),tf)=0.

Free final time and free final state.

If both 𝒙(tf) and tf are free, then δ𝒙f and δtf are arbitrary, and both coefficients in Equation Kirk (2004)88. Kirk, D. E. Optimal Control Theory: An Introduction. Dover Publications, 2004.). ‣ 2.2.3 Pontryagin’s Minimum Principle ‣ 2.2 Indirect Methods" class="ltx_ref">2.17 must be set to zero. That is:

h𝒙(𝒙(tf),tf)𝒑(tf)=0,(n equations)H(𝒙(tf),𝒖(tf),𝒑(tf),tf)+ht(𝒙(tf),tf)=0,(1 equation).

While these four cases cover many problems of practical interest, more general boundary conditions can be found in Kirk (2004)99. Kirk, D. E. Optimal Control Theory: An Introduction. Dover Publications, 2004..

2.2.4 Solving a Two-Point Boundary Value Problem

Finding solutions that satisfy the necessary optimality conditions in Equation Kirk (2004)1010. Kirk, D. E. Optimal Control Theory: An Introduction. Dover Publications, 2004.). ‣ 2.2.3 Pontryagin’s Minimum Principle ‣ 2.2 Indirect Methods" class="ltx_ref">2.16 is a nontrivial task, as these must simultaneously satisfy a system of 2n differential equations together with boundary conditions imposed at both t0 and tf. This type of problem, where conditions are specified at two distinct points in time, is known as a two-point boundary value problem (TPBVP).

Over the years, a number of numerical procedures have been developed for solving TPBVPs. Two broad classes of approaches are commonly used:

  • Shooting methods, which reformulate the TPBVP as an initial value problem by guessing the unknown boundary conditions (e.g., the initial costate), simulating the system forward, and then iteratively adjusting the guess until the terminal boundary conditions are satisfied. Although conceptually straightforward, shooting methods may suffer from numerical instability, especially for long time horizons.

  • Collocation methods, whereby the solution is approximated by a parametric function with unknown parameters at a set of discrete points (called collocation points). These methods turn the TPBVP into a large system of nonlinear algebraic equations that can be solved using computational techniques. Collocation methods are robust and widely used in practice because they avoid the instability issues of shooting methods.

Modern scientific computing environments provide high-level implementations of these ideas. For example, the scikits.bvp_solver package in Python or the function bvp4c in MATLAB implement numerical algorithms for solving TPBVPs with relatively little effort from the user.

Most solvers assume that the system of necessary conditions in Equation Kirk (2004)1111. Kirk, D. E. Optimal Control Theory: An Introduction. Dover Publications, 2004.). ‣ 2.2.3 Pontryagin’s Minimum Principle ‣ 2.2 Indirect Methods" class="ltx_ref">2.16, along with its boundary conditions, can be expressed in the standard form:

𝒛˙=g(𝒛,t),l(𝒛(t0),𝒛(tf))=0, (2.18)

where 𝒛(t) collects the unknown functions (such as states and costates), g encodes their dynamics, and l encodes the two-point boundary constraints.

To illustrate how TPBVPs can be solved in practice, consider the toy dynamics:

𝒛˙(t)=[z˙1(t)z˙2(t)]=[z2(t)z1(t)],

with boundary conditions z1(t0)=0 and z1(tf)=2. The boundary conditions can equivalently be expressed in standard form as:

l(𝒛(t0),𝒛(tf))=[z1(t0)z1(tf)+2]=0.

In Python, the system dynamics g(𝒛,t) and boundary conditions l(𝒛(t0),𝒛(tf)) can be passed directly to solve_bvp as shown in Algorithm 2.1.

Many optimal control problems can, in fact, be cast into the standard TPBVP form in Equation 2.18 and solved directly with off-the-shelf BVP solvers such as solve_bvp, sometimes after simple reformulations. Common cases include problems with conditions at special points, such as free-end problems, switching points, interface points, or discontinuities. Example How (2008)1212. Jonathan P. How. Lecture Notes for Principles of Optimal Control. 2008.). ‣ 2.2.4 Solving a Two-Point Boundary Value Problem ‣ 2.2 Indirect Methods" class="ltx_ref">2.2.1 illustrates these ideas in the context of a free-final-time problem.

from scipy.integrate import solve_bvp
import numpy as np
 
# Dynamics: z˙=g(z,t)
def g(t, z):
return np.vstack((z[1], -z[0]))
 
# Boundary conditions: l(z(t0),z(tf))=0
def l(z0, zf):
return np.array([z0[0], zf[0] + 2])
 
# Time mesh and initial guess for z(t)
t_mesh = np.linspace(0, 4, 5)
z_guess = np.zeros((2, t_mesh.size))
 
# Solve TPBVP
sol = solve_bvp(g, l, t_mesh, z_guess)
z_sol = sol.sol(np.linspace(0, 4, 100))
Algorithm 2.1: Example usage of solve_bvp for a TPBVP in standard form. The code for this example is available in the repository github.com/StanfordASL/pora-exercises in the notebook ch02/tpbvp.ipynb.
Example 2.2.1 (Free Final Time Optimal Control Problem; see Example 6.1 in How (2008)1313. Jonathan P. How. Lecture Notes for Principles of Optimal Control. 2008.).

Consider the double integrator system:

x¨=u,

where x is the state and u is the control input. The control objective is to find a trajectory that minimizes the cost:

J(x,u)=12αtf2+0tf12βu2(t)𝑑t,

and satisfies the boundary conditions:

x(0)=10,x˙(0)=0,x(tf)=0,x˙(tf)=0.

This is a free final time problem with fixed boundary conditions on the state. The cost penalizes both the duration of the maneuver (through the αtf2 term) and the control effort (through the integral of u2), with the trade-off governed by the weights α and β.

We can equivalently express the double integrator dynamics as a first-order system of differential equations by setting x1=x and x2=x˙:

x˙1=x2,x˙2=u,

so that the state vector is 𝒙=[x1,x2] and the boundary conditions become:

x1(0)=10,x2(0)=0,x1(tf)=0,x2(tf)=0.

The Hamiltonian is given by:

H=12βu2+p1x2+p2u,

where p1 and p2 are the costate variables. Next, we construct the NOCs from Equation Kirk (2004)1414. Kirk, D. E. Optimal Control Theory: An Introduction. Dover Publications, 2004.). ‣ 2.2.3 Pontryagin’s Minimum Principle ‣ 2.2 Indirect Methods" class="ltx_ref">2.16 by taking the partial derivatives of H with respect to p, x, and u:

x˙1=x2,x˙2=u,p˙1=0,p˙2=p1,0=βu+p2.

Thus, from the last condition, the optimal control satisfies:

u=1βp2.

Since this is a free-final-time problem with fixed terminal state, the boundary conditions for the NOCs are given by:

x1(0)=10,x2(0)=0,x1(tf)=0,x2(tf)=0,12βu(tf)2+p1(tf)x2(tf)+p2(tf)u(tf)+αtf=0.

However, the necessary conditions obtained above do not immediately match the “standard” form required by numerical TPBVP solvers in Equation 2.18, which assumes fixed final time. To cast the problem into standard form, one can apply the time-scaling strategy. First, the time horizon is rescaled to the fixed interval [0,1] by using the scaled time variable τ=t/tf. Next, the derivatives must be adjusted according to the new time variable. By the chain rule, differentiation with respect to τ introduces a scaling factor, that is, τt(τtf)τ=ttf. Finally, the final time tf is replaced by an auxiliary state variable r with trivial dynamics r˙=0. This results in a TPBVP with fixed final time, namely equal to 1, and an additional state variable r that encodes the original final time tf.

For this example, the time-scaled cost becomes:

J(x,u,r)=12αr2+0112βru2(τ)𝑑τ,

with corresponding Hamiltonian:

H=12βru2+p1rx2+p2ru.

As a result, the necessary conditions for optimality become:

x˙1=rx2,x˙2=ru,p˙1=0,p˙2=rp1,r˙=0,0=βru+rp2,

with boundary conditions:

x1(0)=10,x2(0)=0,x1(1)=0,x2(1)=0,αr+12βru(1)2+rp1(1)x2(1)+rp2(1)u(1)=0.

After this reformulation, the problem adheres to the standard form and can be solved numerically.

For a systematic treatment of how nonstandard boundary value problems can be reformulated into standard form suitable for general-purpose solvers, see Ascher and Russell (1981)1515. Ascher, U. M., Russell, R. D. “Reformulation of boundary value problems into ``standard'' form.” SIAM Review 23(2), 238–254, 1981.. For a practical implementation of TPBVP solvers for free-final time optimal control problems, we refer the reader to the notebook ch02/free_final_time_optimal_control.ipynb in the repository
github.com/StanfordASL/pora-exercises.

2.3 Direct Methods

So far, we introduced indirect methods, which involve deriving the necessary optimality conditions of the continuous-time optimal control problem and then discretizing them to numerically solve the resulting two-point boundary value problem. While indirect methods provide deep theoretical insights, they can be challenging to apply in practice due to the difficulty of solving boundary value problems, particularly for complex nonlinear dynamics or large-scale systems.

Direct methods take the opposite approach. Rather than deriving the optimality conditions analytically, the problem is discretized first. This reduces the continuous-time optimal control problem to a finite-dimensional nonlinear optimization problem, which can then be solved using general-purpose numerical optimization algorithms.

The process of converting the continuous-time optimal control problem into a discretized form amenable to numerical optimization is known as transcription. While there exist many different transcription methods, a simple and widely used approach is the forward Euler discretization. This method selects a discretization 0=t0<t1<<tN=tf of the time interval [0,tf] and approximates the state and control sequences assuming a zero-order hold on both the states and control inputs, meaning that both the state and the control input are constant over each time interval [ti,ti+1). The system dynamics are then integrated forward using Euler integration:

𝒙i+1𝒙i+hif(𝒙i,𝒖i),hi=ti+1ti. (2.19)

Direct methods are typically grouped into two main families:

  • State and control parameterization methods (also known as direct collocation methods): here, both the control inputs and the state trajectories are discretized, and the dynamics are introduced explicitly as algebraic constraints linking the state and control variables at each discretization point (e.g., trapezoidal and Hermite-Simpson collocation, Gauss-Lobatto methods, etc.).

  • Control parameterization methods (also known as direct shooting methods): in this approach, only the control inputs are discretized, and the state trajectories are obtained by numerically integrating the system dynamics forward in time. As a result, the optimization variables are solely the discretized controls, while the states are implicitly defined by the integration of the dynamics (e.g., using single or multiple shooting techniques).

In what follows, we illustrate the fundamental concepts of both families of methods through a concrete example.

Example 2.3.1 (Zermelo’s Problem - Continuous-time problem).

Consider the problem of steering a boat from a point (0,0) to a point (M,) in a river with a current. The boat can be controlled by adjusting its direction and its speed is constant. The dynamics of the boat are described by the following differential equations:

x˙(t) =vcos(u(t))+flow(y(t)),t[0,tf],
y˙(t) =vsin(u(t)),t[0,tf],

where (x(t),y(t)) is the position of the boat with x defining the coordinate along the river and y the coordinate across the river, u(t) is the control input (the direction of the boat), and v is the constant speed of the boat. For simplicity, assume that the river flow is described by an arbitrary function acting in the x-direction, with its intensity depending on the position y(t), namely flow(y(t)).

The objective is to minimize the control effort over time, which can be formulated as an optimal control problem:

minimizeu(t) 0tfu(t)2𝑑t,
subject to x˙(t)=vcos(u(t))+flow(y(t)),t[0,tf],
y˙(t)=vsin(u(t)),t[0,tf],
(x(0),y(0))=(0,0),
(x(tf),y(tf))=(M,),
|u(t)|umax,t[0,tf].

2.3.1 Direct Collocation Methods

Consider the Problem introduced in Example 2.3.1. Applying a state and control parametrization, that is a collocation method, leads to the following finite-dimensional nonlinear program, equivalently described in Algorithm 2.3.1:

minimize(x,y,u) i=0N1hiui2,
subject to xi+1=xi+hi(vcos(ui)+flow(yi)),i=0,,N1,
yi+1=yi+hivsin(ui),i=0,,N1,
(x0,y0)=(0,0),
(xN,yN)=(M,),
|ui|umax,i=0,,N1.

In this formulation, both the state and control trajectories are discretized and treated as decision variables. The system dynamics are not enforced through numerical integration, but rather as algebraic equality constraints linking consecutive discretization points.

# Decision variables: (xi,yi,ui),i=0,,N
get_x = lambda z: z[:N + 1]
get_y = lambda z: z[N + 1:-N]
get_u = lambda z: z[-N:]
get_z = lambda x, y, u: np.concatenate([x, y, u])
 
# Cost: i=0N1hiui2
cost = lambda z: np.sum(h * np.square(get_u(z)))
 
def constraints(z):
x, y, u = get_x(z), get_y(z), get_u(z)
constraints = []
for i in range(N):
# xi+1=xi+hi(vcos(ui)+flow(yi))
constraints.append(x[i+1] - x[i] - h*(v*np.cos(u[i])
+ flow(y[i])))
# yi+1=yi+hivsin(ui)
constraints.append(y[i+1] - y[i] - h*v*np.sin(u[i]))
# Boundary conditions: (x0,y0)=(0,0),(xN,yN)=(M,)
constraints.extend([x[0], y[0], x[N] - M, y[N] - l])
return np.array(constraints)
 
# State bounds
x_lower = np.zeros(N + 1)
x_upper = M * np.ones(N + 1)
y_lower = np.zeros(N + 1)
y_upper = l * np.ones(N + 1)
 
# Control bounds: u_iu_max;
u_lower = -u_max * np.ones(N) # control constraint
u_upper = u_max * np.ones(N) # control constraint
 
bounds = Bounds(
get_z(x_lower, y_lower, u_lower),
get_z(x_upper, y_upper, u_upper))
 
# Solve the NLP
result = minimize(cost, z0, bounds=bounds,
constraints={’type’: ’eq’, ’fun’: constraints})
Algorithm 2.2: Direct collocation approach to Zermelo’s problem using forward Euler discretization. The code for this example is available in the repository github.com/StanfordASL/pora-exercises in the notebook ch02/zermelos_problem.ipynb.

2.3.2 Direct Shooting Methods

Many of the concepts introduced for state and control parametrization carry over to control parametrization methods, with a key distinction in how the dynamics are handled. In control parametrization (shooting) methods, the optimization variables consist only of the control inputs at each discretization point. The state trajectory is not explicitly optimized but is instead computed recursively by forward simulation of the system dynamics. In other words, a candidate sequence of controls uniquely determines the corresponding states, which are then used to evaluate the cost and any state constraints.

Concretely, let us revisit Zermelo’s problem from Example 2.3.1, this time using a shooting method transcription. In this formulation, the control inputs {ui}i=0N1 are treated as the optimization variables, while the states {(xi,yi)}i=0N1 are computed recursively from the dynamics.

The resulting finite-dimensional optimization problem is:

minimize𝑢 i=0N1hiui2,
subject to (xN,yN)=(M,),
|ui|umax,i=0,,N1,
where, recursively,
xi+1=xi+hi(vcos(ui)+flow(yi)),i=0,,N1,
yi+1=yi+hivsin(ui),i=0,,N1.

Here, the dynamics are no longer constraints in the optimization problem, but rather equations that implicitly determine the state evolution given a candidate control sequence. Algorithm 2.3 provides a Python implementation of this shooting method approach to Zermelo’s problem.

# Decision variables: (ui),i=0,,N1; Cost: i=0N1hiui2
cost = lambda u: np.sum(h * np.square(u))
 
# States computed recursively from x0=0,y0=0
dynamics = lambda x, y, u: (
x + h * (v * np.cos(u) + flow(y)),
y + h * v * np.sin(u)
)
 
def inequality_constraints(u):
x, y = 0, 0 # initial condition (x(0), y(0)) = (0, 0)
constraints = []
for ui in u:
x, y = dynamics(x, y, ui)
# (xi,yi)>=(0,0) (box constraint with below)
constraints.extend([x, y])
# (xi,yi)<=[M,]
constraints.extend([M - x, l - y])
# (xN,yN)>=[M,] (enforcing equality with the above)
constraints.extend([x - M, y - l])
return constraints
 
bounds = Bounds(-u_max * np.ones(N),
u_max * np.ones(N)) # |ui|umax
 
# Solve NLP
result = minimize(cost, u0, bounds=bounds,
constraints={’type’: ’ineq’,
’fun’: inequality_constraints})
Algorithm 2.3: Direct shooting approach to Zermelo’s problem using forward Euler discretization. The code for this example is available in the repository github.com/StanfordASL/pora-exercises in the notebook ch02/zermelos_problem.ipynb.

Both approaches come with their own advantages and limitations. Control parameterization methods generally result in smaller optimization problems, making the method computationally attractive. The dynamics are enforced exactly through integration (up to the accuracy of the chosen numerical integrator), which is especially useful when the dynamics are complex or only accessible via a black-box simulator. However, state constraints may be difficult to enforce, as the states are not explicit optimization variables but rather implicitly defined through the integration of the dynamics. This can lead to numerical instability or infeasibility when state constraints are critical. Moreover, errors from numerical integration may accumulate, potentially reducing the accuracy of the solution.

On the other hand, state and control parametrization methods treat both states and controls as optimization variables. This allows state constraints to be imposed directly, improving numerical stability and robustness, often leading to better-conditioned optimization problems when constraints play a central role. However, the resulting optimization problem generally grows significantly in size, since all states and controls at every discretization point are treated as decision variables. This higher dimensionality increases computational cost and can make the solver more sensitive to initial guesses.

In practice, both methods are widely used, and the choice between them often depends on the problem structure, the availability of simulators or system models, and the importance of accurately handling state constraints.

2.4 Differentially Flat Systems

Computing open-loop control sequences by directly solving optimal control problems can often be computationally intensive. In many applications, it is useful to trade off strict optimalitymargin: That is, the theoretical best performance according to a given cost functional. for computational tractability by seeking “good” trajectories that are simpler to compute, even if slightly sub-optimal.

For a special class of systems known as differentially flat systems, generating such feasible trajectories is considerably simpler. A system is differentially flat if there exists a set of outputs, called flat outputs, such that all system states and inputs can be expressed as algebraic functions of these outputs and a finite number of their derivatives. This property allows trajectory generation to be performed in the space of the flat outputs, eliminating the need to solve differential equations as part of the optimization process and greatly reducing computational complexity.

Differentially flat models arise in several common robotics applications, including simple car models, quadrotors, and many other wheeled or aerial vehicles. Their relative simplicity and expressiveness make them particularly attractive for trajectory planning and open-loop control synthesis.

Example 2.4.1 (Differentially Flat Autonomous Vehicle Control).

Recall the motion planning task from Example 2.1.1 where the objective was to compute an open-loop control sequence to drive a vehicle through a course to a goal position in minimum time. If we relax the requirement of optimality and instead aim simply to find a feasible trajectory that follows the course, we can exploit the differential flatness of the kinematic car model. Specifically, consider the kinematic car model from Equation 1.29:

x˙=vcosθ,y˙=vsinθ,θ˙=vLtanϕ,

where (x,y) is the vehicle position, θ is the heading, v is the speed, ϕ is the steering angle, and L is the wheelbase.

This system is differentially flat with flat outputs (x(t),y(t)). Therefore, it is sufficient to specify any differentiable trajectory for x(t) and y(t) that respects the course constraints. From these trajectories, the remaining state and control variables—which are the quantities needed for practical implementation—can be computed analytically. The heading is obtained from the velocity direction as:

θ=tan1(y˙x˙).

and the speed along the trajectory can be computed using either component of the velocity:

v=x˙cosθ,orv=y˙sinθ.

Finally, the steering angle is determined from the heading dynamics:

ϕ=tan1(Lθ˙v).

In this way, a feasible trajectory for the vehicle can be generated entirely by specifying smooth flat output trajectories, from which all states and, importantly, the control inputs can be derived directly.

We formalize this concept through the notion of differential flatnessmargin: Murray (2009)1616. Murray, R. M. Optimization-Based Control. California Institute of Technology, 2009. is a good resource for a comprehensive treatment on differential flatness. .

Definition 2.1 (Differential Flatness).

A nonlinear system with state 𝒙n and control 𝒖m:

𝒙˙(t)=f(𝒙(t),𝒖(t)), (2.20)

is differentially flat if there exists a function α such that:

𝒛=α(𝒙,𝒖,𝒖˙,,𝒖(a)), (2.21)

where 𝒖(i) denotes the i-th time derivative of 𝒖, and such that the system trajectories can be expressed as functions of the flat output 𝒛m and a finite number of its derivatives:

𝒙=β(𝒛,𝒛˙,,𝒛(b))𝒖=γ(𝒛,𝒛˙,,𝒛(c)). (2.22)

In other words, a system is said to be differentially flat if there exists a set of outputs 𝒛 (with the same dimension as the input vector 𝒖) that completely determine both the states and the inputs, without requiring integration of the system dynamics. For trajectory optimization, this property is particularly advantageous: since the evolution of a flat system is fully characterized by its flat outputs, trajectories can be computed directly in the output space and then mapped to the corresponding inputs, thereby avoiding expensive integration of the dynamics.

In the following sections, we explore different techniques to exploit differential flatness for open-loop trajectory design, including how to parameterize trajectories in the flat output space, handle initial and terminal state constraints, and enforce control constraints.

2.4.1 Trajectory Parameterization

Our primary limitation when planning a trajectory in the flat output space is that it must be differentiable. A common approach is to parameterize each component of the flat output 𝒛 using N smooth basis functions:

zj(t)=i=1Nαi[j]ψi(t), (2.23)

where zj is the j-th element of 𝒛, αi[j] are parameters that define the trajectory, and ψi(t) are smooth basis functions.

Polynomial basis functions are a natural choice, e.g., ψ1(t)=1, ψ2(t)=t, ψ3(t)=t2, etc. A key advantage of this parameterization is that zj(t) is linear in the variables αi[j], which facilitates translating constraints on 𝒛 and its derivatives directly into constraints on the coefficients αi[j].

2.4.2 Equality Constraints

A key component of any open-loop motion planning problem is the enforcement of boundary conditions. Typically, this means ensuring that the system begins at a prescribed initial state 𝒙(0)=𝒙0 and often that it reaches a desired terminal state, 𝒙(tf)=𝒙f, at some final time tf. When planning in the flat output space, these state conditions must be expressed as constraints on the flat output 𝒛(t) and its derivatives. Recalling the mapping in Equation 2.22, this leads to:

𝒙0=β(𝒛(0),𝒛˙(0),,𝒛(q)(0)),𝒙f=β(𝒛(tf),𝒛˙(tf),,𝒛(q)(tf)). (2.24)

In practice, this means that boundary conditions on zj(0),z˙j(0),,zj(q)(0) and zj(tf),z˙j(tf),,zj(q)(tf) must be enforced. When using a smooth basis function parameterization of the form in Equation 2.23, these conditions translate directly into algebraic constraints on the coefficients αi[j]. By differentiating Equation 2.23 q times, we obtain:

z˙j(t)=i=1Nαi[j]ψi˙(t),zj(q)(t)=i=1Nαi[j]ψi(q)(t). (2.25)

which allows us to express the boundary conditions as a system of linear equations:

[ψ1(0)ψ2(0)ψN(0)ψ1˙(0)ψ2˙(0)ψN˙(0)ψ1(q)(0)ψ2(q)(0)ψN(q)(0)ψ1(tf)ψ2(tf)ψN(tf)ψ1˙(tf)ψ2˙(tf)ψN˙(tf)ψ1(q)(tf)ψ2(q)(tf)ψN(q)(tf)][α1[j]α2[j]αN[j]]=[zj(0)z˙j(0)zj(q)(0)zj(tf)z˙j(tf)zj(q)(tf)]. (2.26)

Assuming the matrix formed by the basis functions has a sufficient number of columns and that it is full column rank, we can solve for (possibly non-unique) αi[j] that solve the trajectory generation problem.

More generally, any equality constraint on the flat outputs or their derivatives—beyond just initial and terminal states—can be written in this linear form. For instance, waypoints can be added as additional equality constraints. However, if too many constraints are imposed, the system may become overdetermined, leaving no feasible solution. In such cases, one must increase the richness of the basis functions, for example by using higher-order polynomials or additional functions, which improves flexibility but also increases computational complexity.

2.4.3 Inequality Constraints via Time Scaling

Having addressed equality constraints in Section 2.4.2, we now turn to inequality constraints. These commonly arise in motion planning and control to enforce actuator limits or safety bounds on the state. For example, the simple car model from Example 2.4.1 may have a speed constraint of the form:

|v(t)|vmax.

A useful technique for handling such constraints in the flat-output space is time scaling. The idea is to first plan a trajectory that satisfies the equality constraints (e.g., by solving Equation 2.26), and then adjust its temporal evolution—speeding up or slowing down along the path—to enforce the inequality constraints.

Formally, let 𝒙(t) be a trajectory satisfying the equality constraints. We can separate the geometric pathmargin: The geometric path of a trajectory is the sequence of states 𝒙 of the trajectory, but not associated with a particular time from its timing by introducing a path parameter s(t):

𝒙(t)=𝒙(s(t)),

with s(0)=s0, s(tf)=sf, and s˙(t)>0margin: The condition s˙(t)>0 ensures invertibility, so each t corresponds to a unique s. . The geometric path 𝒙(s) captures the sequence of states, while the choice of s(t) determines how quickly the system traverses that path. Varying s(t) is referred to as time scaling.

Example 2.4.2 (Time Scaling for a Simple System).

Consider a scalar system with state x and a straight-line path connecting an initial and terminal state, x0 and xf:

x(s)=x0+s(xfx0),s[0,1].

Choosing a cubic polynomial for s(t),

s(t)=3T2t22T3t3,t[0,T],

which satisfies s(0)=0, s(T)=1, and s˙(t)>0, yields the temporal trajectory:

x(t)=x0+(3T2t22T3t3)(xfx0).

Here, T controls the duration of the trajectory. If we impose a velocity bound:

|x˙|x˙max,

then:

x˙=6(tT2t2T3)(xfx0),x¨=6(1T22tT3)(xfx0),

with the maximum velocity attained at t=T2. We can then convert this into a constraint on T to ensure the inequality constraint is satisfied:

T3(xfx0)2x˙max.

Example 2.4.2 illustrates the key idea: inequality constraints can often be transformed into conditions on the timing law s(t), without altering the geometric path itself.

For general state-space systems, time scaling is often more complex. Given a feasible trajectory (𝒙(t),𝒖(t)) of the system dynamics in Equation 2.20, we can rewrite it as a geometric path (𝒙(s),𝒖(s)) using a path parameter s(t):

d𝒙(s)dsds(t)dt=f(𝒙(s),𝒖(s)). (2.27)

For time scaling, we replace s(t) with a new path parameter s~(t) over a possibly different interval t[0,t~f], with s~(0)=s0 and s~(t~f)=sfmargin: The geometric path is still defined on the interval [s0,sf], which must remain the same for any new time scaling law. . The new scaling must still satisfy the dynamics:

d𝒙(s~)ds~ds~(t)dt=f(𝒙(s~),𝒖(s~)). (2.28)

Since the geometric path is fixed—as it was previously defined—the terms d𝒙(s~)ds~ and 𝒙(s~) are also fixed. Therefore, time scaling with a new path parameter s~(t), is only admissible if an appropriate 𝒖~(s~) can be found. Fortunately, for many systems—including those commonly studied in motion planning—this is possible with the right choice of s~(t).

Example 2.4.3 (Time Scaling for the Simple Car Model).

Consider again the simple car model from Equation 1.29:

x˙=vcosθ,y˙=vsinθ,θ˙=vLtanϕ,

and suppose we have identified a candidate trajectory 𝒙c(t) with control 𝒖c(t) by leveraging the differential flatness of the model through Equation 2.26 and mapping the flat outputs 𝒛c(t) into the state and control space.

For this model, a natural choice for the path parameter s is the arc-length, defined as:

s(t)=0tv(τ)𝑑τ.

such that s˙(t)=v(t)>0. With this choice, the geometric path 𝒙c(s) is defined over s[0,Lpath], where Lpath is the total length of the path. Rewriting the dynamics in terms of an arbitrary time scaling s~(t) gives:

dxc(s~)ds~s~˙=v(s~)cosθc(s~),dyc(s~)ds~s~˙=v(s~)sinθc(s~),dθc(s~)ds~s~˙=v(s~)Ltanϕ(s~),

which must hold for any admissible time scaling s~(t)margin: The trivial choice s~(t)=s(t) reproduces the original candidate trajectory with control inputs 𝒖c(t). .

By adopting the arc-length parameterization, we have s~˙=v(s~), so these equations reduce to:

dxc(s~)ds~=cosθc(s~),dyc(s~)ds~=sinθc(s~),dθc(s~)ds~=1Ltanϕ(s~).

The first two equations are automatically satisfied for any choice of s~[s0,sf], since the original candidate trajectory satisfies the dynamics. On the other hand, the third equation is satisfied provided we reuse the same steering input, ϕ(s~)=ϕc(s~). Therefore, the dynamics remain consistent for any choice of time scaling s~(t): the geometric path is preserved, while the temporal evolution along that path is left free. This observation is powerful as we may freely adjust the speed input v(t), subject only to s~˙(t)>0, without altering the geometry of the trajectory. In practice, this allows us to easily enforce inequality constraints on the speed |v(t)|vmax.

Example 2.4.3 shows a relatively straightforward application of time scaling to a model derived from kinematic constraints. This idea extends naturally to a wide class of kinematic models of the form:

𝒙˙(t)=G(𝒙(t))𝒖(t). (2.29)

Applying the chain rule, we obtain:

d𝒙(s)dss˙=G(𝒙(s(t)))𝒖(t),

which can be rewritten as:

d𝒙(s)ds=G(𝒙(s))𝒖g(s), (2.30)

where 𝒖g(s)=𝒖(t)s˙(t) is the geometric controlmargin: Since s(t) must be strictly increasing, we require s˙(t)>0. . Equation (Equation 2.30) shows that the geometric path 𝒙(s) is fully determined by the geometric control 𝒖g(s), independent of the time parametrization. Therefore, once the geometric control and geometric path are defined, we can temporally scale the trajectory 𝒙(t) using the path parameter s(t) without changing the geometric path. The corresponding control inputs are recovered via 𝒖(t)=s˙(t)𝒖g(s).

In summary, for models of the form (Equation 2.29), we can perform time scaling by:

  1. 1.

    Selecting a path parameter s (e.g., arc-length), computing s(t) for the original trajectory 𝒙(t), and determining the interval [s0,sf].

  2. 2.

    Re-parameterizing the control 𝒖(t) in terms of s.

  3. 3.

    Computing the geometric control 𝒖g(s)=𝒖(s(t))/s˙(t) for s[s0,sf].

  4. 4.

    Defining a new path parameter function s~(t) over the interval [0,t~f] with s~˙(t)>0, s~(0)=s0, and s~(t~f)=sf.

  5. 5.

    Computing the new control inputs as 𝒖~(t)=𝒖g(s~(t))s~˙(t) for all t[0,t~f].

Example 2.4.4 (Time Scaling for the Unicycle Model).

Consider the kinematic unicycle model:

x˙=vcosθ,y˙=vsinθ,θ˙=ω, (2.31)

where (x,y) denote the position, θ the heading, v the forward velocity, and ω the rotation rate. We define the state as 𝒙=[x,y,θ] and the control as 𝒖=[v,ω].

A natural path parameter for this system is again the arc-length:

s(t)=0tv(τ)𝑑τ,

such that s˙(t)=v(t)>0. If the trajectory is defined over t[0,T] with total length Lpath, then s(0)=0 and s(T)=Lpath. The corresponding geometric controls are:

vg(s)=v(s)s˙(t)=1,ωg(s)=ω(s)s˙(t)=ω(s)v(s),

where the fact that vg(s)=1 follows directly from s˙(t)=v(s(t)). Introducing a new timing law s~(t) generates a new velocity profile v~(s~)=s~˙(t) along the path, which can use to solve for the new ω~ inputs by:

ω~(s~)=ωg(s~)s~˙(t)=ω(s~)v(s~)v~(s~).

In practice, it is often simpler to directly prescribe a velocity profile v~(s~) along the path and compute the corresponding angular velocity ω~(s~)=ω(s~)v(s~)v~(s~). Finally, to determine the new controls as functions of time, we note that:

τ(s)=0s1v~(s)𝑑s,

defines a function τ(s) that maps each point s[0,Lpath] to a new time.

Example 2.4.5 (Planar Quadrotor Control).

In this example we consider the control of a planar quadrotor system. The quadrotor is modeled with six state variables: horizontal position x, vertical position y, orientation angle ϕ, and their respective velocities. The control inputs are the thrusts T1 and T2 from the two rotors. The objective is to minimize the energy consumption, represented by the integral of the squared thrusts over time:

minimize[]0tfT1(t)2+T2(t)2dt.

The system dynamics are given by the following differential equations:

[x˙v˙xy˙v˙yϕ˙ω˙]=[vx(T1+T2)msinϕvy(T1+T2)mcosϕgω(T2T1)Izz],

where m is the mass, g is the gravitational acceleration, is the distance from the center of mass to each rotor, and Izz is the moment of inertia about the z-axis.

This system is differentially flat, with flat outputs (x,y). For a practical implementation of differential flatness for trajectory generation applied to this system, refer to the notebook ch02/differentially_flat_planar_quadrotor.ipynb in the repository github.com/StanfordASL/pora-exercises.

2.5 Summary

In this chapter, we explored how trajectory optimization provides a fundamental framework for computing open-loop motions and establishing a foundation for autonomous decision-making in robotic systems.

We began by formalizing the optimal control problem—a mathematical formalization for the task of driving a system’s state evolution through admissible control inputs while optimizing a performance criterion. This formulation involves three key components: the system’s mathematical model, the physical constraints, and the performance criteria.

We then introduced two major families of methods for solving optimal control problems and compute optimal open-loop control sequences: direct methods and indirect methods. Indirect methods adopt an “optimize-then-discretize” approach, deriving analytical necessary conditions for optimality and solving the resulting two-point boundary value problem numerically. In contrast, direct methods follow a “discretize-then-optimize” strategy, transcribing the continuous problem into a finite-dimensional nonlinear program that can be solved with standard optimization solvers.

Lastly, we discussed differentially flat systems, a special class of systems for which trajectory generation is significantly simplified. For these systems, planning can be performed in a lower-dimensional “flat output” space using techniques like polynomial parameterization. We showed how initial, terminal, and waypoint constraints can be translated into linear algebraic equations, and how inequality constraints on state and control can be managed through time scaling.

To learn more.

For comprehensive treatments of optimal control, we point the reader to several excellent references, including Murray (2009)1717. Murray, R. M. Optimization-Based Control. California Institute of Technology, 2009., Kirk (2004)1818. Kirk, D. E. Optimal Control Theory: An Introduction. Dover Publications, 2004., Rao (2010)1919. Rao, A. “A Survey of Numerical Methods for Optimal Control.” Advances in the Astronautical Sciences 135, 2010., and Kelly (2017)2020. Kelly, M. “An Introduction to Trajectory Optimization: How to Do Your Own Direct Collocation.” SIAM Review 59(4), 849-904, 2017.. Kirk (2004)2121. Kirk, D. E. Optimal Control Theory: An Introduction. Dover Publications, 2004. offers a foundational perspective on indirect methods, including detailed derivations of the calculus of variations and Pontryagin’s Minimum Principle. For a thorough exploration of direct methods and modern optimization-based approaches, Rao (2010)2222. Rao, A. “A Survey of Numerical Methods for Optimal Control.” Advances in the Astronautical Sciences 135, 2010. and Kelly (2017)2323. Kelly, M. “An Introduction to Trajectory Optimization: How to Do Your Own Direct Collocation.” SIAM Review 59(4), 849-904, 2017. provide in-depth coverage of transcription techniques, such as collocation and shooting, and their formulation as nonlinear programming problems. Finally, Murray (2009)2424. Murray, R. M. Optimization-Based Control. California Institute of Technology, 2009. gives an extensive overview of differential flatness, illustrating how this property can be exploited for efficient trajectory generation.

2.6 Exercises

The starter code for the exercises provided below is available online through GitHub. To get started, download the code by running in a terminal window:

git clone https://github.com/StanfordASL/pora-exercises.git

We denote Problems requiring hand-written solutions and coding in Python with [Uncaptioned image] and [Uncaptioned image], respectively.

[Uncaptioned image] Problem 1: Extremal Curves

[This exercise is inspired by Kirk (2004)2525. Kirk, D. E. Optimal Control Theory: An Introduction. Dover Publications, 2004., Chapter 4, Problem 4.9]

Given the functional:

J(x)=01(12x˙(t)2+5x(t)x˙(t)+x(t)2+5x(t))𝑑t,

find an extremal curve x:[0,1] that satisfies x(0)=1 and x(1)=3.

[Uncaptioned image] Problem 2: Minimum Control Effort

Consider the dynamics:

x˙(t)=2x(t)+u(t),

with the initial constraint x(0)=2, terminal constraint x(1)=0, and cost functional:

J(u)=01u(t)2𝑑t.

Write down the Hamiltonian and use the necessary optimality conditions to derive an optimal control u(t) and corresponding state trajectory x(t).

[Uncaptioned image] Problem 3: Zermelo’s Ship

Zermelo’s ship must travel through a region of strong currents. The position of the ship is denoted by (x(t),y(t))2. The ship travels at a constant speed v>0, yet its heading θ(t) can be controlled. The current moves in the positive x-direction with speed w(y(t)). The equations of motion for the ship are:

x˙(t) =vcosθ(t)+w(y(t)),
y˙(t) =vsinθ(t).

We want to control the heading θ(t) such that the ship travels from a given initial position (x(t0),y(t0))=(x0,y0) to the origin (0,0) in minimum time.

  1. 1.

    Suppose w(y(t))=vhy(t), where h>0 is a known constant. Show that an optimal control law θ(t) must satisfy a linear tangent law of the form:

    tanθ(t)=αvht,

    for some constant α.

  2. 2.

    Suppose w(y(t))β for some constant β>0. Derive an expression for the optimal transfer time t1t0.

[Uncaptioned image] Problem 4: Singular Arc for Dubins’ Car

The kinematics of Dubins’ car are described by:

x˙ =vcosθ,
y˙ =vsinθ,
θ˙ =u,

where (x,y)2 is the car’s position, θ is the car’s heading, v>0 is the car’s constant known speed, and u is the controlled turn rate. The turn rate is bounded, meaning u[ω¯,ω¯], where ω¯>0 is a known constant.

The car starts at (x,y)=(0,0) with a heading of θ=0 at t=0. We want the car to drive to (x,y)=(0,c) in the least amount of time possible, where c>0 is a given constant.

  1. 1.

    Use Pontryagin’s maximum principle to express the optimal control input u(t) as a function of the optimal co-state p(t)(px(t),py(t),pθ(t))3.

    Hint: You should discover that the maximum condition for u(t) is not informative whenever pθ(t)p¯θ for a particular fixed value p¯θ. When such a lack of information persists over a non-trivial time interval, i.e., any time interval [t1,t2] with t2>t10, this is known as a singular arc. To compute u(t) in this case, use the fact that pθ(t)p¯θ is constant in time along this singular arc.

  2. 2.

    Use boundary conditions to argue why p(t) might end in a singular arc. Suppose we know p(t) begins on a non-singular arc, then switches once to and ends on a singular arc. For this particular case, argue why u(0)=ω¯ and describe the optimal state trajectory (x(t),y(t),θ(t)) and control trajectory u(t) in words without explicitly deriving them.

[Uncaptioned image] [Uncaptioned image] Problem 5: Single Shooting for a Unicycle

Consider the kinematic model of a unicycle:

x˙ =vcos(θ),
y˙ =vsin(θ),
θ˙ =ω,

where (x,y) is the planar position of the vehicle, θ is its heading angle, v is its forward velocity, and ω is its angular velocity. Overall, the state and control input for this system are x(x,y,θ)3 and u(v,ω)2, respectively. We have overloaded x to denote both horizontal position x and the full state vector x3.

Our task is to drive the vehicle from the starting configuration x(0)=(0,0,π/2) to the target configuration x(T)=(5,5,π/2) in minimum time with as little control effort as possible. To this end, we consider the objective:

J(x,u)=0T(α+v(t)2+ω(t)2)𝑑t,

where α>0 is a chosen constant weighting factor and T is the free final time.

  1. 1.

    Derive the Hamiltonian and necessary optimality conditions, specifically

    1. (a)

      the ODE for the state and co-state,

    2. (b)

      the optimal control as a function of the state and co-state, and

    3. (c)

      the boundary conditions, including the additional condition for free final time T.

Hint: Since the control set is unbounded, use the weak maximum condition.

In practice, you might use a boundary value problem (BVP) solver from an existing computing library, such as scipy.integrate.solve_bvp (https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve_bvp.html), but in this problem we will use a bit of nonlinear optimization theory and JAX to write our own!

  1. 2.

    In the file ch02/exercises/unicycle_optimal_control.ipynb, complete the implementations of unicycle_dynamics, hamiltonian, optimal_control, and noc_ode. Use α=0.25.

In the single shooting method, we need to initialize estimates of the initial co-state p(0) and final time T. We then integrate the state and co-state dynamics forward in time from t=0 to t=T, at which point we check whether the terminal boundary conditions are satisfied.

  1. 3.

    Use the ODE integration from noc_trajectories to complete
    boundary_residual, which should compute a measure of how far off each of your terminal boundary conditions is from satisfaction, given guesses for the initial co-state p(0) and final time T.

  2. 4.

    Finally, in newton_step and single_shooting, implement the Newton-Raphson root-finding method for boundary_residual. Now, if you provide an appropriate guess for the initial costate and final time, you can solve the problem in unicycle_optimal_control.ipynb and see a plot of the optimal solution. You may find that whether or not your BVP solver converges to a solution is highly dependent on the quality of your initial guess—indeed, initialization is a major challenge when applying indirect methods for optimal control!

    Hint: For finding roots of a function f:nn, each iteration of the Newton-Raphson method entails improving a current best guess x(k) at iteration k using the update rule:

    x(k+1)=x(k)fx(x(k))1f(x(k)).

Practice · 5 notebooks