Kinodynamic Path Finding¶
Introduction¶
The kinodynamic
planning problem is to synthesize a robot subject to simultaneous
kinematic
constraints, such asavoiding obstacles
dynamic
constraints, such as modulusbounds on velocity, acceleration, and force
A kinodynamic solution is a mapping from time to generalized forces or accelerations.
We choose kinodynamic planning because:
- Straight-line connections between pairs of states are typically not valid trajectories due to the system's
differential constraints
. - The smoother the path we found, the easier we optimize it.
- Coarse-to-fine process
- Trajectory only optimizes locally
- Infeasible path means nothing to nonholonomic system
The typical models we used are:
State Lattice Planning¶
As learned in search-based path finding, we have many weapons to attack graph search. But to assume the robot a mass point is not satisfactory any more, we require a graph with feasible motion connections
now.
The search-based path finding is actually a discretization of control space with the assumption that the robot can move in 4/8 directions:
And the sample-based path finding is a discretization of state sapce where the state is \(\mathbb{R}^2\), only position \((x, y)\) is considered.
We can manually create(build) a graph with all edges executable by robot in two ways:
- forward direction: discrete (sample) in
control
space - reverse direction: discrete (sample) in
state
space
This is the basic motivation for all kinodynamic planning, and state lattice planning is the most straight-forward one.
Build the Graph, Sample in Control vs. State Space¶
For a robot model:
- The robot is differentially driven
- We have an inital state \(s_0\) of the robot
- We can generate feasible local motions by:
- Select a \(u\), fix a time duration \(T\), forward simulate the system(numerical integration)
- Select a \(s_f\), find the connection (a trajectory) between \(s_0\) and \(s_f\)
Sample in Control Space¶
The lattice graph obtained by searching is:
Note that:
- During searching, the graph can be built when necessary.
- Create nodes(state) and edges(motion primitive) when nodes are newly discovered.
- Save computational time/space.
And for vehicle, things are different.
The state
can be:
Input
:
System equation
:
where:
- \(\theta\) is heading angle
- \(\phi\) is steering angle
- \(R\) is steering radius
- \(L\) is the length from front to rear axle
For every \(s \in T\) from the search tree, we pick a control vector \(u\) and integrate the equation over short duration, and finally add collision-free motions to the search tree.
Sample in State Space¶
We build a lattice graph with:
- Given an origin
- For 8 neighbor nodes around the origin, feasible paths are found
- Extend outward to 24 neighbos.
- Complete lattice
Following is build with Reeds-Shepp Car Model
:
And for two or more layers lattice graph, only first layer is different:
Comparison¶
- Trajectories are denser in the direction of the initial angular velocity
-
Very similar outputs for several distinct inputs
Boundary Value Problem(BVP)¶
Boundary Value Problem is the basis of state sampled lattice planning. It has no general solution, we have to design case by case. It often envolves complicated numerical optimization.
The basic problem is to design a trajectory (in x direction, for example) such that:
- \(x(0) = a\)
- \(x(T) = b\)
We can take the trajecotry \(5^{th}\) order polynomial trajectory:
The boundary condition will be:
Position | Velocity | Acceleration | |
---|---|---|---|
t = 0 | a | 0 | 0 |
t = T | b | 0 | 0 |
The problem will be solved with:
Optimal Boundary Value Problem(OBVP)¶
If \(T\) is fixed, we can get the unique solution of:
But if \(T\) is a variable, we can get more than one solutions. This is an optimal boundary value problem.
The general step for this problem is:
- System modelling
Pontryain's Minimum Principle
constructing- Solving costate
- Solving optimal control
We take the quadratic as an example.
Fixed Final State¶
1. System modeling¶
a. State:
b. System modle
c. Input:
d. Boundary state:
e. Cost Function:
The \(k\) in equation is the dimension(x, y, z) of state, and we assume that three dimensions are independent, so we throw away the \(k\) in the following equations.
And we also define that the quadratic must arrive the final position with the state of \(S(f)\), which causes some difference with undefined dimensions' case, we'll discuss this condition later.
- A Computationally Efficient Motion Primitive for Quadrocopter Trajectory Generation
- Dynamic Programming and Optimal Control
2. Pontryain Minimum Principle
constructing¶
Generally, the cost function can be described as:
where:
- \(h(s(T))\) is the
final state
; - \(\int^T_0{g(s(t), u(t)) \cdot dt}\) is the
transition cost
.
Write the Hamiltonian function
and costate
:
and suppose:
- \(s^\star\) is the
optimal state
- \(u^\star\) is the
optimal input
We have following conclusions:
\(\lambda(t)\) is the solution of:
with the boundary condition of:
and the optimal control input is:
By Pontryain's minimum principle
, we first inctroduce the costate
:
And define the Hamiltonian function
:
The Pontryain's minimum principle
says:
with \(S^*(0) = S(0)\), where:
*
, means optimal.
And \(\lambda(t)\) is the solution of:
with the boundary condition of:
and the optimal control input is:
3. Solving costate¶
From equation (8) and (10), calculating the partial derivatives of \((p, v, a)\), we get:
We define \(\lambda_1 = \alpha\), and calculate the integration of \(\lambda_2\) and \(\lambda_3\):
As for that \(\alpha\), \(\beta\) and \(\gamma\) are all unknown variables, we can organize the formula above to:
According to (12), \(u^*(t)\) is the \(u(t)\) value when formula (8) get minimum value with the costate \([\lambda_1, \lambda_2, \lambda_3]'\), so:
As we have known (3), to minimize the \(u(t)\), we let the derivative of \(j\) to \(0\):
We already have the start state (5), according to (2), \(S^{*}(t)\) is the 1/2/3
order integration of \(u^{*}(t) = j\):
The optimal \(S^\star (t)\) should meet the end state (6), so:
The equation above is actually a combination of three independent equations, we can move some iterms from left of equal sign to right:
we let:
in linear algebra form:
We can calculate the inverse of first matrix with Gauss-Jordan Elimination:
And then take the result to (1), we will get the equation about \(J\):
\(J\) only depends on \(T\), and the boundary states are known, so we can get the optimal T.
This is a polynomial function root finding problem, we can solve it with:
1. Quartic Equation Root Finding¶
There are many methods to find roots of quartic equation, we need to ignore negtive and virtual root. But the root is very complex. Not recommanded.
2. Use Companion Matrix to Find Determinant¶
In linear algebra, the Frobenius companion matrix of the monic polynomial:
is the square matrix defined as
We can calculate the determinant of \(C(p)\) and take all positive root to equation (17) to get the optimal \(T\), this can be done within Eigen
library.
3. Eigen PolynomialSolver¶
This is a solver in Eigen
, more in example.
Partial Free Final State¶
The previous process is about fixed final state problem, you may notice that the boundary contidtion (10):
is not used. That's because that:
is not differentialble, so we discard this condition and use given \(S(T)\) to directly solve for unknown variables.
We will solve this again with fixed final \(p\) and free \(v\) and \(a\).
1. Modeling¶
a. Cost Function:
b. State:
c. Input:
d. System Model:
e. Start and End State:
The \(k\) in equation is the dimension(x, y, z) of state, and we assume that three dimensions are independent, so we throw away the \(k\) in the following equations.
And we also define that the quadratic must arrive the final position with the state of \(S(f)\), which causes some difference with undefined dimensions' case, we'll discuss this condition later.
- A Computationally Efficient Motion Primitive for Quadrocopter Trajectory Generation
- Dynamic Programming and Optimal Control
2. Solving¶
By Pontryain's minimum principle
, we first inctroduce the costate
:
And define the Hamiltonian function
:
The Pontryain's minimum principle
says:
with \(S^*(0) = S(0)\), where:
*
, means optimal.
And \(\lambda(t)\) is the solution of:
with the boundary condition of:
and the optimal control input is:
3. Details¶
From equation (8) and (10), calculating the partial derivatives of \((p, v, a)\), we get:
We define \(\lambda_1 = -\frac{1}{T} 2 \alpha\), and calculate the integration of \(\lambda_2\) and \(\lambda_3\):
Using the boundary condition (10), we know that the \(v\) and \(a\) are free, so the function \(h\) has no relationships with \(v, a\) at \(T\). Then:
With the formula about \(\lambda (t)\), we have:
So the equation can be simplified to:
The optimal input can be solve:
Integrating the \(u^\star(t) = j\), we have:
We have the final \(p(f)\), so:
so:
where:
Finally, we get:
\(J\) is the function about \(T\), to minimize \(J\), we calculate the result of \(J' = 0\):
So:
or
Wheeled Robots¶
- Optimal Rough Terrain Trajectory Generation for Wheeled Mobile Robot
- Maximum Likelihood Path Planning for Fast Aerial Maneuvers and Collision Avoidance
Heuristic Design¶
We can design the heuristic in practice, the principle is:
Solve an easier problem
There are mainly two methods:
- Assume no obstacle existence
- Assume no dynamic existence
Ref:
- Planning Long Dynamically Feasible Maneuvers for Autonomous Vehicle
- Path Planning for Autonomous Vehicles in Unknown Semi-structured Environment
Planning in Frenet-serret Frame¶
The frenet-serret frame is widely used in autonomous driving, it's a dynamic reference frame.
The lateral and longitudinal motivations of autonomous vehicle are independently, for lane following problem, the lateral and longitudinal motions are decoupled.
We firstly define the motion/control parametrization(quintic polynomial):
and then solve the optimal control problem.
We only discuss the lateral planning here, for longitudinal planning, please refer to:
- Optimal Trajectory Generation for Dynamic Street Scenarios in a Frenet Frame
- Optimal trajectoires for time-critical street scenarios using discretized terminal manifolds
We have known the initial state:
As we need a lane following, the terminate state will be:
Use what we have learned from Partial Free Final State
, we can get everything.
where:
Hybrid A*¶
Basic Idea¶
Online generating a dense lattice costs too much time, so how about prune
some nodes?
Hybird A star use the grid map to prune the branches.
If there is no node in the grid, we add the node to grid; if there is a node in grid, we check the cost of the node in grid and new node and reserve the lower one.
Reference:
- Pratical Search Techniques in Path Planning for Autonomous Driving
- Path Planning for Autonomous Vehicles in Unknown Semi-structured Environments
Heuristic Design¶
To accumulate the search process, we can use following methods to design the heuristic:
- 2D-Euclidean distance
- non-holonomic-without-obstacles
- non-holonomic-without-obstacles, bad performance in dead ends
- non-holonomic-without-obstacles + holonomic-with-obstacles(2D shortest path)
Other Tricks¶
Control space sample(discretization) is kind of low-efficient, since no target biasing is encoded. So how about we manually add(try) state space sample?
Here come's the Analytic Expansions
(One shot): add a state-driven bias towards the searching process, if at some state we can get an optimal path to the final state, the search process is terminated. A trade-off is that if we do this one-shot
each time visit a node, the cost will be huge. We can do this one-shot
each \(N\) nodes. And as the frontier of graph goes towards the target node, we can decrease the \(N\).
Application¶
- Practical Search Techniques in Path Planning for Autonomous Driving
- Robust and Efficient Quadrotor Trajectory Generation for Fast Autonomous
Kinodynamic RRT*¶
Kinodynamic RRT* is similar to \(RRT\star\), but different in details, the main process is:
- Input: \(E\), \(x_{init}\), \(x_{goal}\)
- Output: A trajectory \(T\) from \(x_{init}\) to \(x_{goal}\)
- T.init()
- for \(i = 1 \to n\) do:
- \(x_{rand} \gets Sample(E)\)
- \(x_{near} \gets Near(x_{rand})\)
- \(x_{min} \gets ChooseParent(x_{near}, x_{rand})\)
- T.addNode(\(x_{rand}\))
- T.rewire()
How to "Sample"?¶
System state-space equation:
For example for double integrator systems:
Instead of sampling in Euclidean space like RRT, it requires to sample in full state space
.
How to define "Near"?¶
If without motion constraints, Euclidean distance or Manhattan distance can be used.
In state space with motion constriants, binging in optimal control
.
We can define cost funtion
of transferring from states to states, typically, a quadratic form of time energy optimal is adopted.
where:
- \(\tau\) is the arriving time
- \(u(t)\) is the control policy of transferring
- \(R\) is the weight matrix
Two states are near
if the cost of transferring from one state to the other is small.(Note that the cost may be different if transfer reversely.)
If we know \(\tau\) and \(u(t)\), we can calculate the cost, it'll in classic optimal control solutions(OBVP).
Reference: - Optimal Control
Fixed final state x1, fixed final time \(\tau\)¶
The optimal control policy \(u^{\star}(t)\):
Where \(G(t)\) is the weighted controllability Gramian:
Which is the solution to the Lyapunov equation:
And \(\bar{x}(t)\) describe what the state x would be at time t if no control input were applied:
Which is the solution to the differential equation:
Fixed final state x1, free final time \(\tau\)¶
If we want to find the optimal arrival time \(\tau\), we do this by filling in the control policy \(u^\star(t)\) into the cost function \(c[\tau]\) and evaluating the integral:
The optimal \(\tau\) is found by taking the derivative of \(\c[\tau]\) with respect to \(\tau\):
where:
Solve \(\dot c [\tau] = 0\) for \(\tau^\star\).
Noted that the function \(c[\tau]\) may have multiple local minima. And for a double integrator system, it's a \(4^{th}\) order polynomail.
Given the optimal arrival time \(\tau^\star\) as defined above, it again turns into a fixed final state, fixed final time problem.
How to ChooseParent
?¶
Now if we sample a random state, we can calculate control policy and cost from those state-nodes in the tree to the sampled state.
Choose one with the minimal cost and check x(t) and u(t) are in bounds
. If no qualified parent found, sample another state.
How to find near nodes efficiently¶
Every time we sample a random state \(x_{rand}\), it requires to check every node in the tree to find its parent, that is solving a OBVP
for each node, which is not efficient.
If we set a cost tolerance
\(r\), we can actually calculate bounds of the states(forward-reachable set) that can be reached by \(x_{rand}\) and bounds of the states (backward-reachable set) that can reach \(x_{rand}\) with cost less than \(r\).
And if we store nodes in from of a kd-tree
, we can then do range query in the tree.
This formula describes how cost of transferring from state \(x_0\) to state \(x_1\) changes with arrval time \(\tau\).
We can see that given inital state \(x_0\), cost tolerance \(r\) and arrival time \(\tau\), the forward-reachable set of \(x_0\) is:
where \(\varepsilon[x, M]\) is an ellipsoid
with center \(x\) and positive definite weight matrix \(M\), formally defined as:
Hence, the forward-reachable set is the union of high dimensional ellipsoids for all possible arrival times \(\tau\).
For simplification, we sample several \(\tau\)s and calculate axis-aligned bounding boxe of the ellipsoids for each \(\tau\) and update the maximum and minimum in each dimension:
Simmilar for the calculation of the backward-reachable set.
When do Near
query and ChooseParent
, \(x_{near}\) can be found from the backward-reachable set
of \(x_{rand}\)
How to Rewire
?¶
When Rewire
, we calculate the forward-reachable set
of \(x_{rand}\), and solve OBVP
s.